11cmake_minimum_required (VERSION 2.8 FATAL_ERROR)
2- # Always prefer system modules to local ones
3- cmake_policy (SET CMP0017 NEW)
2+ # Set CMake policies here
3+ if (CMAKE_VERSION VERSION_GREATER 2.8.3)
4+ # CMP0017 was introduced in CMake 2.8.4
5+ # Always prefer system modules to local ones
6+ cmake_policy (SET CMP0017 NEW)
7+ endif ()
48#
59# Declare project name and programming languages
610#
7- project (PCMSolver)
8- enable_language (CXX C Fortran)
11+ project (PCMSolver CXX C Fortran)
912#
1013# Options
1114# There still is nothing going on inside the code regarding MPI and OpenMP!!
@@ -45,160 +48,82 @@ include(GenericMacros)
4548include (ConfigGitRevision) # Has to come after ConfigVersion.cmake
4649include (MergeStaticLibs)
4750include (FortranCInterface)
48- include (CheckPython)
4951
5052FortranCInterface_VERIFY(CXX)
5153init_FCMangle()
5254
5355set (EMBEDDED_PYTHON FALSE )
54- # Check Python:
56+ # Try to configure Python, if not possible disable Python embedding
5557if (ENABLE_PYTHON_EMBEDDING)
56- # 1. a Python interpreter of the suitable version exists
57- if ("${PYTHON_INTERPRETER} " STREQUAL "" )
58- find_package (PythonInterp 2.4 REQUIRED)
59- else ()
60- set (PYTHONINTERP_FOUND TRUE )
61- set (PYTHON_EXECUTABLE "${PYTHON_INTERPRETER} " )
62- get_Python_version_string(pyVersion)
63- set (PYTHON_VERSION_STRING "${pyVersion} " )
64- message (STATUS "Passed PythonInterp: ${PYTHON_INTERPRETER} (found suitable version \" ${PYTHON_VERSION_STRING} \" , minimum required is \" 2.4\" )" )
65- endif ()
66- # 2. Python libraries and headers of the same version exist
67- # Set variables to help find Python library that is compatible with interpreter
68- # Copied from https://bitbucket.org/fenics-project/dolfin
69- if (PYTHONINTERP_FOUND)
70- # Get Python include path from Python interpretter
71- execute_process (COMMAND "${PYTHON_EXECUTABLE} " -c
72- "import distutils.sysconfig, sys; sys.stdout.write(distutils.sysconfig.get_python_inc())"
73- OUTPUT_VARIABLE _PYTHON_INCLUDE_PATH
74- RESULT_VARIABLE _PYTHON_INCLUDE_RESULT)
75- # Get Python library path from interpreter
76- execute_process (COMMAND "${PYTHON_EXECUTABLE} " -c
77- "import os, sys, inspect; sys.stdout.write(os.path.split(os.path.split(inspect.getfile(inspect))[0])[0])"
78- OUTPUT_VARIABLE _PYTHON_LIB_PATH
79- RESULT_VARIABLE _PYTHON_LIB_RESULT)
80- # Set include path, if returned by interpreter
81- if ("${_PYTHON_INCLUDE_RESULT} " STREQUAL "0" )
82- set (PYTHON_INCLUDE_DIR ${_PYTHON_INCLUDE_PATH} )
83- endif ()
84- # Add a search path for Python library based on output from
85- # interpreter
86- set (CMAKE_LIBRARY_PATH_SAVE ${CMAKE_LIBRARY_PATH} )
87- if ("${_PYTHON_LIB_RESULT} " STREQUAL "0" )
88- set (CMAKE_LIBRARY_PATH ${_PYTHON_LIB_PATH} )
89- endif ()
90- # Find Pythons libs
91- find_package (PythonLibs ${PYTHON_VERSION_STRING} EXACT REQUIRED)
92- # Check headers
93- include (CheckIncludeFiles)
94- set (CMAKE_REQUIRED_INCLUDES "${PYTHON_INCLUDE_DIRS} " )
95- check_include_files(Python.h HAS_PYTHON_H)
96- check_include_files(pyconfig.h HAS_PYCONFIG_H)
97- if (NOT HAS_PYTHON_H)
98- message (STATUS "No Python.h header found!!" )
99- endif ()
100- if (NOT HAS_PYCONFIG_H)
101- message (STATUS "No pyconfig.h header found!!" )
58+ # libutil and libdl are needed in case only the static version of libpython is available
59+ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
60+ find_package (Util REQUIRED)
61+ if (NOT LIBUTIL_FOUND)
62+ message (STATUS "Python embedding DISABLED (libutil NOT FOUND)" )
10263 endif ()
103- unset (CMAKE_REQUIRED_INCLUDES)
104- # 3. that we can link against those libraries
105- check_Python_compiles(pyCompiles)
106- if (NOT pyCompiles)
107- message (STATUS "Cannot link against Python!!" )
108- endif ()
10964 endif ()
110- # Iff the answer is "YES" to all of the above, we set
111- # EMBEDDED_PYTHON to TRUE enabling the embedded Python code
112- if (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND
113- AND HAS_PYTHON_H AND HAS_PYCONFIG_H AND pyCompiles)
65+
66+ find_package (DL REQUIRED)
67+ if (NOT LIBDL_FOUND)
68+ message (STATUS "Python embedding DISABLED (libdl NOT FOUND)" )
69+ endif ()
70+ include (ConfigPython)
71+ # We set EMBEDDED_PYTHON to TRUE enabling the embedded Python code
72+ # only if the interpreter and the headers/libraries were found
73+ if (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND)
11474 set (EMBEDDED_PYTHON TRUE )
11575 add_definitions (-DEMBEDDED_PYTHON)
76+ include_directories (SYSTEM ${PYTHON_INCLUDE_DIRS} )
11677 message (STATUS "Python embedding ENABLED" )
11778 else ()
11879 message (STATUS "Python embedding DISABLED" )
11980 message (STATUS " Dependencies not satisfied" )
12081 endif ()
121- else ()
82+ else (ENABLE_PYTHON_EMBEDDING )
12283 # The Python interpreter is anyway needed to run the MergeStaticLibs.py script
12384 find_package (PythonInterp 2.4 REQUIRED)
12485 message (STATUS "Python embedding DISABLED" )
125- endif ()
86+ endif (ENABLE_PYTHON_EMBEDDING)
87+
12688find_package (ZLIB REQUIRED)
89+ include_directories (SYSTEM ${ZLIB_INCLUDE_DIRS} )
12790
12891if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
129- set (CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR} /external)
130- set (EXTERNAL_PROJECT_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} )
131- set (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT ${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT} CACHE INTERNAL "" )
92+ set (CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR} /external)
93+ set (EXTERNAL_PROJECT_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} )
94+ set (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT ${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT} CACHE INTERNAL "" )
13295else ()
133- set (EXTERNAL_PROJECT_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} )
134- set (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT ${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT} CACHE INTERNAL "" )
96+ set (EXTERNAL_PROJECT_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} )
97+ set (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT ${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT} CACHE INTERNAL "" )
13598endif ()
13699
137- # Just change the Boost version number here
138- set (BOOSTVER 1.54.0)
139- set (BUILD_CUSTOM_BOOST FALSE )
140- # List all components needed (except mpi and unit_test_framework) here.
141- # Components additionally required in PSI4: python, serialization, thread (Might be useful in the future?)
142- # mpi and unit_test_framework will be added afterwards, if needed.
143- list (APPEND needed_components filesystem system )
144- set (Boost_USE_STATIC_LIBS ON )
145- set (Boost_USE_MULTITHREADED ON )
146- set (Boost_USE_STATIC_RUNTIME OFF )
147- if (ENABLE_TESTS)
148- list (APPEND needed_components unit_test_framework)
149- find_package (Boost ${BOOSTVER} COMPONENTS "${needed_components} " )
150- else ()
151- find_package (Boost ${BOOSTVER} COMPONENTS "${needed_components} " )
152- endif ()
153- if (NOT Boost_FOUND)
154- # Set also variables usually set by find_package
155- message (STATUS " Build custom Boost ${BOOSTVER} " )
156- set (BUILD_CUSTOM_BOOST TRUE )
157- set (CUSTOM_BOOST_LOCATION ${EXTERNAL_PROJECT_INSTALL_PREFIX} /boost)
158- string (REGEX REPLACE "\\ ." "0" Boost_VERSION ${BOOSTVER} )
159- math (EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000" )
160- math (EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000" )
161- math (EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100" )
162- set (Boost_LIB_VERSION ${Boost_MAJOR_VERSION} _${Boost_MINOR_VERSION} )
163- add_subdirectory (external)
164- set (Boost_FOUND TRUE )
165- set (Boost_LIBRARIES "" )
166- # Read documentation in FindBoost.cmake for the difference between the singular and plural forms
167- set (Boost_INCLUDE_DIR ${CUSTOM_BOOST_LOCATION} /include )
168- set (Boost_INCLUDE_DIRS ${CUSTOM_BOOST_LOCATION} /include )
169- set (Boost_LIBRARY_DIR ${CUSTOM_BOOST_LOCATION} /lib)
170- set (Boost_LIBRARY_DIRS ${CUSTOM_BOOST_LOCATION} /lib)
171- # We will link statically, so just set the Boost_<C>_LIBRARY for the static library
172- foreach (_component ${needed_components} )
173- string (TOUPPER ${_component} _COMP)
174- set (Boost_${_COMP} _FOUND TRUE )
175- set (Boost_${_COMP} _LIBRARY libboost_${_component} -${Boost_LIB_VERSION} .a)
176- list (APPEND Boost_LIBRARIES Boost_${_COMP} _LIBRARY)
177- endforeach ()
178- endif ()
100+ # Boost detection
101+ include (ConfigBoost)
102+ link_directories (${Boost_LIBRARY_DIRS} )
103+ include_directories (SYSTEM ${Boost_INCLUDE_DIRS} )
179104
180- #
181105# Eigen 3 stuff
182- #
183106if ("${EIGEN3_ROOT} " STREQUAL "" )
184- if (DISABLE_EIGEN_OWN)
185- find_package (Eigen3 3.0.0)
186- message (STATUS "Eigen " ${EIGEN3_VERSION} " is located here: " ${EIGEN3_INCLUDE_DIR} )
187- else ()
188- set (EIGEN3_ROOT ${PROJECT_SOURCE_DIR} /external/eigen3)
189- set (EIGEN3_INCLUDE_DIR ${EIGEN3_ROOT} /include /eigen3)
190- install (DIRECTORY ${PROJECT_SOURCE_DIR} /external/eigen3 DESTINATION ${EXTERNAL_PROJECT_INSTALL_PREFIX} /include )
191- message (STATUS "Eigen 3.2.0 is located here: " ${EXTERNAL_PROJECT_INSTALL_PREFIX} /include /eigen3)
192- endif ()
107+ if (DISABLE_EIGEN_OWN)
108+ find_package (Eigen3 3.0.0)
109+ message (STATUS "Eigen " ${EIGEN3_VERSION} " is located here: " ${EIGEN3_INCLUDE_DIR} )
110+ else ()
111+ set (EIGEN3_ROOT ${PROJECT_SOURCE_DIR} /external/eigen3)
112+ set (EIGEN3_INCLUDE_DIR ${EIGEN3_ROOT} /include /eigen3)
113+ install (DIRECTORY ${PROJECT_SOURCE_DIR} /external/eigen3 DESTINATION ${EXTERNAL_PROJECT_INSTALL_PREFIX} /include )
114+ message (STATUS "Eigen 3.2.0 is located here: " ${EXTERNAL_PROJECT_INSTALL_PREFIX} /include /eigen3)
115+ endif ()
193116else ()
194- find_package (Eigen3 3.0.0)
195- message (STATUS "Eigen " ${EIGEN3_VERSION} " is located here: " ${EIGEN3_INCLUDE_DIR} )
117+ find_package (Eigen3 3.0.0)
118+ message (STATUS "Eigen " ${EIGEN3_VERSION} " is located here: " ${EIGEN3_INCLUDE_DIR} )
196119endif ()
120+ include_directories (SYSTEM ${EIGEN3_INCLUDE_DIR} )
121+
197122if (ENABLE_EIGEN_MKL)
198- message (STATUS "ENABLE_EIGEN_MKL option requires at least Eigen 3.1.0 and Intel MKL 10.3" )
199- message (STATUS " Be sure you have read http://eigen.tuxfamily.org/dox/TopicUsingIntelMKL.html" )
200- include (ConfigMath)
201- set (EIGEN_USE_MKL_ALL ON )
123+ message (STATUS "ENABLE_EIGEN_MKL option requires at least Eigen 3.1.0 and Intel MKL 10.3" )
124+ message (STATUS " Be sure you have read http://eigen.tuxfamily.org/dox/TopicUsingIntelMKL.html" )
125+ include (ConfigMath)
126+ set (EIGEN_USE_MKL_ALL ON )
202127endif ()
203128
204129set (CMAKE_Fortran_MODULE_DIRECTORY
@@ -239,12 +164,8 @@ ExternalProject_Add(libtaylor
239164
240165configure_files()
241166
242- # To be includes as system headers
167+ # To be included as system headers
243168include_directories (SYSTEM
244- ${EIGEN3_INCLUDE_DIR}
245- ${Boost_INCLUDE_DIRS}
246- ${PYTHON_INCLUDE_DIRS}
247- ${ZLIB_INCLUDE_DIRS}
248169 ${PROJECT_SOURCE_DIR} /external
249170 ${EXTERNAL_PROJECT_INSTALL_PREFIX} /include )
250171# To be included as project headers
@@ -255,9 +176,7 @@ include_directories(${PROJECT_SOURCE_DIR}
255176add_subdirectory (src)
256177include_directories (${header_dir_list} )
257178
258- link_directories (${Boost_LIBRARY_DIRS}
259- ${PYTHON_LIBRARIES}
260- ${EXTERNAL_PROJECT_INSTALL_PREFIX} /external/lib
179+ link_directories (${EXTERNAL_PROJECT_INSTALL_PREFIX} /external/lib
261180 ${EXTERNAL_PROJECT_INSTALL_PREFIX} /lib)
262181
263182install (FILES
@@ -277,19 +196,15 @@ install(FILES
277196 DESTINATION include )
278197
279198if (ENABLE_TESTS)
280- include (ConfigFramework)
281- include (TestingMacros)
282-
283- setup_boosttest()
284-
285- enable_testing ()
286- add_subdirectory (tests) # This must come last!!
199+ include (ConfigFramework)
200+ include (TestingMacros)
201+
202+ setup_boosttest()
203+
204+ enable_testing ()
205+ add_subdirectory (tests) # This must come last!!
287206endif ()
288207
289- # How to add a debug executable. Shouldn't be necessary, we have unit tests...
290- #add_executable(debug_wavcav.x ${PROJECT_SOURCE_DIR}/src/debug_wavcav.cpp)
291- #target_link_libraries(debug_wavcav.x solver green cavity wavcav pwl wem utils ${LIBS})
292-
293208# Merge static libs from subfolders into one static lib: libpcm.a
294209# This is the very last thing we do, i.e. DO NOT add anything depending on this target!!!
295210merge_static_libs(pcm "${libs_to_merge} " )
0 commit comments