-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
116 lines (94 loc) · 3.73 KB
/
CMakeLists.txt
File metadata and controls
116 lines (94 loc) · 3.73 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
cmake_minimum_required(VERSION 3.20)
# Project name and version
project(MyProject VERSION 1.0.0 LANGUAGES CXX)
# --- FIX 1: Suppress download warning (timestamp) ---
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
# --- Coverage Option ---
option(ENABLE_COVERAGE "Activate Clang Source-based Code Coverage" OFF)
if(ENABLE_COVERAGE)
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
add_link_options(-fprofile-instr-generate -fcoverage-mapping)
endif()
# --- Linting: Clang-Tidy ---
find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
if(CLANG_TIDY_EXE)
message(STATUS "Clang-Tidy found: ${CLANG_TIDY_EXE}")
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
else()
message(WARNING "Clang-Tidy not found! Linting is disabled.")
endif()
# --- Testing Setup ---
enable_testing()
# --- 1. Configuration & C++ Standard ---
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(BUILD_TESTS "Build Unit Tests" ON)
# --- 2. Compiler Warnings & Sanitizers ---
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options(
-Wall -Wextra -Wpedantic
-Wconversion -Wsign-conversion
-Wshadow
)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
add_compile_options(-fsanitize=address,undefined -fno-omit-frame-pointer)
add_link_options(-fsanitize=address,undefined)
endif()
endif()
# --- 3. Load Dependencies ---
# HERE the include of your external file happens
# CMAKE_CURRENT_LIST_DIR ensures that the folder is found relative to CMakeLists.txt
include("${CMAKE_CURRENT_LIST_DIR}/Dependencies.cmake")
# --- 4. Collect Source Code ---
file(GLOB_RECURSE APP_SOURCES "src/cpp/*.cpp")
file(GLOB_RECURSE APP_HEADERS "src/include/*.hpp" "src/include/*.h")
list(FILTER APP_SOURCES EXCLUDE REGEX ".*main\\.cpp$")
# --- 5. Main Executable ---
add_executable(${PROJECT_NAME} src/cpp/main.cpp ${APP_SOURCES} ${APP_HEADERS})
target_include_directories(${PROJECT_NAME} PRIVATE src/include)
# Link libraries that were collected in Dependencies.cmake
if(EXTERNAL_LIBS)
target_link_libraries(${PROJECT_NAME} PRIVATE ${EXTERNAL_LIBS})
endif()
# --- 6. Tests (GoogleTest Integration) ---
if(BUILD_TESTS)
# We keep GTest here as it is specific to tests.
# We could also move it out, but GTest is often handled separately.
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
)
set(INSTALL_GTEST OFF)
FetchContent_MakeAvailable(googletest)
file(GLOB_RECURSE TEST_SOURCES "src/tests/*.cpp")
add_executable(unit_tests ${TEST_SOURCES} ${APP_SOURCES})
target_include_directories(unit_tests PRIVATE src/include)
target_link_libraries(unit_tests PRIVATE GTest::gtest_main)
include(GoogleTest)
gtest_discover_tests(unit_tests)
endif()
# --- 7. Installation & Packaging ---
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
# install(FILES config.json DESTINATION bin) # Optional
set(CPACK_PACKAGE_VENDOR "YourName")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "My cool C++ Project")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
if(WIN32)
set(CPACK_GENERATOR "ZIP;NSIS")
elseif(APPLE)
set(CPACK_GENERATOR "DragNDrop")
else()
# Relevant for your Linux setup (RPM for Fedora, TGZ often used on Arch)
set(CPACK_GENERATOR "DEB;RPM;TGZ")
endif()
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "YourName <your.email@example.com>")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
include(CPack)