-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
146 lines (134 loc) · 5.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
#######################################################
### External libraries ###
#######################################################
# Async++
CPMAddPackage(
NAME Async++
GITHUB_REPOSITORY Amanieu/asyncplusplus
GIT_TAG v1.1
VERSION 1.1
DOWNLOAD_ONLY TRUE
OPTIONS
"BUILD_SHARED_LIBS OFF"
)
if (Async++_ADDED)
SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Build as shared lib")
add_subdirectory(${Async++_SOURCE_DIR} ${Async++_SOURCE_DIR}/../Async++-binaries EXCLUDE_FROM_ALL)
if (NOT TARGET Async++)
message(FATAL_ERROR Async++ directory included but Async++ target not found)
endif ()
elseif (Async++_FOUND)
if (NOT TARGET Async++)
message(FATAL_ERROR Async++ found but Async++ target not found)
endif ()
else ()
message(FATAL_ERROR Cannot find or download Async++)
endif ()
if (UNIX)
if (APPLE)
set(COMPILE_OPTIONS_TO_IGNORE_ASYNCPP_WARNINGS
-Wno-shadow-field-in-constructor
-Wno-shadow
-Wno-shadow-field
-Wno-sign-conversion
-Wno-implicit-float-conversion
)
else ()
set(COMPILE_OPTIONS_TO_IGNORE_ASYNCPP_WARNINGS
-Wno-error=sign-conversion
)
endif ()
endif ()
# Ranges
CPMAddPackage(
NAME range-v3
URL https://github.com/ericniebler/range-v3/archive/0.11.0.zip
VERSION 0.11.0
# the range-v3 CMakeLists screws with configuration options
DOWNLOAD_ONLY True
)
if (range-v3_ADDED)
add_library(range-v3 INTERFACE IMPORTED)
target_include_directories(range-v3 INTERFACE "${range-v3_SOURCE_DIR}/include")
endif ()
# Threads
find_package(Threads REQUIRED)
#######################################################
### Library ###
#######################################################
# Generate the main file with all headers for convenience only
file(GLOB_RECURSE ALL_HEADERS *.h)
set(ALL_HEADERS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/scistats/scistats.h)
file(WRITE ${ALL_HEADERS_FILE} "// This file is generated automatically
// Do not modify
#ifndef SCISTATS_SCISTATS_ALL_HEADERS_H
#define SCISTATS_SCISTATS_ALL_HEADERS_H\n\n")
foreach (HEADER ${ALL_HEADERS})
file(RELATIVE_PATH RELATIVE_HEADER ${CMAKE_CURRENT_SOURCE_DIR} ${HEADER})
file(APPEND ${ALL_HEADERS_FILE} "#include <${RELATIVE_HEADER}>\n")
endforeach ()
file(APPEND ${ALL_HEADERS_FILE} "\n#endif // SCISTATS_SCISTATS_ALL_HEADERS_H\n")
# Add interface target
add_library(scistats INTERFACE)
target_include_directories(scistats
INTERFACE $<BUILD_INTERFACE:${SCISTATS_ROOT_DIR}/source>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(scistats INTERFACE Threads::Threads Async++ range-v3)
target_compile_options(scistats INTERFACE ${COMPILE_OPTIONS_TO_IGNORE_ASYNCPP_WARNINGS})
# https://cmake.org/cmake/help/v3.14/manual/cmake-compile-features.7.html#requiring-language-standards
target_compile_features(scistats INTERFACE cxx_std_20)
# Hacks to support MSVC
if (MSVC)
# World maps require this option because there is so much in the file
target_compile_options(scistats INTERFACE /bigobj)
target_compile_options(scistats INTERFACE /wd4305)
# Fix compile error caused by utf8 character in line_spec.cpp
target_compile_options(scistats INTERFACE /utf-8)
# Allow exceptions
target_compile_options(scistats INTERFACE /EHsc)
endif ()
# Another hack to check for min in Windows.h
# http://www.suodenjoki.dk/us/archive/2010/min-max.htm
include(CheckSymbolExists)
check_symbol_exists(min "Windows.h" HAVE_WINDOWS_MINMAX)
if (HAVE_WINDOWS_MINMAX)
target_compile_definitions(scistats INTERFACE NOMINMAX)
endif ()
# Use pedantic warnings especially in debug mode
if (BUILD_WITH_PEDANTIC_WARNINGS)
if (MSVC)
target_compile_options(scistats INTERFACE /W4 /WX)
else ()
target_compile_options(scistats INTERFACE -Wall -Wextra -pedantic -Werror)
# Allow the warnings related to the bundled CImg
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_compile_options(scistats INTERFACE -Wno-null-pointer-arithmetic -Wno-char-subscripts)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(scistats INTERFACE -Wno-error=class-memaccess -Wno-class-memaccess)
else ()
message(ERROR "Cannot disable the relevant warnings for ${CMAKE_CXX_COMPILER_ID}")
endif ()
endif ()
endif ()
#######################################################
### Installer ###
#######################################################
if (BUILD_INSTALLER)
# Install targets
install(TARGETS scistats
EXPORT Scistats++Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# Install headers
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)
# Install cmake script
install(EXPORT Scistats++Targets
FILE Scistats++Targets.cmake
NAMESPACE Scistats++::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Scistats++
)
endif ()