-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
170 lines (148 loc) · 5.97 KB
/
Copy pathCMakeLists.txt
File metadata and controls
170 lines (148 loc) · 5.97 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
cmake_minimum_required(VERSION 3.13)
# Version detection: Git tag with fallback to 0.0.0
# conan portfile can inject version via -DCONSTFILT_VERSION=<version>
if(DEFINED CONSTFILT_VERSION)
set(_constfilt_version "${CONSTFILT_VERSION}")
else()
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE _constfilt_git_tag
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
RESULT_VARIABLE _git_result
)
if(_git_result EQUAL 0)
string(REGEX REPLACE "^v" "" _constfilt_version "${_constfilt_git_tag}")
else()
set(_constfilt_version "0.0.0")
endif()
else()
set(_constfilt_version "0.0.0")
endif()
endif()
project(constfilt VERSION ${_constfilt_version} LANGUAGES CXX)
include(GNUInstallDirs)
################################################################################
# Public INTERFACE target (the only target external consumers need)
################################################################################
add_library(constfilt INTERFACE)
target_include_directories(constfilt INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_features(constfilt INTERFACE cxx_std_17)
add_library(constfilt::constfilt ALIAS constfilt)
################################################################################
# consteig + gcem (vendored under include/constfilt/vendor/)
# To update: run scripts/vendor_consteig.sh
################################################################################
set(_constfilt_vendor "${CMAKE_CURRENT_SOURCE_DIR}/include/constfilt/vendor")
if(NOT TARGET consteig::consteig)
add_library(consteig INTERFACE)
target_include_directories(consteig SYSTEM INTERFACE
$<BUILD_INTERFACE:${_constfilt_vendor}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/constfilt/vendor>
)
add_library(consteig::consteig ALIAS consteig)
endif()
if(NOT TARGET gcem::gcem)
add_library(gcem INTERFACE)
target_include_directories(gcem SYSTEM INTERFACE
$<BUILD_INTERFACE:${_constfilt_vendor}/gcem>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/constfilt/vendor/gcem>
)
target_compile_definitions(gcem INTERFACE GCEM_TRAITS_BUILTIN)
add_library(gcem::gcem ALIAS gcem)
endif()
target_link_libraries(constfilt INTERFACE
consteig::consteig
gcem
)
# INTERFACE_SYSTEM_INCLUDE_DIRECTORIES does not propagate transitively beyond
# direct consumers, so re-declare vendor paths as SYSTEM on constfilt itself so
# that downstream targets see -isystem and suppress third-party warnings (e.g.
# -Wfloat-equal in gcem).
target_include_directories(constfilt SYSTEM INTERFACE
$<BUILD_INTERFACE:${_constfilt_vendor}>
$<BUILD_INTERFACE:${_constfilt_vendor}/gcem>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/constfilt/vendor>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/constfilt/vendor/gcem>
)
################################################################################
# Development mode (skipped when consumed via add_subdirectory/FetchContent)
################################################################################
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
option(CONSTFILT_BUILD_TESTS "Build constfilt tests" OFF)
option(CONSTFILT_COMPILE_ONLY
"Build tests as object libraries only (no run, no link to gtest); used for ARM cross-compile constexpr verification."
OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_library(constfilt_warnings INTERFACE)
target_compile_options(constfilt_warnings INTERFACE
-Wall
-Wextra
-pedantic
-Werror
-Wmisleading-indentation
-Wshadow
-Wconversion
-Wsign-conversion
-Wnull-dereference
-Wdouble-promotion
-Wformat=2
-Wundef
)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(constfilt_warnings INTERFACE
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
)
endif()
if(CONSTFILT_BUILD_TESTS)
add_subdirectory(test_dependencies)
enable_testing()
add_subdirectory(tests)
endif()
option(CONSTFILT_BUILD_PROFILING "Build profiling suite" OFF)
if(CONSTFILT_BUILD_PROFILING)
add_subdirectory(profiling)
endif()
endif()
################################################################################
# Install rules (package distribution)
################################################################################
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CMakePackageConfigHelpers)
install(TARGETS constfilt consteig gcem EXPORT constfiltTargets)
install(DIRECTORY include/constfilt DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT constfiltTargets
FILE constfiltTargets.cmake
NAMESPACE constfilt::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/constfilt
)
configure_package_config_file(
cmake/constfiltConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/constfiltConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/constfilt
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/constfiltConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/constfiltConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/constfiltConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/constfilt
)
endif()