-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
142 lines (116 loc) · 3.84 KB
/
CMakeLists.txt
File metadata and controls
142 lines (116 loc) · 3.84 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
cmake_minimum_required(VERSION 3.20)
# Read version from VERSION file
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" PROJECT_VERSION)
string(STRIP "${PROJECT_VERSION}" PROJECT_VERSION)
project(graph3_library
VERSION ${PROJECT_VERSION}
DESCRIPTION "Modern C++20 graph library"
HOMEPAGE_URL "https://github.com/pratzl/desc"
LANGUAGES CXX
)
# Include custom CMake modules
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(StandardProjectSettings)
include(CompilerWarnings)
include(Sanitizers)
include(CodeCoverage)
include(CompilerCache)
include(PrecompiledHeaders)
include(CPM)
# C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Options
option(BUILD_TESTS "Build unit tests" ON)
option(BUILD_EXAMPLES "Build examples" ON)
option(BUILD_BENCHMARKS "Build benchmarks" OFF)
option(BUILD_DOCS "Build documentation" OFF)
option(ENABLE_COVERAGE "Enable code coverage" OFF)
option(ENABLE_SANITIZERS "Enable sanitizers (address, undefined)" OFF)
option(ENABLE_UNITY_BUILD "Enable unity builds for faster compilation" OFF)
option(ENABLE_CACHE "Enable compiler cache (ccache/sccache)" ON)
option(ENABLE_PCH "Enable precompiled headers" ON)
# Enable compiler cache
enable_compiler_cache()
# Enable unity builds if requested
if(ENABLE_UNITY_BUILD)
set(CMAKE_UNITY_BUILD ON)
message(STATUS "Unity builds enabled")
endif()
# Library target (header-only)
add_library(graph3 INTERFACE)
add_library(graph::graph3 ALIAS graph3)
target_include_directories(graph3 INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_features(graph3 INTERFACE cxx_std_20)
# Link tl::expected for optional cycle detection in topological sort
target_link_libraries(graph3 INTERFACE tl::expected)
# Apply compiler warnings
set_project_warnings(graph3)
# Apply sanitizers if enabled
enable_sanitizers(graph3)
# Apply code coverage if enabled
enable_coverage(graph3)
# Apply precompiled headers if enabled
enable_precompiled_headers(graph3)
# Testing
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# Examples
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# Benchmarks
if(BUILD_BENCHMARKS)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/benchmark/CMakeLists.txt")
add_subdirectory(benchmark)
else()
message(STATUS "Benchmark directory exists but no CMakeLists.txt found - skipping")
endif()
endif()
# Documentation
if(BUILD_DOCS)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/docs/CMakeLists.txt")
add_subdirectory(docs)
else()
message(STATUS "Docs directory exists but no CMakeLists.txt found - skipping")
endif()
endif()
# Installation configuration
include(InstallConfig)
# Packaging with CPack
set(CPACK_PACKAGE_NAME "graph3")
set(CPACK_PACKAGE_VENDOR "pratzl")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Modern C++20 graph library")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_INSTALL_DIRECTORY "graph3")
# Optional license and readme
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
endif()
# Package generators based on platform
set(CPACK_GENERATOR "TGZ;ZIP")
if(WIN32)
list(APPEND CPACK_GENERATOR "NSIS")
elseif(APPLE)
list(APPEND CPACK_GENERATOR "DragNDrop")
elseif(UNIX)
list(APPEND CPACK_GENERATOR "DEB;RPM")
endif()
# Debian package metadata
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "pratzl")
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "all")
# RPM package metadata
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
set(CPACK_RPM_PACKAGE_ARCHITECTURE "noarch")
include(CPack)