Skip to content

Commit a3a0b6b

Browse files
committed
Refactor project: separate app target
1 parent 51ee44d commit a3a0b6b

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

CMakeLists.txt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1010

1111
# Options
1212
option(ENABLE_TESTING "Build tests" ON)
13+
option(BUILD_APP "Build the demo application" ON)
14+
option(BUILD_DOCS "Enable documentation via Doxygen" ON)
1315

1416
# Add custom "Sanitize" build type
1517
if(CMAKE_CONFIGURATION_TYPES)
@@ -21,26 +23,18 @@ endif()
2123
# Load cmake modules
2224
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
2325

24-
# Warnings, sanitizers, Link Time Optimiziatiion (LTO)
26+
# Warnings, sanitizers, Link Time Optimization (LTO)
2527
include(options/LTO)
2628
include(options/Warnings)
2729
include(options/Sanitizers)
2830

2931
# === Libraries ===
30-
add_subdirectory(src) # modern_cpp_template::math
32+
add_subdirectory(src) # modern_cpp_project::math
3133

3234
# === Application ===
33-
add_executable(${PROJECT_NAME}
34-
src/main.cpp
35-
)
36-
37-
target_link_libraries(${PROJECT_NAME}
38-
PRIVATE math
39-
)
40-
41-
enable_lto(${PROJECT_NAME})
42-
enable_sanitizers(${PROJECT_NAME})
43-
enable_strict_warnings(${PROJECT_NAME})
35+
if(BUILD_APP)
36+
add_subdirectory(app) # modern_cpp_project_app
37+
endif()
4438

4539
# === Tests ===
4640
if(ENABLE_TESTING)
@@ -49,7 +43,9 @@ if(ENABLE_TESTING)
4943
endif()
5044

5145
# === Docs ===
52-
include(tools/Doxygen)
46+
if(BUILD_DOCS)
47+
include(tools/Doxygen)
48+
endif()
5349

5450
# === Installation ===
5551
include(install/InstallConfig)

CMakePresets.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"binaryDir": "${sourceDir}/build/${presetName}",
1313
"cacheVariables": {
1414
"ENABLE_TESTING": "ON",
15+
"BUILD_APP": "ON",
16+
"BUILD_DOCS": "ON",
1517
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
1618
},
1719
"description": "Common settings for all configurations"

app/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
add_executable(${PROJECT_NAME}_app
2+
main.cpp
3+
)
4+
5+
target_link_libraries(${PROJECT_NAME}_app
6+
PRIVATE ${PROJECT_NAME}::math
7+
)
8+
9+
enable_lto(${PROJECT_NAME}_app)
10+
enable_sanitizers(${PROJECT_NAME}_app)
11+
enable_strict_warnings(${PROJECT_NAME}_app)
File renamed without changes.

0 commit comments

Comments
 (0)