-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
163 lines (128 loc) · 5.04 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# ===========================================================================
# CMake project setup
# ===========================================================================
cmake_minimum_required(VERSION 3.14)
# Provides the version from the version header
include(cmake/version.cmake)
parse_version()
project(replaceme
LANGUAGES C CXX
# Set the version in the version header
VERSION ${REPLACEME_VERSION}
)
# ---------------------------------------------------------------------------
# Configuration
# The project offers some configuration options that may be altered here.
# In general those can be overwritten by cmake invokation with -D command
# line options.
#
# Example: -DENABLE_TESTING=off will overwrite the value configured here
#
# ---------------------------------------------------------------------------
option(ENABLE_INSTALL "Activates support for installing the project" ON)
option(ENABLE_TESTING "Activates support for unit tests" ON)
# For more information on CCache see https://ccache.dev/
option(ENABLE_CCACHE "Enables CCache integration" ON)
# Set your C++ version here
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# ---------------------------------------------------------------------------
# Setup for CTest / CCache / install dirs
# ---------------------------------------------------------------------------
# Install directories according to GNU standard
if(ENABLE_INSTALL)
include(GNUInstallDirs)
endif()
# Unit testing
if(ENABLE_TESTING)
include(CTest)
include(GoogleTest)
include(FindGTest)
endif()
# CCache integration
if(ENABLE_CCACHE)
find_program(CCACHE_FOUND ccache REQUIRED)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
endif()
endif()
# ---------------------------------------------------------------------------
# Find additionally required packages
# If your project requires additional packages, you can add them here.
# Of just uncomment the specific parts of already available snippets.
# ---------------------------------------------------------------------------
## Find threads library. Prefer pthread, if available.
#set(THREADS_PREFER_PTHREAD_FLAG ON)
#find_package(Threads REQUIRED)
## Find boost library with some components
#find_package(Boost REQUIRED
# COMPONENTS
# date_time
# filesystem
# thread
#)
# ---------------------------------------------------------------------------
# Setup summary
# ---------------------------------------------------------------------------
message(STATUS "----------------------------------------------------------------------")
message(STATUS "Building ${CMAKE_PROJECT_NAME} in version ${CMAKE_PROJECT_VERSION}")
message(STATUS " C++ standard: ${CMAKE_CXX_STANDARD}")
message(STATUS " Installing enabled: ${ENABLE_INSTALL}")
message(STATUS " Unit tests enabled: ${ENABLE_TESTING}")
message(STATUS " CCache enabled: ${ENABLE_CCACHE}")
message(STATUS "----------------------------------------------------------------------")
# ===========================================================================
# Build targets
# Put the target definitions for your libraries / executables here.
# Add them to the INSTALL_TARGETS list if you want them to be installed
#
# NOTE: Installation requires ENABLE_INSTALL to be active, see config
# section above.
# ===========================================================================
add_executable(hello
src/hello.cpp
)
list(APPEND INSTALL_TARGETS hello)
# ===========================================================================
# Unit tests
# ===========================================================================
if(ENABLE_TESTING)
add_subdirectory(test)
endif()
# ===========================================================================
# Installation
# ===========================================================================
if(ENABLE_INSTALL)
# Install targets and define the export targets.
install(
TARGETS ${INSTALL_TARGETS}
EXPORT replacemeTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Define the replacemeTargets.cmake file and the namespace for exported targets.
install(
EXPORT replacemeTargets
FILE replacemeTargets.cmake
NAMESPACE replaceme::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/replaceme
)
include(CMakePackageConfigHelpers)
# Generate a replacemeConfigVersion.cmake file.
# Preconfigured is a compatibility of 'SameMajorVersion'. Adjust this to your needs.
# https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html#generating-a-package-version-file
write_basic_package_version_file(
"replacemeConfigVersion.cmake"
VERSION ${REPLACEME_VERSION}
COMPATIBILITY SameMajorVersion
)
# Install the config files.
install(
FILES
"replacemeConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/replacemeConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/replaceme
)
endif()