-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
121 lines (103 loc) · 2.95 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
cmake_minimum_required(VERSION 3.8)
project(
sp3
VERSION 1.1.0
DESCRIPTION "Sp3 Fundamental Utils for Satellite Geodesy"
LANGUAGES CXX
)
# Ensure required libraries are available
find_package(datetime REQUIRED)
# Pass the library dependencies to subdirectories
set(PROJECT_DEPENDENCIES datetime)
# Enable clang-tidy option
option(ENABLE_CLANG_TIDY "Enable clang-tidy checks" OFF)
# Define an option for building tests (defaults to ON)
option(BUILD_TESTING "Enable building of tests" ON)
# compiler flags
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED On)
set(CMAKE_CXX_EXTENSIONS Off)
add_compile_options(-Wall
-Wextra
-Werror
-pedantic
-W
-Wshadow
$<$<CONFIG:Release>:-O2>
$<$<CONFIG:Release>:-march=native>
$<$<CONFIG:Debug>:-g>
$<$<CONFIG:Debug>:-pg>
$<$<CONFIG:Debug>:-Wdisabled-optimization>
)
add_compile_definitions(
$<$<CONFIG:Debug>:DEBUG>
)
# clang-tidy (targets that follow will be checked)
if(ENABLE_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=bugprone-*,\
clang-analyzer-*,\
cppcoreguidelines-*,\
llvm-*,\
modernize-*,\
performance-*,\
-modernize-use-trailing-return-type,\
-cppcoreguidelines-pro-bounds-pointer-arithmetic,\
-cppcoreguidelines-pro-bounds-constant-array-index,\
-cppcoreguidelines-pro-type-vararg")
message(STATUS "clang-tidy is enabled.")
else()
message(STATUS "clang-tidy is disabled. To enable it, use -DENABLE_CLANG_TIDY=ON.")
endif()
# the library and includes
add_library(sp3)
target_include_directories(sp3
PUBLIC
# Public headers during build time
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
# Public headers during install time
$<INSTALL_INTERFACE:include/sp3>
PRIVATE
# Private/internal headers only during build time (src/)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
# Internal/private headers during install time (from include/sp3/core)
$<INSTALL_INTERFACE:include/sp3/core>
)
# library source code
add_subdirectory(src/lib)
# disable clang-tidy (targets that follow will not be checked)
set(CMAKE_CXX_CLANG_TIDY "")
# The tests
if(BUILD_TESTING)
include(CTest)
add_subdirectory(test/examples)
enable_testing()
endif()
# install library
install(TARGETS sp3
EXPORT sp3Targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
# Install public headers at: $PREFIX/sp3/...
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION include/sp3
)
# Install private headers to a separate directory $PREFIX/sp3/core
install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/core/
DESTINATION include/sp3/core
)
install(EXPORT sp3Targets
FILE sp3Targets.cmake
NAMESPACE dso::
DESTINATION lib/cmake
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"sp3ConfigVersion.cmake"
VERSION ${sp3_version}
COMPATIBILITY AnyNewerVersion
)
install(FILES "sp3Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/sp3ConfigVersion.cmake"
DESTINATION lib/cmake
)