forked from AUSAXS/AUSAXS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
156 lines (144 loc) · 5.34 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
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
cmake_minimum_required(VERSION 3.15)
project(AUSAXS VERSION 1.0)
option(GUI "Enable GUI executables" OFF)
option(DLIB "Download and use the dlib minimizers" ON)
option(BUILD_PLOT_EXE "Compile the plotting utility as an executable for the current platform" OFF)
option(CONSTEXPR_TABLES "Generate lookup tables at compile-time" OFF)
set(ARCH "native" CACHE STRING "Target architecture. Default: native")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
add_compile_definitions("CONSTEXPR_TABLES=${CONSTEXPR_TABLES};$<$<CONFIG:DEBUG>:DEBUG=1;SAFE_MATH=1>")
if (WIN32)
if (MSVC)
add_compile_definitions("NOMINMAX")
add_compile_options(
/fp:fast /constexpr:steps10000000000 /Zm500
/wd4267 # disable size_t --> int, unsigned int conversions
/wd4244 # disable double --> float,int conversions
"$<$<STREQUAL:${ARCH},x86-64>:/arch:AVX>"
"$<$<STREQUAL:${ARCH},arm64>:/arch:armv8.0>"
)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
elseif (MINGW)
add_compile_options(
-Ofast -pipe -mavx
"$<$<STREQUAL:${CMAKE_CXX_COMPILER_ID},Clang>:-fconstexpr-steps=1000000000>"
"$<$<STREQUAL:${CMAKE_CXX_COMPILER_ID},GNU>:-fconstexpr-ops-limit=10000000000>"
"$<$<CONFIG:DEBUG>:-g;-Wall;-Wpedantic;-Wextra;-march=native>"
"$<$<AND:$<CONFIG:RELEASE>,$<STREQUAL:${ARCH},x86-64>>:-march=x86-64-v3>"
"$<$<AND:$<CONFIG:RELEASE>,$<STREQUAL:${ARCH},native>>:-march=native>"
)
endif()
elseif (APPLE)
add_compile_options(
-Ofast -pipe
"$<$<STREQUAL:${CMAKE_CXX_COMPILER_ID},Clang>:-fconstexpr-steps=1000000000>"
"$<$<STREQUAL:${CMAKE_CXX_COMPILER_ID},GNU>:-fconstexpr-ops-limit=10000000000>"
"$<$<CONFIG:DEBUG>:-g;-Wall;-Wpedantic;-Wextra>"
"$<$<AND:$<CONFIG:RELEASE>,$<STREQUAL:${ARCH},x86-64>>:-march=x86-64>"
"$<$<AND:$<CONFIG:RELEASE>,$<STREQUAL:${ARCH},arm64>>:-march=armv8-a>"
)
elseif (UNIX)
# add_compile_definitions("$<$<CONFIG:DEBUG>:_GLIBCXX_DEBUG>")
add_compile_options(
-Ofast -pipe -mavx
"$<$<STREQUAL:${CMAKE_CXX_COMPILER_ID},Clang>:-fconstexpr-steps=1000000000>"
"$<$<STREQUAL:${CMAKE_CXX_COMPILER_ID},GNU>:-fconstexpr-ops-limit=10000000000>"
"$<$<CONFIG:DEBUG>:-g;-Wall;-Wpedantic;-Wextra;-march=native>"
"$<$<AND:$<CONFIG:RELEASE>,$<STREQUAL:${ARCH},x86-64>>:-march=x86-64-v3>"
"$<$<AND:$<CONFIG:RELEASE>,$<STREQUAL:${ARCH},native>>:-march=native>"
)
endif()
############################################
## Dependencies ##
############################################
include(FetchContent)
set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
if (DLIB)
FetchContent_Declare(
dlib
GIT_REPOSITORY https://github.com/davisking/dlib
GIT_TAG v19.24.4
GIT_PROGRESS TRUE
)
# tell dlib not to link with various unnecessary libraries
set(DLIB_NO_GUI_SUPPORT TRUE)
set(DLIB_JPEG_SUPPORT OFF)
set(DLIB_LINK_WITH_SQLITE3 OFF)
set(DLIB_USE_BLAS OFF)
set(DLIB_USE_LAPACK OFF)
set(DLIB_USE_CUDA OFF)
set(DLIB_PNG_SUPPORT OFF)
set(DLIB_GIF_SUPPORT OFF)
set(DLIB_WEBP_SUPPORT OFF)
set(DLIB_JXL_SUPPORT OFF)
set(DLIB_USE_FFTW OFF)
set(DLIB_USE_MKL_FFT OFF)
set(DLIB_USE_FFMPEG OFF)
set(CMAKE_CXX_STANDARD 17) # dlib must be compiled with C++17
FetchContent_MakeAvailable(dlib)
set(CMAKE_CXX_STANDARD 20) # continue with C++20
add_compile_definitions("DLIB_AVAILABLE")
endif()
FetchContent_Declare(
backward
GIT_REPOSITORY https://github.com/bombela/backward-cpp
)
FetchContent_Declare(
thread_pool
GIT_REPOSITORY https://github.com/bshoshany/thread-pool
)
FetchContent_Declare(
gcem
GIT_REPOSITORY https://github.com/kthohr/gcem
)
FetchContent_MakeAvailable(thread_pool GCEM backward)
include_directories(${thread_pool_SOURCE_DIR}/include ${gcem_SOURCE_DIR}/include ${backward_SOURCE_DIR})
############################################
## Find and link CURL ##
############################################
if (WIN32)
add_compile_definitions("CURL_STATICLIB")
find_package(CURL REQUIRED)
set(LIBS -static CURL::libcurl)
include_directories(${CURL_INCLUDE_DIRS}) # find_package apparently does not always include the headers
elseif (APPLE)
find_package(CURL REQUIRED)
set(LIBS CURL::libcurl)
link_libraries("$<$<CONFIG:Debug>:-ldwarf>")
elseif(UNIX)
find_package(CURL REQUIRED)
set(LIBS CURL::libcurl -static-libgcc -static-libstdc++)
link_libraries("$<$<CONFIG:Debug>:-ldwarf>")
endif()
############################################
## Doxygen ##
############################################
find_package(Doxygen)
if (DOXYGEN_FOUND)
set(sim3a_Doxygen "${CMAKE_BINARY_DIR}/saxs.dox")
configure_file(${CMAKE_SOURCE_DIR}/scripts/ausaxs.dox.in ${sim3a_Doxygen} @ONLY)
add_custom_target(
doc
${DOXYGEN_EXECUTABLE} ${sim3a_Doxygen}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif()
############################################
## Build library ##
############################################
if (${CMAKE_BUILD_TYPE} STREQUAL "Release")
include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_SUPPORTED)
else()
set(LTO_SUPPORTED OFF)
endif()
add_subdirectory(source)
add_subdirectory(tests)
add_subdirectory(executable)