forked from kfrlib/kfr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
214 lines (181 loc) · 6.32 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Copyright (C) 2016 D Levin (http://www.kfrlib.com)
# This file is part of KFR
#
# KFR is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# KFR is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with KFR.
cmake_minimum_required(VERSION 3.1)
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS}" CACHE STRING "compile flags" FORCE)
project(kfr CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
message(STATUS "C++ compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} ${CMAKE_CXX_COMPILER} ")
message(STATUS CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR})
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
set (X86 TRUE)
else ()
set (X86 FALSE)
endif ()
if (X86)
message(STATUS X86)
endif ()
if (MSVC)
message(STATUS MSVC)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(CLANG 1)
else()
set(CLANG 0)
endif()
# Include autogenerated list of source files
include(sources.cmake)
option(ENABLE_TESTS "Enable tests and examples" OFF)
if (CLANG)
option(ENABLE_DFT "Enable DFT and related algorithms." ON)
option(ENABLE_DFT_NP "Enable Non-power of 2 DFT" ON)
if (X86)
option(ENABLE_DFT_MULTIARCH "Build DFT static libraries for various architectures. Requires Clang" OFF)
endif ()
else ()
option(ENABLE_DFT "Enable DFT and related algorithms." OFF)
option(ENABLE_DFT_NP "Enable Non-power of 2 DFT" OFF)
endif()
option(ENABLE_ASMTEST "Enable writing disassembly" OFF)
option(REGENERATE_TESTS "Regenerate auto tests" OFF)
option(DISABLE_CLANG_EXTENSIONS "Disable Clang vector extensions" OFF)
option(KFR_EXTENDED_TESTS "Extended tests (up to hour)" OFF)
option(SKIP_TESTS "Skip tests (only build)" OFF)
mark_as_advanced(ENABLE_ASMTEST)
mark_as_advanced(REGENERATE_TESTS)
mark_as_advanced(DISABLE_CLANG_EXTENSIONS)
if (NOT CPU_ARCH)
set(CPU_ARCH detect)
endif ()
if (CPU_ARCH STREQUAL "detect" AND X86)
message(STATUS "Detecting native cpu...")
try_run(
RUN_RESULT COMPILE_RESULT
"${CMAKE_CURRENT_BINARY_DIR}/tmpdir"
${CMAKE_CURRENT_SOURCE_DIR}/cmake/detect_cpu.cpp
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CMAKE_CURRENT_SOURCE_DIR}/include" -DCMAKE_CXX_STANDARD=17
-DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_CXX_EXTENSIONS=ON
COMPILE_OUTPUT_VARIABLE COMPILE_OUT
RUN_OUTPUT_VARIABLE RUN_OUT
)
if (COMPILE_RESULT AND RUN_RESULT EQUAL 0)
message(STATUS DETECTED_CPU = ${RUN_OUT})
set(CPU_ARCH ${RUN_OUT} CACHE STRING "Detected CPU" FORCE)
else()
message(STATUS COMPILE_RESULT = ${COMPILE_RESULT})
message(STATUS RUN_RESULT = ${RUN_RESULT})
message(STATUS COMPILE_OUT = ${COMPILE_OUT})
message(STATUS RUN_OUT = ${RUN_OUT})
endif ()
endif ()
include(cmake/target_set_arch.cmake)
add_library(use_arch INTERFACE)
target_set_arch(use_arch INTERFACE ${CPU_ARCH})
if (WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS)
add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
endif()
if (IOS)
set(STD_LIB)
else ()
set(STD_LIB stdc++)
endif ()
if (ANDROID)
set(PTHREAD_LIB)
else ()
set(PTHREAD_LIB pthread)
endif ()
# KFR library
add_library(kfr INTERFACE)
target_sources(kfr INTERFACE ${KFR_SRC})
target_include_directories(kfr INTERFACE include)
target_compile_options(kfr INTERFACE "$<$<CONFIG:DEBUG>:-DKFR_DEBUG>")
if (APPLE)
target_compile_options(kfr INTERFACE -faligned-allocation)
endif ()
if (NOT IOS)
if (CLANG)
target_compile_options(kfr INTERFACE -Xclang -mstackrealign)
elseif (NOT MSVC)
target_compile_options(kfr INTERFACE -mstackrealign)
endif ()
endif ()
if (MSVC)
target_compile_options(kfr INTERFACE -bigobj -EHsc)
else ()
target_link_libraries(kfr INTERFACE ${STD_LIB} ${PTHREAD_LIB} m)
endif ()
if (DISABLE_CLANG_EXTENSIONS)
target_compile_definitions(kfr INTERFACE -DCMT_DISABLE_CLANG_EXT)
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(kfr INTERFACE -Wno-ignored-qualifiers)
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(kfr INTERFACE -Wno-c++1z-extensions)
endif ()
if (NOT ENABLE_DFT)
target_compile_definitions(kfr INTERFACE -DKFR_NO_DFT)
endif ()
if (KFR_EXTENDED_TESTS)
target_compile_definitions(kfr INTERFACE -DKFR_EXTENDED_TESTS)
endif()
message(STATUS CPU_ARCH=${CPU_ARCH})
if (X86)
add_executable(detect_cpu ${CMAKE_CURRENT_SOURCE_DIR}/cmake/detect_cpu.cpp)
target_link_libraries(detect_cpu PRIVATE kfr)
target_set_arch(detect_cpu PRIVATE generic)
endif ()
if (ENABLE_DFT)
add_library(kfr_dft ${KFR_DFT_SRC})
target_link_libraries(kfr_dft kfr use_arch)
if (MSVC)
target_compile_options(kfr_dft PRIVATE -fp:fast)
else()
target_compile_options(kfr_dft PRIVATE -ffast-math)
endif()
if (ENABLE_DFT_NP)
target_compile_definitions(kfr_dft PUBLIC -DKFR_DFT_NPo2)
else ()
target_compile_definitions(kfr_dft PUBLIC -DKFR_DFT_NO_NPo2)
endif ()
if (ENABLE_CAPI_BUILD)
add_subdirectory(capi)
endif ()
endif()
if (ENABLE_TESTS)
add_subdirectory(examples)
add_subdirectory(tests)
add_subdirectory(tools)
endif ()
add_library(kfr_io ${KFR_IO_SRC})
target_link_libraries(kfr_io kfr)
install(TARGETS kfr kfr_io ARCHIVE DESTINATION lib LIBRARY DESTINATION lib)
if (ENABLE_DFT)
install(TARGETS kfr_dft ARCHIVE DESTINATION lib LIBRARY DESTINATION lib)
endif ()
install(DIRECTORY include/kfr DESTINATION include)
# uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake)
endif()