-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
131 lines (111 loc) · 5.29 KB
/
CMakeLists.txt
File metadata and controls
131 lines (111 loc) · 5.29 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
# ── CMakeLists.txt (top level) ────────────────────────────────────────────────
cmake_minimum_required(VERSION 3.20) # 3.20+ for gtest_discover_tests niceties
project(cpp_project_template
VERSION 0.1.0
LANGUAGES CXX)
# ── Global compiler defaults (but avoid leaking flags) ───────────────────────
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # helps clang-tools; optional
# Set RPATH for portable library discovery
# $ORIGIN = directory containing the executable, ../lib = library directory
# See docs/rpath-guide.md for detailed explanation
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # Use different RPATH for build vs install
# -----------------------------------------------------------------------------
# Coverage option
# -----------------------------------------------------------------------------
option(ENABLE_COVERAGE "Enable code coverage" OFF)
if(ENABLE_COVERAGE)
message(STATUS "Code coverage enabled")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
else()
message(WARNING "Code coverage only supported with GCC")
endif()
endif()
# -----------------------------------------------------------------------------
# 1. Primary code
# -----------------------------------------------------------------------------
add_subdirectory(src/example_public_private)
add_subdirectory(src/example_interface)
add_subdirectory(src/example_static)
add_subdirectory(src/example_shared)
add_subdirectory(src/example_plugin_loader)
add_subdirectory(src/example_plugin_impl)
add_subdirectory(src/main) # -> target "main_exec" etc.
# -----------------------------------------------------------------------------
# 2. Unit-test toggle
# -----------------------------------------------------------------------------
option(ENABLE_UNIT_TESTS "Build GoogleTest unit tests" ON)
if(ENABLE_UNIT_TESTS)
enable_testing() # Makes ctest happy to find the tests
include(FetchContent)
# First try system / package-manager copy; fall back to FetchContent
find_package(GTest CONFIG QUIET)
if(NOT GTest_FOUND)
message(STATUS "GTest not found, fetching google test v1.14.0")
# Prevent GoogleTest from being installed
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
set(INSTALL_GMOCK OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
DOWNLOAD_EXTRACT_TIMESTAMP TRUE # <- fixes CMP0135 warning
)
FetchContent_MakeAvailable(googletest) # exports GTest::gtest / gtest_main
endif()
add_subdirectory(tests)
endif()
# Install rules - only install shippable/runtime components
install(TARGETS main_exec
RUNTIME DESTINATION bin)
# Install shared libraries (needed at runtime)
install(TARGETS example_shared example_plugin_impl
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
# Note: Static libraries and headers are typically not installed unless
# this project is meant to be a library package for other developers.
# Uncomment the lines below if you want to ship a development package:
#
# install(TARGETS example_static example_plugin_loader
# ARCHIVE DESTINATION lib)
# install(DIRECTORY src/example_public_private/include/
# DESTINATION include/example_public_private)
# install(DIRECTORY src/example_interface/include/
# DESTINATION include/example_interface)
# install(DIRECTORY src/example_usage/include/
# DESTINATION include/example_usage)
# install(DIRECTORY src/example_static/
# DESTINATION include/example_static
# FILES_MATCHING PATTERN "*.hpp")
# install(DIRECTORY src/example_shared/
# DESTINATION include/example_shared
# FILES_MATCHING PATTERN "*.hpp")
# install(DIRECTORY src/example_plugin_loader/
# DESTINATION include/example_plugin_loader
# FILES_MATCHING PATTERN "*.hpp")
# install(DIRECTORY src/example_plugin_impl/
# DESTINATION include/example_plugin_impl
# FILES_MATCHING PATTERN "*.hpp")
# -----------------------------------------------------------------------------
# 3. CPack configuration for packaging
# -----------------------------------------------------------------------------
set(CPACK_PACKAGE_NAME "cpp-project-template")
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Modern C++ Project Template")
set(CPACK_PACKAGE_VENDOR "Your Name")
set(CPACK_PACKAGE_CONTACT "your.email@example.com")
# Package types to generate
set(CPACK_GENERATOR "TGZ;ZIP")
# For Linux distributions - DEB packaging disabled for now
# if(UNIX AND NOT APPLE)
# list(APPEND CPACK_GENERATOR "DEB")
# set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Your Name <your.email@example.com>")
# set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
# endif()
include(CPack)