This repository has been archived by the owner on Jan 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
202 lines (182 loc) · 8.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
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
#OpenSUSE 15.1 has CMake 3.10
#OpenSUSE 15.2 has CMake 3.17
#Current (july 2021) latest release: CMake 3.21
cmake_minimum_required(VERSION 3.16)
project(BOLSIG+ LANGUAGES C CXX Fortran)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
#Add protection against in-source builds
include(PreventInSourceBuilds)
set(CMAKE_CXX_STANDARD 17)
#Verify that the Fortran and C++ compiler can interact with each other
#This is needed for compiling odepack, mumps4, etc.
include(FortranCInterface)
message("Checking C-Fortran compatibility")
FortranCInterface_VERIFY()
message("Checking CXX-Fortran compatibility")
FortranCInterface_VERIFY(CXX)
#Special handling for Windows. Perhaps not all in this section is
#needed.
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
#I think this is needed, generates next to a .dll also a .lib
#and a .exp file.
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
#Put all dlls and executables in a single folder. This
#enables all regtests and executables to find the dlls.
#Probably there is a nicer way (a copy step at the end of
#the compile that copies all dlls next to the executables?)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()
# Adopt cmake policy 0092:
# do not ad /W3 by default for MSVC (and Intel on Windows?)
# since that gets overridden by /W4, which causes a warning
# for every file being compiled.
cmake_policy(SET CMP0092 NEW)
option(ALL_WARNINGS "-DALL_WARNINGS=0|1 : Show all warnings" off)
if (MSVC)
# warning level 4
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/W4>)
if(NOT ALL_WARNINGS)
#disable some valid, but perhaps not so interesting warnings
#disable warning C4100: "unreferenced formal parameter"
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/wd4100>)
#disable warning C4244: "conversion from 'X' to 'Y', possible loss of data"
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/wd4244>)
#disable warning C4267: "'return': conversion from 'size_t' to 'unsigned int', possible loss of data"
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/wd4267>)
#disable warning C4996: 'XXX': This function or variable may be unsafe.
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/wd4996>)
#disable warning C4389: '==': signed/unsigned mismatch
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/wd4389>)
#disable warning C4127: conditional expression is constant
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/wd4127>)
#disable warning C4459: declaration of 'attr' hides global declaration
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/wd4459>)
#disable warning C4702: unreachable code
#note: this is triggered by the implementation of plGET_SAME_UNITS
#in plmathparser/unit.h. Let's see if that can be written in a way
#that allows us to enable this warning again.
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/wd4702>)
#Some libraries get complaints: fatal error C1128: number of sections
#exceeded object file format limit: compile with /bigobj
#We have seen this before also on mxe builds. /bigobj removes this warning
#TODO: find out which libraries are exactly the problematic ones, and apply
#this flag on a target level.
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/bigobj>)
endif()
else()
# lots of warnings
add_compile_options(-Wall -Wextra)
if(NOT ALL_WARNINGS)
#disable some valid, but perhaps not so interesting warnings
add_compile_options(-Wno-unused-parameter)
endif()
add_link_options(LINKER:-no-undefined)
endif()
if(MSVC)
#In C++17 binary_function and unary_function are removed
#These functions are used on multiple places throughout the
#code, and even in Boost. This preprocessor directive makes
#the MSVC compiler happy, for now. see:
#https://stackoverflow.com/questions/41972522/c2143-c2518-when-trying-to-compile-project-using-boost-multiprecision
#https://devblogs.microsoft.com/cppblog/stl-fixes-in-vs-2015-update-3/
add_compile_definitions(_HAS_AUTO_PTR_ETC=1)
endif()
###############################################
######### Math library ################
###############################################
#If libm is available, link against it. Otherwise,
#(on Windows this is the case), MATH_LIB is empty
include(CheckLibraryExists)
check_library_exists(m sin "" HAVE_LIB_M)
if (HAVE_LIB_M)
set(MATH_LIB m)
endif (HAVE_LIB_M)
#########################################
############### Threads #################
##########################################
find_package(Threads)
###### Colored output: when Ninja is used GCC doesn't output colored output by default #########
option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." TRUE)
if (${FORCE_COLORED_OUTPUT})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options (-fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options (-fcolor-diagnostics)
endif ()
endif ()
#########################################
################# BLAS ##################
#########################################
message("Looking for BLAS....")
find_package(BLAS REQUIRED)
if(BLAS_FOUND)
message("Found BLAS")
#From CMake 3.18 onwards we can link to the BLAS::BLAS target.
#for lower versions, we make it ourselves, based on
#https://github.com/Kitware/CMake/blob/master/Modules/FindBLAS.cmake
if(NOT TARGET BLAS::BLAS)
message(" -- creating target BLAS::BLAS")
add_library(BLAS::BLAS INTERFACE IMPORTED)
if(BLAS_LIBRARIES)
set_target_properties(BLAS::BLAS PROPERTIES INTERFACE_LINK_LIBRARIES "${BLAS_LIBRARIES}")
endif()
if(BLAS_LINKER_FLAGS)
set_target_properties(BLAS::BLAS PROPERTIES INTERFACE_LINK_OPTIONS "${BLAS_LINKER_FLAGS}")
endif()
endif()
set(BLAS_LIBS BLAS::BLAS)
message(" -- BLAS libraries: ${BLAS_LIBRARIES}")
message(" -- BLAS linker flags: ${BLAS_LINKER_FLAGS}")
endif()
#########################################
################ LAPACK #################
#########################################
message("Looking for LAPACK....")
find_package(LAPACK REQUIRED)
if(LAPACK_FOUND)
#A target LAPACK::LAPACK is available for CMake 3.18 onwards
#for lower versions, we make it ourselves, based on
#https://github.com/Kitware/CMake/blob/master/Modules/FindLAPACK.cmake
if(NOT TARGET LAPACK::LAPACK)
message(" -- creating target LAPACK::LAPACK")
set(_lapack_libs "${LAPACK_LIBRARIES}")
set(_lapack_flags "${LAPACK_LINKER_FLAGS}")
#Filter out redundant BLAS libraries and linker flags as in the
#FindLAPACK.cmake file (maybe a bit overkill, but okay)
if(_lapack_libs AND BLAS_LIBRARIES)
foreach(_blas_lib IN LISTS BLAS_LIBRARIES)
list(REMOVE_ITEM _lapack_libs "${_blas_lib}")
endforeach()
endif()
if(_lapack_flags AND BLAS_LINKER_FLAGS)
foreach(_blas_flag IN LISTS BLAS_LINKER_FLAGS)
list(REMOVE_ITEM _lapack_flags "${_blas_flag}")
endforeach()
endif()
#Do the actual creation of the library
#The FindLAPACK.cmake file also filters out dub
add_library(LAPACK::LAPACK INTERFACE IMPORTED)
if(LAPACK_LIBRARIES)
set_target_properties(LAPACK::LAPACK PROPERTIES INTERFACE_LINK_LIBRARIES "${LAPACK_LIBRARIES}")
endif()
if(LAPACK_LINKER_FLAGS)
set_target_properties(LAPACK::LAPACK PROPERTIES INTERFACE_LINK_OPTIONS "${LAPACK_LINKER_FLAGS}")
endif()
#Link to BLAS
if(TARGET BLAS::BLAS)
target_link_libraries(BLAS::BLAS INTERFACE BLAS::BLAS)
else()
target_link_libraries(BLAS::BLAS INTERFACE ${BLAS_LINKER_FLAGS} ${BLAS_LIBRARIES})
endif()
endif()
set(LAPACK_LIBS LAPACK::LAPACK)
message(" -- Found the following LAPACK libs: ${_lapack_libs}")
message(" -- LAPACK linker flags: ${_lapack_flags}")
endif()
enable_testing()
add_subdirectory(lib)
add_subdirectory(app)
#add_subdirectory(input)
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/lib)