-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
69 lines (51 loc) · 3.56 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
cmake_minimum_required (VERSION 3.26)
project(template
DESCRIPTION "<description>"
HOMEPAGE_URL "https://github.com/Challanger524/template-cpp"
LANGUAGES CXX)
# # Setup: main project # #
add_executable (${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/include" # project portable library
"${PROJECT_SOURCE_DIR}/src/int" # project internal library
"${PROJECT_SOURCE_DIR}/src" ) # project sources (.cpp/.hpp)
target_precompile_headers (${PROJECT_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/src/config.hpp") # force include to all source files
set_target_properties (${PROJECT_NAME} PROPERTIES
CXX_STANDARD 23
CXX_STANDARD_REQUIRED ON
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}$<0:>" # put executable near the `./res` resource folder
EXPORT_COMPILE_COMMANDS ON # generate `out/build/${presetName}/compile_commands.json`
)
# # Apply: compile definitions # #
target_compile_definitions(${PROJECT_NAME} PRIVATE "${_DEFINITIONS_}")
# # Gather: sources # #
file(GLOB_RECURSE SOURCE_FILES_ CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/*.cpp")
list(FILTER SOURCE_FILES_ EXCLUDE REGEX ".*\\/_.*\\..*") # exclude files starting with uncderscore `_<file>`: https://regex101.com/r/DT6qGi/1
target_sources (${PROJECT_NAME} PRIVATE ${SOURCE_FILES_})
# # Apply: compiler and linker flags (from: file:///./CMakePresets.json) # #
target_link_options (${PROJECT_NAME} PRIVATE "${_FLAGS_LINKER_}") # flags: linker
target_link_options (${PROJECT_NAME} PRIVATE "${_FLAGS_COMP_LINK_}") # flags: linker & compiler (mutual)
target_compile_options(${PROJECT_NAME} PRIVATE "${_FLAGS_COMP_LINK_}") #
target_compile_options(${PROJECT_NAME} PRIVATE "${_FLAGS_COMPILE_0_}" # flags: complier, inherit lvl: base GNU/LLVM (common flags)
"${_FLAGS_COMPILE_1_}" # inherit lvl: base compiler (GCC/Clang)
"${_FLAGS_COMPILE_2_}") # inherit lvl: compiler (debug/release/..)
# # Setup: libraries # #
#find_package(OpenGL REQUIRED)
#add_subdirectory("${CMAKE_SOURCE_DIR}/dep/<lib>") # add git submodule lib
# ImGui - https://github.com/Challanger524/ChernoOpenGL-CMake/blob/main/CMakeLists.txt (example)
# Boost - https://github.com/boostorg/cmake?tab=readme-ov-file#using-boost-with-add_subdirectory
# git clone --depth 1 --recurse --shallow-submodules --jobs=4 "https://github.com/boostorg/boost" # clone in parent folder, or
# git submodule add --depth 1 --name boost -- "https://github.com/boostorg/boost" "dep/boost" # ..add as git submodule to the project, +
# git submodule update --init --recursive --depth 1 --jobs=4 -- "dep/boost" # ..init boost with all its submodules
# # Apply: project dependencies # #
#target_link_libraries (${PROJECT_NAME} PRIVATE OpenGL::GL <lib_target>)
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE #
"${CMAKE_SOURCE_DIR}/dep" # silence dependencies
) # child dirs will be treated as SYSTEM, even if opposite stated explicitly (with: -I)
###Stash###
#set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "" FORCE) # debug compiling
# debug file(GLOB_RECURSE)
#string (REPLACE ";" "\n" SOURCE_FILES_ "${SOURCE_FILES_}")
#message(FATAL_ERROR ${SOURCE_FILES_})
#cmake_path(GET CMAKE_CACHEFILE_DIR FILENAME PRESET_)
#message(${CMAKE_CACHEFILE_DIR})
#message(${PRESET_})