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
|
|
|
###########################################################
|
|
|
|
# External dependencies
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
include(external/external.cmake)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
2019-05-27 04:26:09 +08:00
|
|
|
###########################################################
|
2019-06-07 20:29:05 +08:00
|
|
|
# QE build framework
|
|
|
|
# Please use the following functions in place of the
|
|
|
|
# corresponding CMake builtin
|
2019-05-27 04:26:09 +08:00
|
|
|
###########################################################
|
|
|
|
|
2020-01-09 01:34:41 +08:00
|
|
|
function(qe_add_executable EXE)
|
|
|
|
add_executable(${EXE} ${ARGN})
|
2020-01-09 06:40:15 +08:00
|
|
|
target_link_libraries(${EXE} PUBLIC QE::Definitions)
|
2020-01-09 01:34:41 +08:00
|
|
|
endfunction(qe_add_executable)
|
|
|
|
|
2019-06-07 20:29:05 +08:00
|
|
|
function(qe_add_library LIB)
|
|
|
|
add_library(${LIB} ${ARGN})
|
|
|
|
# Mandatory targets
|
|
|
|
target_link_libraries(${LIB} PUBLIC QE::Definitions)
|
|
|
|
# All of the following target modifications make
|
|
|
|
# sense on non-interfaces only
|
|
|
|
get_target_property(tgt_type ${LIB} TYPE)
|
|
|
|
if(NOT ${tgt_type} STREQUAL "INTERFACE_LIBRARY")
|
|
|
|
get_target_property(tgt_module_dir ${LIB} Fortran_MODULE_DIRECTORY)
|
|
|
|
# set module path to tgt_binary_dir/mod
|
|
|
|
get_target_property(tgt_binary_dir ${LIB} BINARY_DIR)
|
|
|
|
set_target_properties(${LIB}
|
|
|
|
PROPERTIES
|
|
|
|
Fortran_MODULE_DIRECTORY ${tgt_binary_dir}/mod)
|
|
|
|
# make module directory available for clients of LIB
|
|
|
|
target_include_directories(${LIB}
|
|
|
|
PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${tgt_binary_dir}/mod>
|
|
|
|
INTERFACE
|
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/qe>)
|
|
|
|
endif()
|
|
|
|
endfunction(qe_add_library)
|
2019-05-27 04:26:09 +08:00
|
|
|
|
2019-06-07 20:29:05 +08:00
|
|
|
function(qe_install_target TGT)
|
|
|
|
install(TARGETS ${TGT}
|
|
|
|
EXPORT qeTargets
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # Windows needs RUNTIME also for libraries
|
|
|
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qe)
|
|
|
|
# Retrieving non-whitelisted properties leads to an hard
|
|
|
|
# error, let's skip the following section for interface
|
|
|
|
# targets. See here for details:
|
|
|
|
# https://gitlab.kitware.com/cmake/cmake/issues/17640
|
|
|
|
get_target_property(tgt_type ${TGT} TYPE)
|
|
|
|
if(NOT ${tgt_type} STREQUAL "INTERFACE_LIBRARY")
|
|
|
|
# If the target generates Fortran modules, make sure
|
|
|
|
# to install them as well to a proper location
|
|
|
|
get_target_property(tgt_module_dir ${TGT} Fortran_MODULE_DIRECTORY)
|
|
|
|
if(tgt_module_dir)
|
|
|
|
install(DIRECTORY ${tgt_module_dir}/
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qe)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction(qe_install_target)
|
2019-05-27 04:26:09 +08:00
|
|
|
|
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 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 01:34:41 +08:00
|
|
|
add_subdirectory(PW)
|
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 01:34:41 +08:00
|
|
|
# # Install all internal interface targets to allow
|
|
|
|
# # proper targets export
|
|
|
|
# qe_install_target(qe_definitions)
|
|
|
|
# qe_install_target(qe_mpi_fortran)
|
|
|
|
# qe_install_target(qe_mpi_c)
|
|
|
|
# # TODO check that everything is in good shape
|
|
|
|
# qe_install_target(qe_fox)
|
|
|
|
|
|
|
|
# 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}")
|