-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
195 lines (151 loc) · 6.73 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
cmake_minimum_required(VERSION 3.18)
set(CCMATH_BUILD_VERSION 0.2.0)
project(
ccmath
VERSION ${CCMATH_BUILD_VERSION}
DESCRIPTION "A C++17 Compile Time <cmath> Library"
HOMEPAGE_URL "https://github.com/Rinzii/ccmath"
LANGUAGES CXX
)
set(is_root_project OFF) # Identifies if this is the root project
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(is_root_project ON)
endif ()
if(NOT CCMATH_SOURCE_DIR)
set(CCMATH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif ()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
message(STATUS "CCMath version: ${PROJECT_VERSION}")
# TO THE IMPLEMENTOR: If CCMATH_BUILD_TESTS is set to OFF then googletest can be deleted from the ext folder.
option(CCMATH_BUILD_TESTS "Build ccmath tests" ${is_root_project})
option(CCMATH_FIND_GTEST_PACKAGE "Enable finding of gtest package" OFF)
option(CCMATH_BUILD_EXAMPLES "Build ccmath examples" ${is_root_project})
option(CCMATH_BUILD_BENCHMARKS "Build ccmath benchmarks" ${is_root_project})
option(CCMATH_FIND_GBENCH_PACKAGE "Enable finding of google benchmark package" OFF)
option(CCMATH_INSTALL "Setup install and package steps" ${is_root_project})
option(CCMATH_ENABLE_EXTENSIONS "Enable the extended ccmath library that adds helpful additional methods that are not defined by the standard" ${is_root_project})
option(CCMATH_ENABLE_RUNTIME_SIMD "Enable SIMD optimization for runtime evaluation (does not effect compile time)" ON)
option(CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS "Enable user defined optimization macros instead of having ccmath define its own internal ones in cmake" OFF)
option(CCMATH_DISABLE_ERRNO "Disable the use of errno in ccmath during runtime" OFF)
# include the global configuration file
include(cmake/GlobalConfig.cmake)
add_library(${PROJECT_NAME}-compile-options INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME}-compile-options ALIAS ${PROJECT_NAME}-compile-options)
##### ccmath specified compiler options
# Generic clang/gcc compiler options
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|IntelLLVM")
target_compile_options(${PROJECT_NAME}-compile-options INTERFACE
-Wall
-Wextra
-Wconversion
-Werror=return-type
-Wno-pedantic
# Allow FMA instructions
-ffp-contract=fast
# Macros to define
-DNOMINMAX
)
if (CMAKE_CXX_COMPILER_ID STREQUAL MSVC)
target_compile_options(${PROJECT_NAME}-compile-options INTERFACE
/W3
/WX
/permissive-
/Zc:__cplusplus
# Macros to define
/DNOMINMAX
/D_ENABLE_EXTENDED_ALIGNED_STORAGE
)
endif ()
# Disable intel specific warnings that don't apply to us.
if (CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM)
target_compile_options(${PROJECT_NAME}-compile-options INTERFACE
-Wno-tautological-constant-compare
)
endif ()
# TODO: Remove this later.
# Some variables have been provided but are not currently being used, but it would not atm make sense to remove them.
# So to clean up the warnings we are just silencing these specific cases.
target_compile_options(${PROJECT_NAME}-compile-options INTERFACE
-Wno-unused-but-set-variable -Wno-unused-value -Wno-unused-parameter
)
endif ()
include(ccmath_internal_headers.cmake)
include(ccmath_core_headers.cmake)
add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_sources(${PROJECT_NAME} INTERFACE "$<BUILD_INTERFACE:${ccmath_internal_headers}>")
target_sources(${PROJECT_NAME} INTERFACE "$<BUILD_INTERFACE:${ccmath_core_headers}>")
if (CCMATH_ENABLE_EXTENSIONS)
include(ccmath_extensions_headers.cmake)
target_sources(${PROJECT_NAME} INTERFACE "$<BUILD_INTERFACE:${ccmath_extensions_headers}>")
endif ()
target_include_directories(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>)
target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>)
target_link_libraries(${PROJECT_NAME} INTERFACE
${PROJECT_NAME}::${PROJECT_NAME}-compile-options
)
if (CCMATH_ENABLE_RUNTIME_SIMD)
target_compile_definitions(${PROJECT_NAME} INTERFACE CCM_CONFIG_USE_RT_SIMD)
endif ()
if (NOT CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS)
# Set these definitions based on the build type to aid in identifying the optimization level.
# These are essential when dealing with compiler specific outcomes that are based on the optimization level.
target_compile_definitions(${PROJECT_NAME}
INTERFACE
$<$<CONFIG:Debug>:CCM_CONFIG_DEBUG> # -O0
$<$<CONFIG:RelWithDebInfo>:CCM_CONFIG_OPTIMIZE> # -O2
$<$<CONFIG:Release>:CCM_CONFIG_AGGRESSIVELY_OPTIMIZE> # -O3
$<$<CONFIG:MinSizeRel>:CCM_CONFIG_MINSIZE> # -Os
)
endif ()
if (CCMATH_DISABLE_ERRNO)
target_compile_definitions(${PROJECT_NAME} INTERFACE CCM_CONFIG_DISABLE_ERRNO)
endif ()
configure_file(cmake/version.hpp.in "${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}/version.hpp" @ONLY)
if (CCMATH_BUILD_EXAMPLES OR CCMATH_BUILD_BENCHMARKS OR CCMATH_BUILD_TESTS)
add_subdirectory(thirdparty)
endif ()
if (CCMATH_BUILD_EXAMPLES)
add_subdirectory(example)
endif ()
if (CCMATH_BUILD_BENCHMARKS)
add_subdirectory(benchmark)
endif ()
if (CCMATH_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif ()
if (CCMATH_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
install(TARGETS
${PROJECT_NAME}
${PROJECT_NAME}-compile-options
EXPORT ${PROJECT_NAME}-targets
)
# Manually specify the headers to install
install(DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING PATTERN "*.hpp"
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}/version.hpp"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)
install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}-targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
configure_package_config_file(
cmake/${PROJECT_NAME}-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
endif ()