2019-05-25 04:44:56 +08:00
|
|
|
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
|
2019-05-25 23:58:54 +08:00
|
|
|
# Policy CMP0048: The project() command manages VERSION variables
|
|
|
|
set(CMAKE_POLICY_DEFAULT_CMP0048 NEW)
|
2019-05-25 04:44:56 +08:00
|
|
|
|
|
|
|
project(qe
|
|
|
|
VERSION 6.4.1
|
2019-06-06 20:13:52 +08:00
|
|
|
DESCRIPTION "ESPRESSO: opEn-Source Package for Research in Electronic Structure, Simulation, and Optimization"
|
|
|
|
LANGUAGES Fortran C)
|
2020-01-10 07:18:09 +08:00
|
|
|
|
2019-05-27 05:28:14 +08:00
|
|
|
# Add our own custom CMake modules
|
|
|
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
|
|
|
|
2019-05-25 04:44:56 +08:00
|
|
|
###########################################################
|
|
|
|
# Build Type
|
|
|
|
# Ensure that a specific, default build type is set when
|
|
|
|
# none has been explicitly set by the user
|
|
|
|
###########################################################
|
|
|
|
set(default_build_type "Release")
|
|
|
|
|
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
|
|
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
|
|
|
|
set(CMAKE_BUILD_TYPE "${default_build_type}"
|
|
|
|
CACHE STRING "Choose the type of build." FORCE)
|
|
|
|
# Set the possible values of build type for cmake-gui
|
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE
|
|
|
|
PROPERTY
|
|
|
|
STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
|
|
|
|
endif()
|
|
|
|
|
2019-05-25 05:48:35 +08:00
|
|
|
###########################################################
|
2020-01-09 20:10:56 +08:00
|
|
|
# Modules
|
2019-05-25 05:48:35 +08:00
|
|
|
###########################################################
|
|
|
|
|
2020-01-09 07:49:03 +08:00
|
|
|
include(CheckFunctionExists)
|
2019-05-25 17:09:27 +08:00
|
|
|
# Must use GNUInstallDirs to install libraries into correct
|
|
|
|
# locations on all platforms.
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2019-06-07 20:29:05 +08:00
|
|
|
###########################################################
|
|
|
|
# Build Options
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
option(QE_ENABLE_TEST
|
|
|
|
"enable unit tests" ON)
|
|
|
|
option(QE_ENABLE_MPI
|
|
|
|
"enable distributed execution support via MPI" ON)
|
|
|
|
|
2019-05-27 04:05:30 +08:00
|
|
|
###########################################################
|
|
|
|
# Build Features
|
2019-05-25 04:44:56 +08:00
|
|
|
# Each one of the following options boils down to a simple
|
|
|
|
# compile definition, no additional dependencies are needed
|
2019-06-07 20:29:05 +08:00
|
|
|
add_library(qe_definitions INTERFACE)
|
|
|
|
add_library(QE::Definitions ALIAS qe_definitions)
|
2019-05-27 04:05:30 +08:00
|
|
|
###########################################################
|
|
|
|
# TODO change all ifdefs throughout code base to match
|
|
|
|
# cmake options
|
|
|
|
# TODO symbols beginning with '__' followed by a capital
|
|
|
|
# character are reserved for standard library use (at
|
|
|
|
# least in C, not sure about Fortran), change all feature
|
|
|
|
# macros to avoid weird behaviors
|
2019-05-25 04:44:56 +08:00
|
|
|
option(QE_ENABLE_TRACE
|
|
|
|
"enable execution tracing output" OFF)
|
|
|
|
option(QE_ENABLE_MPI_INPLACE
|
|
|
|
"enable inplace MPI calls (ignored when QE_ENABLE_MPI=OFF)" OFF)
|
2019-05-27 04:26:09 +08:00
|
|
|
option(QE_ENABLE_MPI_MODULE
|
|
|
|
"use MPI via Fortran module instead of mpif.h header inclusion" OFF)
|
2019-05-25 04:44:56 +08:00
|
|
|
option(QE_ENABLE_BARRIER
|
|
|
|
"enable global synchronization between execution units" OFF)
|
|
|
|
|
2020-01-09 07:49:03 +08:00
|
|
|
# Disable all configuration headers used to be generated
|
|
|
|
# by configure (see <qe>/include/)
|
|
|
|
set_property(TARGET qe_definitions APPEND
|
|
|
|
PROPERTY INTERFACE_COMPILE_DEFINITIONS QE_NO_CONFIGURE_HEADERS)
|
|
|
|
|
2019-05-25 04:44:56 +08:00
|
|
|
if(QE_ENABLE_TRACE)
|
2019-06-07 20:29:05 +08:00
|
|
|
set_property(TARGET qe_definitions APPEND
|
|
|
|
PROPERTY INTERFACE_COMPILE_DEFINITIONS __TRACE)
|
2019-05-25 04:44:56 +08:00
|
|
|
endif()
|
|
|
|
if(QE_ENABLE_MPI_INPLACE)
|
2019-06-07 20:29:05 +08:00
|
|
|
set_property(TARGET qe_definitions APPEND
|
|
|
|
PROPERTY INTERFACE_COMPILE_DEFINITIONS __USE_INPLACE_MPI)
|
2019-05-27 04:26:09 +08:00
|
|
|
endif()
|
2019-05-27 04:26:09 +08:00
|
|
|
if(QE_ENABLE_MPI_MODULE)
|
2019-06-07 20:29:05 +08:00
|
|
|
set_property(TARGET qe_definitions APPEND
|
|
|
|
PROPERTY INTERFACE_COMPILE_DEFINITIONS __MPI_MODULE)
|
2019-05-27 04:26:09 +08:00
|
|
|
endif()
|
2019-05-25 04:44:56 +08:00
|
|
|
if(QE_ENABLE_BARRIER)
|
2019-06-07 20:29:05 +08:00
|
|
|
set_property(TARGET qe_definitions APPEND
|
|
|
|
PROPERTY INTERFACE_COMPILE_DEFINITIONS __USE_BARRIER)
|
2020-01-09 07:49:03 +08:00
|
|
|
endif()
|
|
|
|
|
2020-01-09 07:49:03 +08:00
|
|
|
# Feature checks
|
|
|
|
|
|
|
|
check_function_exists(mallinfo HAVE_MALLINFO)
|
|
|
|
if(HAVE_MALLINFO)
|
|
|
|
set_property(TARGET qe_definitions APPEND
|
|
|
|
PROPERTY INTERFACE_COMPILE_DEFINITIONS HAVE_MALLINFO)
|
|
|
|
endif()
|
|
|
|
|
2020-01-09 20:10:56 +08:00
|
|
|
###########################################################
|
|
|
|
# External dependencies
|
|
|
|
###########################################################
|
|
|
|
|
2020-01-09 23:44:49 +08:00
|
|
|
set(QE_MANDATORY_TARGETS QE::Definitions CACHE STRING "" FORCE)
|
|
|
|
include(cmake/qeHelpers.cmake)
|
2020-01-09 20:10:56 +08:00
|
|
|
include(external/external.cmake)
|
|
|
|
|
2019-05-25 04:44:56 +08:00
|
|
|
###########################################################
|
|
|
|
# MPI
|
|
|
|
# The following targets will be defined:
|
2019-06-07 20:29:05 +08:00
|
|
|
add_library(qe_mpi_fortran INTERFACE)
|
2019-05-25 04:44:56 +08:00
|
|
|
add_library(QE::MPI_Fortran ALIAS qe_mpi_fortran)
|
2019-06-07 20:29:05 +08:00
|
|
|
add_library(qe_mpi_c INTERFACE)
|
2019-05-25 04:44:56 +08:00
|
|
|
add_library(QE::MPI_C ALIAS qe_mpi_c)
|
|
|
|
###########################################################
|
2019-05-25 04:44:56 +08:00
|
|
|
|
2019-05-25 04:44:56 +08:00
|
|
|
if(QE_ENABLE_MPI)
|
|
|
|
set(mpi_definitions
|
|
|
|
# legacy macro used throughout qe
|
|
|
|
__MPI
|
|
|
|
# skip CXX APIs on openmpi, cause trouble to C APIs
|
|
|
|
OMPI_SKIP_MPICXX)
|
|
|
|
|
|
|
|
find_package(MPI REQUIRED Fortran C)
|
|
|
|
|
|
|
|
target_link_libraries(qe_mpi_fortran
|
2019-06-07 20:29:05 +08:00
|
|
|
INTERFACE MPI::MPI_Fortran)
|
2019-05-25 04:44:56 +08:00
|
|
|
set_property(TARGET qe_mpi_fortran
|
2019-06-07 20:29:05 +08:00
|
|
|
PROPERTY INTERFACE_COMPILE_DEFINITIONS ${mpi_definitions})
|
2019-05-25 04:44:56 +08:00
|
|
|
|
|
|
|
target_link_libraries(qe_mpi_c
|
2019-06-07 20:29:05 +08:00
|
|
|
INTERFACE MPI::MPI_C)
|
2019-05-25 04:44:56 +08:00
|
|
|
set_property(TARGET qe_mpi_c
|
2019-06-07 20:29:05 +08:00
|
|
|
PROPERTY INTERFACE_COMPILE_DEFINITIONS ${mpi_definitions})
|
2019-05-25 04:44:56 +08:00
|
|
|
endif(QE_ENABLE_MPI)
|
|
|
|
|
2019-06-07 20:29:05 +08:00
|
|
|
###########################################################
|
|
|
|
# Tests
|
|
|
|
# Any executable target marked as test runner via
|
|
|
|
# 'add_test()' will be run by the 'test' make target
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
if(QE_ENABLE_TEST)
|
|
|
|
enable_testing()
|
|
|
|
endif(QE_ENABLE_TEST)
|
|
|
|
|
2019-05-25 04:44:56 +08:00
|
|
|
###########################################################
|
2019-06-07 17:04:07 +08:00
|
|
|
# Components
|
2019-05-25 04:44:56 +08:00
|
|
|
###########################################################
|
2019-05-25 04:44:56 +08:00
|
|
|
|
2020-01-09 07:18:27 +08:00
|
|
|
add_subdirectory(clib)
|
2020-01-09 01:34:41 +08:00
|
|
|
add_subdirectory(FFTXlib)
|
2019-06-07 17:04:07 +08:00
|
|
|
add_subdirectory(UtilXlib)
|
2020-01-09 01:34:41 +08:00
|
|
|
add_subdirectory(Modules)
|
2019-06-07 17:04:07 +08:00
|
|
|
add_subdirectory(LAXlib)
|
2020-01-09 16:49:04 +08:00
|
|
|
add_subdirectory(KS_Solvers)
|
2020-01-09 06:51:01 +08:00
|
|
|
add_subdirectory(dft-d3)
|
2020-01-09 01:34:41 +08:00
|
|
|
add_subdirectory(PW)
|
2020-01-09 16:49:12 +08:00
|
|
|
add_subdirectory(CPV)
|
2019-05-25 17:09:27 +08:00
|
|
|
|
2019-06-07 20:29:05 +08:00
|
|
|
###########################################################
|
2019-06-07 17:04:07 +08:00
|
|
|
# Exports
|
2019-06-07 20:29:05 +08:00
|
|
|
###########################################################
|
2019-05-25 04:44:56 +08:00
|
|
|
|
2020-01-09 20:10:56 +08:00
|
|
|
# Install all internal interface targets to allow
|
|
|
|
# proper targets export
|
2020-01-09 21:46:51 +08:00
|
|
|
qe_install_targets(
|
|
|
|
qe_definitions
|
|
|
|
qe_mpi_fortran
|
|
|
|
qe_mpi_c
|
|
|
|
# TODO check that everything is in good shape
|
|
|
|
qe_fox
|
|
|
|
)
|
2020-01-09 20:10:56 +08:00
|
|
|
|
|
|
|
install(EXPORT qeTargets
|
|
|
|
FILE qeTargets.cmake
|
|
|
|
NAMESPACE qe::
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/qe)
|
|
|
|
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
write_basic_package_version_file(
|
|
|
|
qeConfigVersion.cmake
|
|
|
|
VERSION ${PACKAGE_VERSION}
|
|
|
|
COMPATIBILITY AnyNewerVersion)
|
|
|
|
|
|
|
|
configure_file(
|
|
|
|
cmake/qeConfig.cmake.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/qeConfig.cmake @ONLY)
|
|
|
|
|
|
|
|
install(FILES
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/qeConfigVersion.cmake
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/qeConfig.cmake
|
|
|
|
DESTINATION
|
|
|
|
${CMAKE_INSTALL_LIBDIR}/cmake/qe)
|
2019-06-07 20:29:05 +08:00
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# Dependency graph generation
|
|
|
|
# Defines the custom target 'depgraph'
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeGraphVizOptions.cmake
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/CMakeGraphVizOptions.cmake COPYONLY)
|
|
|
|
add_custom_target(depgraph
|
|
|
|
"${CMAKE_COMMAND}" "--graphviz=depgraph" .
|
2020-01-09 06:40:15 +08:00
|
|
|
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
|