forked from TRIQS/triqs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
291 lines (243 loc) · 11.4 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
###################################################################################
#
# TRIQS: a Toolbox for Research in Interacting Quantum Systems
#
# Copyright (C) 2011-2017 by O. Parcollet, M. Ferrero, A. Antipov
# Copyright (C) 2019-2020 Simons Foundation
# authors: N. Wentzell
#
# TRIQS 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.
#
# TRIQS 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
# TRIQS. If not, see <http://www.gnu.org/licenses/>.
#
###################################################################################
#---------------------------------------------------------------------
# Preliminary : path, policy
#---------------------------------------------------------------------
# Check CMAKE_INSTALL_PREFIX : must be provided and absolute
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR (NOT IS_ABSOLUTE ${CMAKE_INSTALL_PREFIX}))
message(FATAL_ERROR "CMAKE_INSTALL_PREFIX must be specified and must be an absolute path.\n There is no default.\n Current value : ${CMAKE_INSTALL_PREFIX}\n. e.g. ... -DCMAKE_INSTALL_PREFIX=$HOME/triqs_install")
endif()
message(STATUS "Installation directory will be ${CMAKE_INSTALL_PREFIX}")
#---------------------------------------------------------------------
# Start project
#---------------------------------------------------------------------
cmake_minimum_required(VERSION 3.3.2 FATAL_ERROR)
cmake_policy(VERSION 3.3.2)
project(TRIQS VERSION 3.0.2 LANGUAGES C CXX)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
## C & C++ Headers
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
#---------------------------------------------------------------------
# Compiler check
#---------------------------------------------------------------------
message( STATUS "-------- Checking compiler C++ status-------------")
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if(${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 5.0.0)
message(FATAL_ERROR "The Clang compiler version is ${CMAKE_CXX_COMPILER_VERSION}, but TRIQS requires 5.0.0 or later")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
if(${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 7.0.0)
message(FATAL_ERROR "The GCC compiler version is ${CMAKE_CXX_COMPILER_VERSION}, but TRIQS requires 7.0 or later")
endif()
else()
message(FATAL_ERROR "TRIQS Has to be compiled with g++ (7.x) or clang (>= 5.0.0)")
endif()
try_compile(_CXX_OK ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/cxx_check.cpp COMPILE_DEFINITIONS -std=c++17)
if (NOT _CXX_OK)
message(FATAL_ERROR "The compiler does not support C++17")
endif()
#---------------------------------------------------------------------
# CMake Options
#---------------------------------------------------------------------
# Default to Release build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Type of build" FORCE)
endif()
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
# Python Support
option(PythonSupport "Build with Python support" ON)
# Documentation
option(Build_Documentation "Build the documentation ?" OFF)
if(Build_Documentation AND NOT PythonSupport)
message(FATAL_ERROR "Build_Documentation=ON requires PythonSupport to be enabled")
endif()
# Testing
option(Build_Tests "Build tests" ON)
if(Build_Tests)
enable_testing()
endif()
# Build shared libraries by default
option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" ON)
#---------------------------------------------------------------------
# log info
#---------------------------------------------------------------------
message( STATUS "-------- triqs version and git hash detection -------------")
# Find the TRIQS_GIT_HASH
find_package(Git)
# Get the Git Hash
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE TRIQS_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Compute TRIQS_HOSTNAME and TRIQS_COMPILEDBY
execute_process(COMMAND hostname
OUTPUT_VARIABLE TRIQS_HOSTNAME
RESULT_VARIABLE returncode
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(COMMAND id -un
OUTPUT_VARIABLE TRIQS_COMPILEDBY
RESULT_VARIABLE returncode
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "Triqs version : ${TRIQS_VERSION}")
message(STATUS "Git hash : ${TRIQS_GIT_HASH}")
message(STATUS "Hostname : ${TRIQS_HOSTNAME}")
message(STATUS "Compiled by : ${TRIQS_COMPILEDBY}")
# Compile a small file with the hash
configure_file(./cmake/git_hash.cpp.in c++/triqs/git_hash.cpp @ONLY)
# ---------------------------------
# RPATH setting
# ---------------------------------
# Make sure the rpath is set fine after installation for libtriqs, module, and executables
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_MACOSX_RPATH 1) # new for cmake 3.x
else()
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
endif()
# ---------------------------------
# Resolve Clang Linktime Problems
# CMake will adjust any linker flags from '-L path_to/mylib.so' to -lmylib
# if the proper mylib.so is automatically found by the linker, i.e.
# the directory comes first in LIBRARY_PATH.
# The clang linker however ignores LIBRARY_PATH.
# We thus explicitly add the content of LIBRARY_PATH to the LDFLAGS
# FIXME For future cmake versions we should populate the
# INTERFACE_LINK_DIRECTORIES of the triqs target
# ---------------------------------
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND DEFINED ENV{LIBRARY_PATH})
string(REPLACE ":" ";" LINK_DIRS $ENV{LIBRARY_PATH})
foreach(dir ${LINK_DIRS})
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -L${dir}")
string(APPEND CMAKE_MODULE_LINKER_FLAGS " -L${dir}")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -L${dir}")
endforeach()
endif()
#---------------------------------------------------------------------
# External Dependencies (nda, h5, itertools, gtest, ...)
#---------------------------------------------------------------------
add_subdirectory(deps)
#------------------------
# triqs library
#------------------------
add_subdirectory(c++/triqs)
#---------------------------------------------------------------------
# Python modules
#---------------------------------------------------------------------
if(PythonSupport)
set(TRIQS_WITH_PYTHON_SUPPORT 1) # To export the TRIQSConfig file
message( STATUS "-------- Preparing python extension modules -------------")
add_subdirectory(python/triqs)
endif()
#------------------------
# build tests
#------------------------
if(Build_Tests)
message(STATUS "-------- Preparing tests -------------")
add_subdirectory(test)
endif()
#------------------------
# Documentation
#------------------------
if(Build_Documentation)
message( STATUS "-------- Prepare documentation -------------")
add_subdirectory (doc)
endif()
#-----------------------------------------------
# Install the FindXXX that should be exported
#-----------------------------------------------
install (FILES cmake/FindNFFT.cmake DESTINATION share/cmake/Modules)
install (FILES cmake/Findsanitizer.cmake DESTINATION share/cmake/Modules)
#---------------------------------------
# Fortran bindings
#---------------------------------------
option(BIND_FORTRAN_LOWERCASE "FORTRAN functions are compiled WITHOUT a trailing underscore" OFF)
mark_as_advanced(BIND_FORTRAN_LOWERCASE)
if (BIND_FORTRAN_LOWERCASE)
set(TRIQS_BIND_FORTRAN_LOWERCASE OFF )
endif (BIND_FORTRAN_LOWERCASE)
#---------------------------------------
# TRIQSConfig
#---------------------------------------
message( STATUS "-------- Making TRIQSConfig.cmake -------------")
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
configure_file(./cmake/TRIQSConfig.cmake.in Config/TRIQSConfig.cmake @ONLY)
else()
configure_file(./cmake/TRIQSConfig.cmake.in Config/TRIQSConfig1.cmake @ONLY)
# I assume there is a basic python available
EXECUTE_PROCESS(COMMAND python -c "import re;open('${PROJECT_BINARY_DIR}/Config/TRIQSConfig.cmake','w').write(re.sub(r';*\\s*-framework\\s+([a-zA-Z_][a-zA-Z_0-9]*)',r' \"-framework \\1\"',open('${PROJECT_BINARY_DIR}/Config/TRIQSConfig1.cmake').read()))" , ConfigFile)
endif()
configure_file(./cmake/TRIQSConfig-version.cmake.in Config/TRIQSConfig-version.cmake @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/Config/TRIQSConfig.cmake DESTINATION lib/cmake/triqs)
install(FILES ${PROJECT_BINARY_DIR}/Config/TRIQSConfig-version.cmake DESTINATION lib/cmake/triqs)
#------------------------
# Test macros
#------------------------
configure_file(./cmake/FindTriqsTest.cmake.in Config//FindTriqsTest.cmake @ONLY)
configure_file(./cmake/run_test.cmake.in Config/run_test.cmake @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/Config/FindTriqsTest.cmake DESTINATION share/cmake/Modules)
install(FILES ${PROJECT_BINARY_DIR}/Config/run_test.cmake DESTINATION share/cmake/Modules)
#--------------------------------------------------------
# Remind the user how to set up his/her variables
#--------------------------------------------------------
if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr")
# Configure and install the file to source to setup the environment variables
configure_file(${PROJECT_SOURCE_DIR}/triqsvars.sh.in ${PROJECT_BINARY_DIR}/triqsvars.sh @ONLY)
configure_file(${PROJECT_SOURCE_DIR}/triqs.modulefile.in ${PROJECT_BINARY_DIR}/triqs.modulefile @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/triqsvars.sh DESTINATION ${CMAKE_INSTALL_PREFIX}/share)
message(STATUS "***************************************************************")
message(STATUS "* Use : ")
message(STATUS "* source ${CMAKE_INSTALL_PREFIX}/share/triqsvars.sh ")
message(STATUS "* to set up the environment variables ")
if(DEFINED ENV{MODULEPATH})
message(STATUS "* ")
message(STATUS "* Consider copying ${PROJECT_BINARY_DIR}/triqs.modulefile")
message(STATUS "* into your environment module directories ")
endif()
message(STATUS "***************************************************************")
endif()
#--------------------------------------------------------
# Packaging
#--------------------------------------------------------
option(BUILD_DEBIAN_PACKAGE "Build a deb package" OFF)
if(BUILD_DEBIAN_PACKAGE)
if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr")
message(FATAL_ERROR "CMAKE_INSTALL_PREFIX must be /usr for packaging")
endif()
set(CPACK_PACKAGE_NAME triqs)
SET(CPACK_GENERATOR "DEB")
SET(CPACK_PACKAGE_VERSION ${TRIQS_VERSION})
SET(CPACK_PACKAGE_CONTACT "https://github.com/TRIQS/triqs")
EXECUTE_PROCESS(COMMAND dpkg --print-architecture OUTPUT_VARIABLE CMAKE_DEBIAN_PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE)
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "python3, python3-numpy, python3-mako, python3-mpi4py, python3-matplotlib, python3-scipy, libopenmpi-dev")
SET(CPACK_DEBIAN_PACKAGE_CONFLICTS "cpp2py")
SET(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
SET(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
INCLUDE(CPack)
endif()