Skip to content

Commit

Permalink
CMake refactoring (#191)
Browse files Browse the repository at this point in the history
* [source/common] Now using complete header path.

* [source/common] Now using "common/" prefix for includes.

* [source/server] Now using complete header path.

* [source/client] Now using complete header path.

* [CMake] No longer using globbing to get source file list.

* [cmake/om_target] Removed message.

* [CMake] Moved compiler flags to a dedicated file.

* [cmake/compiler_flags] Removed define GK_DEBUG.

* [external] No longer using my forks for some libraries.

* [tests/CMakeLists.txt] Removed warning.

* [external/SDL2] No longer print lots of messages.

* [external/CMakeLists.txt] Refactored.

* [docs/Doxyfile] Removed.

* [Notes] Removed.
  • Loading branch information
Unarelith authored Nov 20, 2023
1 parent 1cb0bf7 commit 580c9a4
Show file tree
Hide file tree
Showing 373 changed files with 1,829 additions and 4,044 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
ignore = dirty
[submodule "external/zlib"]
path = external/zlib
url = https://github.com/Unarelith/zlib.git
url = https://github.com/madler/zlib
ignore = dirty
[submodule "external/sol2"]
path = external/sol2
url = https://github.com/ThePhD/sol2.git
ignore = dirty
[submodule "external/lua"]
path = external/lua
url = https://github.com/Unarelith/LuaJIT
url = https://github.com/WohlSoft/LuaJIT
ignore = dirty
[submodule "external/SFML"]
path = external/SFML
Expand All @@ -22,7 +22,7 @@
url = https://github.com/bkaradzic/bgfx.cmake
[submodule "external/tinyxml2"]
path = external/tinyxml2
url = https://github.com/Unarelith/tinyxml2
url = https://github.com/leethomason/tinyxml2
[submodule "external/glm"]
path = external/glm
url = https://github.com/g-truc/glm
Expand Down
69 changes: 13 additions & 56 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,75 +1,32 @@
#------------------------------------------------------------------------------
# CMakeLists.txt
#------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.6)

project(openminer)

#------------------------------------------------------------------------------
# Setup
#------------------------------------------------------------------------------
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

if (APPLE)
add_definitions(-DGL_SILENCE_DEPRECATION=1)
endif ()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

set(OM_BUILD_TESTS ON CACHE BOOL "Enable building tests if CxxTest is available")

include_directories(external)

#------------------------------------------------------------------------------
# Compiler flags
# Options
#------------------------------------------------------------------------------
set(DEBUG_GCC_FLAGS
-g -Og
-Wall -Wextra -Wconversion -Wno-unused-parameter
-Wfatal-errors
-DGK_DEBUG
-DOM_DEBUG
-DOM_PROFILER_ENABLED
)

set(RELEASE_GCC_FLAGS
-O3
-Wall -Wextra -Wconversion -Wno-unused-parameter
-Wfatal-errors
)

set(RELWITHDEB_GCC_FLAGS
-g -O3
-Wall -Wextra -Wconversion -Wno-unused-parameter
-Wfatal-errors
)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CLANG_FLAGS
-Wno-sign-conversion
-Wno-implicit-int-float-conversion
-Wno-nested-anon-types
)
endif()

set(CMAKE_CXX_STANDARD 17)

if (MSVC)
# Disable iterator debug, improves performance of debug builds
add_compile_definitions($<$<CONFIG:Debug>:_ITERATOR_DEBUG_LEVEL=0>)
endif ()
option(OM_BUILD_TESTS "Enable building tests if CxxTest is available" ON)
option(GIT_SUBMODULE "Check git submodules during build" ON)

#------------------------------------------------------------------------------
# Setting default build type
# Additional cmake files
#------------------------------------------------------------------------------
set(DEFAULT_BUILD_TYPE RelWithDebInfo)

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE)

# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
include(compiler_flags)
include(git_submodules)
include(om_target)
include(utils)

#------------------------------------------------------------------------------
# Subdirectories
Expand Down
16 changes: 0 additions & 16 deletions Notes

This file was deleted.

43 changes: 43 additions & 0 deletions cmake/compiler_flags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#------------------------------------------------------------------------------
# Compiler flags
#------------------------------------------------------------------------------
set(DEBUG_GCC_FLAGS
-g -Og
-Wall -Wextra -Wconversion -Wno-unused-parameter
-Wfatal-errors
-DOM_DEBUG
-DOM_PROFILER_ENABLED
)

set(RELEASE_GCC_FLAGS
-O3
-Wall -Wextra -Wconversion -Wno-unused-parameter
-Wfatal-errors
)

set(RELWITHDEB_GCC_FLAGS
-g -O3
-Wall -Wextra -Wconversion -Wno-unused-parameter
-Wfatal-errors
)

#------------------------------------------------------------------------------
# Platform-specific flags
#------------------------------------------------------------------------------
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CLANG_FLAGS
-Wno-sign-conversion
-Wno-implicit-int-float-conversion
-Wno-nested-anon-types
)
elseif (MSVC)
# Disable iterator debug, improves performance of debug builds
add_compile_definitions($<$<CONFIG:Debug>:_ITERATOR_DEBUG_LEVEL=0>)
endif()

#------------------------------------------------------------------------------
# Additional setup
#------------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 17)

include_directories(external)
21 changes: 21 additions & 0 deletions cmake/git_submodules.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# From https://cliutils.gitlab.io/modern-cmake/chapters/projects/submodule.html
function(update_git_submodules)
find_package(Git QUIET)

if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
if(GIT_SUBMODULE)
message(STATUS "Git submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule sync -q --recursive WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()

if(NOT EXISTS "${PROJECT_SOURCE_DIR}/external/zlib/CMakeLists.txt")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
endfunction()
43 changes: 43 additions & 0 deletions cmake/om_target.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function(om_setup_target PROJECT_NAME)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..)

# FIXME: Use target_include_directories(PUBLIC ...) in zlib/lua
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${PROJECT_SOURCE_DIR}/external/entt/src)
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${PROJECT_SOURCE_DIR}/external/zlib ${CMAKE_CURRENT_BINARY_DIR}/external/zlib)
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${PROJECT_SOURCE_DIR}/external/lua/src)
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${PROJECT_SOURCE_DIR}/external/FastNoiseLite)

if (NOT MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:DEBUG>:${DEBUG_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:RELEASE>:${RELEASE_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:RELWITHDEBINFO>:${RELWITHDEB_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC ${CLANG_FLAGS})
endif ()

target_compile_options(${PROJECT_NAME} PUBLIC -D_USE_MATH_DEFINES)
target_compile_options(${PROJECT_NAME} PUBLIC -DSOL_CHECK_ARGUMENTS -DSOL_PRINT_ERRORS=0)

# target_compile_options(${PROJECT_NAME} PRIVATE -pg)
endfunction()

function(om_add_library PROJECT_NAME HEADER_FILES SOURCE_FILES)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Header Files" FILES ${HEADER_FILES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Source Files" FILES ${SOURCE_FILES})

add_library(${PROJECT_NAME} STATIC ${HEADER_FILES} ${SOURCE_FILES})

om_setup_target(${PROJECT_NAME})
endfunction()

function(om_add_executable PROJECT_NAME HEADER_FILES SOURCE_FILES)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Header Files" FILES ${HEADER_FILES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Source Files" FILES ${SOURCE_FILES})

add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES})

om_setup_target(${PROJECT_NAME})

if(MINGW)
target_link_options(${PROJECT_NAME} PRIVATE -static-libstdc++ -static-libgcc -mconsole)
endif()
endfunction()
5 changes: 5 additions & 0 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function(message)
if (NOT MESSAGE_QUIET)
_message(${ARGN})
endif()
endfunction()
1 change: 0 additions & 1 deletion cmake/vs_folders.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,3 @@ set_target_properties(showanim PROPERTIES FOLDER "extern
set_target_properties(showimage PROPERTIES FOLDER "external/misc")
set_target_properties(uninstall PROPERTIES FOLDER "external/misc")
set_target_properties(xmltest PROPERTIES FOLDER "external/misc")

Loading

0 comments on commit 580c9a4

Please sign in to comment.