mirror of https://gitlab.com/QEF/q-e.git
Export all QE targets
By properly exporting all QE CMake targets, external clients looking for QE via CMake would have a good time in finding all versioning, targets and transitive dependencies available.
This commit is contained in:
parent
241ad122e0
commit
55110e9ba9
206
CMakeLists.txt
206
CMakeLists.txt
|
@ -10,6 +10,81 @@ project(qe
|
|||
# Add our own custom CMake modules
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
||||
|
||||
###########################################################
|
||||
# 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()
|
||||
|
||||
###########################################################
|
||||
# External dependencies
|
||||
###########################################################
|
||||
|
||||
include(external/external.cmake)
|
||||
|
||||
# Must use GNUInstallDirs to install libraries into correct
|
||||
# locations on all platforms.
|
||||
include(GNUInstallDirs)
|
||||
|
||||
###########################################################
|
||||
# Build Options
|
||||
###########################################################
|
||||
|
||||
option(QE_ENABLE_TEST
|
||||
"enable unit tests" ON)
|
||||
option(QE_ENABLE_MPI
|
||||
"enable distributed execution support via MPI" ON)
|
||||
|
||||
###########################################################
|
||||
# Build Features
|
||||
# Each one of the following options boils down to a simple
|
||||
# compile definition, no additional dependencies are needed
|
||||
add_library(qe_definitions INTERFACE)
|
||||
add_library(QE::Definitions ALIAS qe_definitions)
|
||||
###########################################################
|
||||
# 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
|
||||
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)
|
||||
option(QE_ENABLE_MPI_MODULE
|
||||
"use MPI via Fortran module instead of mpif.h header inclusion" OFF)
|
||||
option(QE_ENABLE_BARRIER
|
||||
"enable global synchronization between execution units" OFF)
|
||||
|
||||
if(QE_ENABLE_TRACE)
|
||||
set_property(TARGET qe_definitions APPEND
|
||||
PROPERTY INTERFACE_COMPILE_DEFINITIONS __TRACE)
|
||||
endif()
|
||||
if(QE_ENABLE_MPI_INPLACE)
|
||||
set_property(TARGET qe_definitions APPEND
|
||||
PROPERTY INTERFACE_COMPILE_DEFINITIONS __USE_INPLACE_MPI)
|
||||
endif()
|
||||
if(QE_ENABLE_MPI_MODULE)
|
||||
set_property(TARGET qe_definitions APPEND
|
||||
PROPERTY INTERFACE_COMPILE_DEFINITIONS __MPI_MODULE)
|
||||
endif()
|
||||
if(QE_ENABLE_BARRIER)
|
||||
set_property(TARGET qe_definitions APPEND
|
||||
PROPERTY INTERFACE_COMPILE_DEFINITIONS __USE_BARRIER)
|
||||
endif()
|
||||
|
||||
###########################################################
|
||||
# QE build framework
|
||||
# Please use the following functions in place of the
|
||||
|
@ -18,10 +93,13 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
|||
|
||||
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}
|
||||
|
@ -59,96 +137,13 @@ function(qe_install_target TGT)
|
|||
endif()
|
||||
endfunction(qe_install_target)
|
||||
|
||||
###########################################################
|
||||
# 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()
|
||||
|
||||
###########################################################
|
||||
# External dependencies
|
||||
###########################################################
|
||||
|
||||
include(external/external.cmake)
|
||||
|
||||
# Must use GNUInstallDirs to install libraries into correct
|
||||
# locations on all platforms.
|
||||
include(GNUInstallDirs)
|
||||
|
||||
###########################################################
|
||||
# Build Features
|
||||
# Each one of the following options boils down to a simple
|
||||
# compile definition, no additional dependencies are needed
|
||||
###########################################################
|
||||
# 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
|
||||
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)
|
||||
option(QE_ENABLE_MPI_MODULE
|
||||
"use MPI via Fortran module instead of mpif.h header inclusion" OFF)
|
||||
option(QE_ENABLE_BARRIER
|
||||
"enable global synchronization between execution units" OFF)
|
||||
|
||||
if(QE_ENABLE_TRACE)
|
||||
add_definitions(-D__TRACE)
|
||||
endif()
|
||||
if(QE_ENABLE_MPI_INPLACE)
|
||||
add_definitions(-D__USE_INPLACE_MPI)
|
||||
endif()
|
||||
if(QE_ENABLE_MPI_MODULE)
|
||||
add_definitions(-D__MPI_MODULE)
|
||||
endif()
|
||||
if(QE_ENABLE_BARRIER)
|
||||
add_definitions(-D__USE_BARRIER)
|
||||
endif()
|
||||
|
||||
###########################################################
|
||||
# Build Options
|
||||
###########################################################
|
||||
|
||||
option(QE_ENABLE_TEST
|
||||
"enable unit tests" ON)
|
||||
option(QE_ENABLE_MPI
|
||||
"enable distributed execution support via MPI" ON)
|
||||
|
||||
###########################################################
|
||||
# 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)
|
||||
|
||||
###########################################################
|
||||
# MPI
|
||||
# The following targets will be defined:
|
||||
qe_add_library(qe_mpi_fortran INTERFACE)
|
||||
add_library(qe_mpi_fortran INTERFACE)
|
||||
add_library(QE::MPI_Fortran ALIAS qe_mpi_fortran)
|
||||
qe_add_library(qe_mpi_c INTERFACE)
|
||||
add_library(qe_mpi_c INTERFACE)
|
||||
add_library(QE::MPI_C ALIAS qe_mpi_c)
|
||||
# Install all internal interface targets to allow
|
||||
# proper targets export
|
||||
qe_install_target(qe_mpi_fortran)
|
||||
qe_install_target(qe_mpi_c)
|
||||
###########################################################
|
||||
|
||||
if(QE_ENABLE_MPI)
|
||||
|
@ -161,20 +156,26 @@ if(QE_ENABLE_MPI)
|
|||
find_package(MPI REQUIRED Fortran C)
|
||||
|
||||
target_link_libraries(qe_mpi_fortran
|
||||
INTERFACE
|
||||
MPI::MPI_Fortran)
|
||||
INTERFACE MPI::MPI_Fortran)
|
||||
set_property(TARGET qe_mpi_fortran
|
||||
PROPERTY
|
||||
INTERFACE_COMPILE_DEFINITIONS ${mpi_definitions})
|
||||
PROPERTY INTERFACE_COMPILE_DEFINITIONS ${mpi_definitions})
|
||||
|
||||
target_link_libraries(qe_mpi_c
|
||||
INTERFACE
|
||||
MPI::MPI_C)
|
||||
INTERFACE MPI::MPI_C)
|
||||
set_property(TARGET qe_mpi_c
|
||||
PROPERTY
|
||||
INTERFACE_COMPILE_DEFINITIONS ${mpi_definitions})
|
||||
PROPERTY INTERFACE_COMPILE_DEFINITIONS ${mpi_definitions})
|
||||
endif(QE_ENABLE_MPI)
|
||||
|
||||
###########################################################
|
||||
# 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)
|
||||
|
||||
###########################################################
|
||||
# Components
|
||||
###########################################################
|
||||
|
@ -186,6 +187,12 @@ add_subdirectory(LAXlib)
|
|||
# Exports
|
||||
###########################################################
|
||||
|
||||
# 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)
|
||||
|
||||
install(EXPORT qeTargets
|
||||
FILE qeTargets.cmake
|
||||
NAMESPACE qe::
|
||||
|
@ -205,4 +212,15 @@ install(FILES
|
|||
${CMAKE_CURRENT_BINARY_DIR}/qeConfigVersion.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/qeConfig.cmake
|
||||
DESTINATION
|
||||
${CMAKE_INSTALL_LIBDIR}/cmake/qe)
|
||||
${CMAKE_INSTALL_LIBDIR}/cmake/qe)
|
||||
|
||||
###########################################################
|
||||
# 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" .
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
|
|
@ -0,0 +1 @@
|
|||
set(GRAPHVIZ_IGNORE_TARGETS "qe_definitions;")
|
Loading…
Reference in New Issue