From 5402cb3ec52a4bc158d90381d25617630f282809 Mon Sep 17 00:00:00 2001 From: Willem Deconinck Date: Mon, 5 Feb 2024 16:05:03 +0100 Subject: [PATCH] Add options to disable compilation of parkind_(sp,dp) --- CMakeLists.txt | 8 +++++++ cmake/fiat-import.cmake.in | 14 ++++++++++++ src/parkind/CMakeLists.txt | 37 ++++++++++++++++++------------- tests/test-install.sh.in | 8 +++++-- tests/test_install/CMakeLists.txt | 4 ++++ 5 files changed, 53 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index abd033f..06e4dae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,14 @@ ecbuild_add_option( FEATURE DR_HOOK_MULTI_PRECISION_HANDLES DESCRIPTION "[DEPRECATED] Support single precision handles for DR_HOOK" DEFAULT OFF ) +ecbuild_add_option( FEATURE DOUBLE_PRECISION + DEFAULT ON + DESCRIPTION "Compilation of parkind_dp" ) + +ecbuild_add_option( FEATURE SINGLE_PRECISION + DEFAULT ON + DESCRIPTION "Compilation of parkind_sp" ) + ecbuild_add_option( FEATURE WARNINGS DEFAULT ON DESCRIPTION "Add warnings to compiler" ) diff --git a/cmake/fiat-import.cmake.in b/cmake/fiat-import.cmake.in index c500b20..87acf0c 100644 --- a/cmake/fiat-import.cmake.in +++ b/cmake/fiat-import.cmake.in @@ -15,6 +15,8 @@ set( fiat_VERSION_STR @fiat_VERSION_STR@ ) set( fiat_HAVE_MPI @fiat_HAVE_MPI@ ) set( fiat_HAVE_OMP @fiat_HAVE_OMP@ ) set( fiat_HAVE_FCKIT @fckit_HAVE_FCKIT@ ) +set( fiat_HAVE_SINGLE_PRECISION @fiat_HAVE_SINGLE_PRECISION@ ) +set( fiat_HAVE_DOUBLE_PRECISION @fiat_HAVE_DOUBLE_PRECISION@ ) set( fiat_SOURCE_FILENAMES @fiat_SOURCE_FILENAMES@ ) if( fiat_HAVE_OMP AND NOT TARGET OpenMP::OpenMP_Fortran ) @@ -36,3 +38,15 @@ else() set(_no_whole_archive "-Wl,--no-whole-archive") endif() set(MPI_SERIAL_LIBRARIES ${_whole_archive} mpi_serial ${_no_whole_archive}) + +################################################################## +## Handle components + +set( ${CMAKE_FIND_PACKAGE_NAME}_single_FOUND ${fiat_HAVE_SINGLE_PRECISION} ) +set( ${CMAKE_FIND_PACKAGE_NAME}_double_FOUND ${fiat_HAVE_DOUBLE_PRECISION} ) + +foreach( _component ${${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS} ) + if( NOT ${CMAKE_FIND_PACKAGE_NAME}_${_component}_FOUND AND ${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED ) + message( SEND_ERROR "fiat was not build with support for COMPONENT ${_component}" ) + endif() +endforeach() diff --git a/src/parkind/CMakeLists.txt b/src/parkind/CMakeLists.txt index 9c2d5ab..882de4e 100644 --- a/src/parkind/CMakeLists.txt +++ b/src/parkind/CMakeLists.txt @@ -6,25 +6,30 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. -foreach( target parkind_sp parkind_dp ) +set( HAVE_dp ${HAVE_DOUBLE_PRECISION} ) +set( HAVE_sp ${HAVE_SINGLE_PRECISION} ) - ecbuild_add_library( - TARGET ${target} - SOURCES parkind1.F90 - parkind2.F90 - ) +foreach( prec sp dp ) + if( HAVE_${prec} ) + set( target parkind_${prec} ) + ecbuild_add_library( + TARGET ${target} + SOURCES parkind1.F90 + parkind2.F90 + ) - fiat_target_fortran_module_directory( - TARGET ${target} - MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/module/${target} - INSTALL_DIRECTORY module/${target} - ) + if( EC_OS_BITS EQUAL "64" ) + target_compile_definitions( ${target} PRIVATE ADDRESS64 ) + endif() - if( EC_OS_BITS EQUAL "64" ) - target_compile_definitions( parkind_sp PRIVATE ADDRESS64 ) + fiat_target_fortran_module_directory( + TARGET ${target} + MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/module/${target} + INSTALL_DIRECTORY module/${target} + ) endif() - endforeach() -target_compile_definitions( parkind_sp PRIVATE PARKIND1_SINGLE ) - +if( TARGET parkind_sp ) + target_compile_definitions( parkind_sp PRIVATE PARKIND1_SINGLE ) +endif() diff --git a/tests/test-install.sh.in b/tests/test-install.sh.in index 3b85fe8..0a291e8 100755 --- a/tests/test-install.sh.in +++ b/tests/test-install.sh.in @@ -49,8 +49,12 @@ cmake $SOURCE \ make VERBOSE=1 -bin/main_dp -bin/main_sp +if [ -f bin/main_dp ] ; then + bin/main_dp +fi +if [ -f bin/main_sp ] ; then + bin/main_sp +fi { set +ex; } 2>/dev/null echo "+++++++++++++++++" diff --git a/tests/test_install/CMakeLists.txt b/tests/test_install/CMakeLists.txt index da9ae95..b744bd0 100644 --- a/tests/test_install/CMakeLists.txt +++ b/tests/test_install/CMakeLists.txt @@ -12,10 +12,14 @@ project( fiat_test_install VERSION 0.0.0 LANGUAGES Fortran ) find_package( fiat REQUIRED ) +if( TARGET parkind_dp ) ecbuild_add_executable( TARGET main_dp SOURCES main.F90 LIBS fiat parkind_dp ) +endif() +if( TARGET parkind_sp ) ecbuild_add_executable( TARGET main_sp SOURCES main.F90 LIBS fiat parkind_sp ) +endif()