From 84542c35e49550f24ac0bb940bac4ae997de80b0 Mon Sep 17 00:00:00 2001 From: Taylor Barnes Date: Tue, 7 Jan 2025 12:07:25 -0500 Subject: [PATCH 1/8] Improve handling of CMake language choice --- CMakeLists.txt | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92c4909f..0d99dc3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,10 @@ cmake_minimum_required(VERSION 3.7) -option(language "language") +# Options +option(MDI_CXX "Build with CXX suport (on or off)" ON) +option(MDI_Fortran "Build with Fortran support (on or off)" ON) +option(MDI_Python "Build with Python support (on or off)" ON) + option(libtype "libtype") option(mpi "on or off" ON) option(python_package "on or off" OFF) @@ -12,6 +16,9 @@ option(test_drivers "on or off" ${test_codes}) option(test_engines "on or off" ${test_codes}) option(debug "on or off" OFF) +# Deprecated Options +option(language "language") + set(use_C "") set(use_CXX "") set(use_Fortran "") @@ -20,9 +27,15 @@ set(use_Python "") if( NOT language ) # By default, compile for all languages set(use_C "C") - set(use_CXX "CXX") - set(use_Fortran "Fortran") - set(use_Python "Python") + if( MDI_CXX ) + set(use_CXX "CXX") + endif() + if( MDI_Fortran ) + set(use_Fortran "Fortran") + endif() + if( MDI_Python ) + set(use_Python "Python") + endif() elseif( language STREQUAL "C" ) set(use_C "C") elseif( language STREQUAL "CXX" ) From fb00591bf4791783d8caa83e80ef236d7454fbaa Mon Sep 17 00:00:00 2001 From: Taylor Barnes Date: Tue, 7 Jan 2025 12:52:28 -0500 Subject: [PATCH 2/8] Deprecate libtype --- CMakeLists.txt | 12 +++++----- MDI_Library/CMakeLists.txt | 49 +++++++++++++++++++------------------- MDI_Library/mdi_global.h | 2 +- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d99dc3b..0055f29c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,10 @@ cmake_minimum_required(VERSION 3.7) # Options -option(MDI_CXX "Build with CXX suport (on or off)" ON) -option(MDI_Fortran "Build with Fortran support (on or off)" ON) -option(MDI_Python "Build with Python support (on or off)" ON) +option(MDI_CXX "Build with CXX suport - ON (DEFAULT) or OFF)" ON) +option(MDI_Fortran "Build with Fortran support - ON (DEFAULT) or OFF)" ON) +option(MDI_Python "Build with Python support - ON (DEFAULT) or OFF)" ON) -option(libtype "libtype") option(mpi "on or off" ON) option(python_package "on or off" OFF) option(plugins "on or off" ON) @@ -17,7 +16,8 @@ option(test_engines "on or off" ${test_codes}) option(debug "on or off" OFF) # Deprecated Options -option(language "language") +option(language "Deprecated; use MDI_CXX, MDI_Fortran, and/or MDI_Python instead.") +option(libtype "Deprecated; use BUILD_SHARED_LIBS instead.") set(use_C "") set(use_CXX "") @@ -52,7 +52,7 @@ else() endif() project(mdi - VERSION 1.4.30 + VERSION 1.4.31 LANGUAGES ${use_C} ${use_CXX} ${use_Fortran}) # set a definition to enable MDI debug mode diff --git a/MDI_Library/CMakeLists.txt b/MDI_Library/CMakeLists.txt index b6fa90c0..811cbe07 100644 --- a/MDI_Library/CMakeLists.txt +++ b/MDI_Library/CMakeLists.txt @@ -4,13 +4,10 @@ macro(string_to_list _VAR _STR) STRING(REPLACE " " ";" ${_VAR} "${_STR}") endmacro(string_to_list _VAR _STR) - -################################# MDI Project ################################## include(GNUInstallDirs) include(CMakePackageConfigHelpers) - -#check for MPI +# Check for MPI if ( NOT ( mpi STREQUAL "OFF") ) find_package(MPI) endif() @@ -21,19 +18,11 @@ if( NOT MPI_FOUND ) set(mpi "OFF") endif() -#confirm that "language" is a valid value +# Confirm that "language" is a valid value if( language AND (NOT language STREQUAL "C") AND (NOT language STREQUAL "CXX") AND (NOT language STREQUAL "Fortran") AND (NOT language STREQUAL "Python") ) message( FATAL_ERROR "Value of language not recognized. Accepted values are: C; CXX; Fortran; Python." ) endif() -#determine whether this is a SHARED or STATIC build -if( NOT libtype ) - set(libtype "SHARED") -elseif ( (NOT libtype STREQUAL "STATIC") AND - (NOT libtype STREQUAL "SHARED") ) - message( FATAL_ERROR "Value of libtype not recognized. Accepted values are: SHARED; STATIC; PACKAGE." ) -endif() - # Set flag for whether to build plugins if( ${plugins} ) add_definitions(-D_MDI_PLUGIN_SUPPORT=1) @@ -41,8 +30,7 @@ else() add_definitions(-D_MDI_PLUGIN_SUPPORT=0) endif() - -#construct the list of source files +# Construct the list of source files list(APPEND sources "mdi.c") list(APPEND sources "mdi_global.h") list(APPEND sources "mdi_global.c") @@ -79,18 +67,32 @@ if( (NOT language) OR (language STREQUAL "Fortran") ) list(APPEND sources "mdi_f90.F90") endif() -add_library(mdi ${libtype} - ${sources}) +# Set whether MDI should be built as a shared or static library +if ( libtype STREQUAL "SHARED" ) + set(BUILD_SHARED_LIBS ON) +endif() +if (BUILD_SHARED_LIBS) + set(mdi_STATIC_BUILD OFF) +else() + set(mdi_STATIC_BUILD ON) +endif() + +# Add the MDI target +add_library(mdi) + +# Add the source files +target_sources(mdi + PRIVATE ${sources}) -# set API version of MDI Library +# Set API version of MDI Library set_target_properties(mdi PROPERTIES SOVERSION 1) # bump whenever interface has changes or removals -#if this is a Windows build, link to ws2_32 +# If this is a Windows build, link to ws2_32 if(WIN32) target_link_libraries(mdi wsock32 ws2_32) endif() -#link to libdl, which is used for the plugin system +# Link to libdl, which is used for the plugin system if(NOT WIN32) target_link_libraries(mdi dl) endif() @@ -102,10 +104,10 @@ else() add_definitions(-DMDI_WINDOWS=0) endif() -#include and link to MPI +# Include and link to MPI if( mpi STREQUAL "ON" ) - #include MPI + # Include MPI string_to_list(MPI_C_COMPILE_OPTIONS "${MPI_C_COMPILE_FLAGS}") string_to_list(MPI_C_LINK_OPTIONS "${MPI_C_LINK_FLAGS}") @@ -136,7 +138,7 @@ else() endif() -#do any Python-specific work +# Do any Python-specific work if( (NOT language) OR (language STREQUAL "Python") ) if( libtype STREQUAL "STATIC" ) @@ -221,7 +223,6 @@ install(TARGETS mdi ARCHIVE DESTINATION ${MDI_INSTALL_LIBDIR}) # Provide support for packages - set(CMAKECONFIG_INSTALL_DIR "share/cmake/${PN}") configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/${PN}Config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/${PN}Config.cmake" diff --git a/MDI_Library/mdi_global.h b/MDI_Library/mdi_global.h index cc389f97..ec2d731d 100644 --- a/MDI_Library/mdi_global.h +++ b/MDI_Library/mdi_global.h @@ -32,7 +32,7 @@ // MDI version numbers #define MDI_MAJOR_VERSION_ 1 #define MDI_MINOR_VERSION_ 4 -#define MDI_PATCH_VERSION_ 30 +#define MDI_PATCH_VERSION_ 31 // length of an MDI command in characters #define MDI_COMMAND_LENGTH_ 256 From 731103f84ac04219ec786ccf60b77ef2fb3ab4cb Mon Sep 17 00:00:00 2001 From: Taylor Barnes Date: Tue, 7 Jan 2025 18:32:32 +0000 Subject: [PATCH 3/8] Improve handling of MPI CMake option --- CMakeLists.txt | 17 +++++++++++++++-- MDI_Library/CMakeLists.txt | 13 +------------ tests/MDI_Test_Codes/CMakeLists.txt | 15 ++------------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0055f29c..e2a7a61f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,8 @@ cmake_minimum_required(VERSION 3.7) option(MDI_CXX "Build with CXX suport - ON (DEFAULT) or OFF)" ON) option(MDI_Fortran "Build with Fortran support - ON (DEFAULT) or OFF)" ON) option(MDI_Python "Build with Python support - ON (DEFAULT) or OFF)" ON) +set(MDI_USE_MPI "" CACHE STRING "Flag to use MPI - ON (DEFAULT) or OFF") -option(mpi "on or off" ON) option(python_package "on or off" OFF) option(plugins "on or off" ON) option(python_plugins "on or off" ${plugins}) @@ -18,6 +18,7 @@ option(debug "on or off" OFF) # Deprecated Options option(language "Deprecated; use MDI_CXX, MDI_Fortran, and/or MDI_Python instead.") option(libtype "Deprecated; use BUILD_SHARED_LIBS instead.") +set(mpi ${MDI_USE_MPI} CACHE STRING "Deprecated; use MDI_USE_MPI instead.") set(use_C "") set(use_CXX "") @@ -55,7 +56,19 @@ project(mdi VERSION 1.4.31 LANGUAGES ${use_C} ${use_CXX} ${use_Fortran}) -# set a definition to enable MDI debug mode +# Check for MPI +if ( mpi STREQUAL "ON" ) + find_package(MPI REQUIRED) +elseif( NOT ( mpi STREQUAL "OFF") ) + find_package(MPI) + if ( MPI_FOUND ) + set( mpi "ON" ) + else() + set( mpi "OFF" ) + endif() +endif() + +# Set a definition to enable MDI debug mode if( ${debug} ) add_definitions(-D_MDI_DEBUG=1) else() diff --git a/MDI_Library/CMakeLists.txt b/MDI_Library/CMakeLists.txt index 811cbe07..a5a130db 100644 --- a/MDI_Library/CMakeLists.txt +++ b/MDI_Library/CMakeLists.txt @@ -7,17 +7,6 @@ endmacro(string_to_list _VAR _STR) include(GNUInstallDirs) include(CMakePackageConfigHelpers) -# Check for MPI -if ( NOT ( mpi STREQUAL "OFF") ) - find_package(MPI) -endif() -if( NOT MPI_FOUND ) - if( mpi STREQUAL "ON" ) - message( WARNING "Could not find MPI. Compiling without MPI support." ) - endif() - set(mpi "OFF") -endif() - # Confirm that "language" is a valid value if( language AND (NOT language STREQUAL "C") AND (NOT language STREQUAL "CXX") AND (NOT language STREQUAL "Fortran") AND (NOT language STREQUAL "Python") ) message( FATAL_ERROR "Value of language not recognized. Accepted values are: C; CXX; Fortran; Python." ) @@ -122,7 +111,7 @@ elseif( mpi STREQUAL "OFF" ) else() - message( FATAL_ERROR "Value of mpi not recognized. Accepted values are: ON; OFF." ) + message( FATAL_ERROR "Value of mpi (${mpi}) not recognized. Accepted values are: ON; OFF." ) endif() diff --git a/tests/MDI_Test_Codes/CMakeLists.txt b/tests/MDI_Test_Codes/CMakeLists.txt index 9384d2f9..1120d583 100644 --- a/tests/MDI_Test_Codes/CMakeLists.txt +++ b/tests/MDI_Test_Codes/CMakeLists.txt @@ -1,20 +1,9 @@ -# Check for MPI - -if ( NOT ( mpi STREQUAL "OFF") ) - find_package(MPI) -endif() -if( NOT MPI_FOUND ) - if( mpi STREQUAL "ON" ) - message( WARNING "Could not find MPI. Compiling without MPI support." ) - endif() +# Include MPI stubs, if needed +if( mpi STREQUAL "OFF" ) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/STUBS_MPI/mpi.h ${CMAKE_CURRENT_BINARY_DIR}/STUBS_MPI/mpi.h COPYONLY) - set(mpi "OFF") endif() - - # Macro to link target to MPI - macro(link_against_mpi _TAR) if( mpi STREQUAL "ON" ) From 8ccf429d8a160b28ab909ed5276932174f744dea Mon Sep 17 00:00:00 2001 From: Taylor Barnes Date: Tue, 7 Jan 2025 18:46:37 +0000 Subject: [PATCH 4/8] Update CMakeLists.txt --- CMakeLists.txt | 2 +- MDI_Library/CMakeLists.txt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2a7a61f..87d43c8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.10) # Options option(MDI_CXX "Build with CXX suport - ON (DEFAULT) or OFF)" ON) diff --git a/MDI_Library/CMakeLists.txt b/MDI_Library/CMakeLists.txt index a5a130db..56a4ccb0 100644 --- a/MDI_Library/CMakeLists.txt +++ b/MDI_Library/CMakeLists.txt @@ -60,6 +60,9 @@ endif() if ( libtype STREQUAL "SHARED" ) set(BUILD_SHARED_LIBS ON) endif() +if ( NOT libtype ) + set(BUILD_SHARED_LIBS ON) +endif() if (BUILD_SHARED_LIBS) set(mdi_STATIC_BUILD OFF) else() From a1e0a80a15f52f364ed56f1e00b27b901d4499a8 Mon Sep 17 00:00:00 2001 From: Taylor Barnes Date: Tue, 7 Jan 2025 18:56:52 +0000 Subject: [PATCH 5/8] Compile static build with position independent code --- MDI_Library/CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/MDI_Library/CMakeLists.txt b/MDI_Library/CMakeLists.txt index 56a4ccb0..17ac73d1 100644 --- a/MDI_Library/CMakeLists.txt +++ b/MDI_Library/CMakeLists.txt @@ -60,9 +60,6 @@ endif() if ( libtype STREQUAL "SHARED" ) set(BUILD_SHARED_LIBS ON) endif() -if ( NOT libtype ) - set(BUILD_SHARED_LIBS ON) -endif() if (BUILD_SHARED_LIBS) set(mdi_STATIC_BUILD OFF) else() @@ -76,6 +73,11 @@ add_library(mdi) target_sources(mdi PRIVATE ${sources}) +# If this is a static library, should compile with position independent code +if ( mdi_STATIC_BUILD ) + set_target_properties(mdi PROPERTIES POSITION_INDEPENDENT_CODE ON) +endif() + # Set API version of MDI Library set_target_properties(mdi PROPERTIES SOVERSION 1) # bump whenever interface has changes or removals From 7af99122531359c073368bee5e346cf994541b76 Mon Sep 17 00:00:00 2001 From: Taylor Barnes Date: Tue, 7 Jan 2025 19:23:28 +0000 Subject: [PATCH 6/8] Set shared library build if supporting Python --- MDI_Library/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MDI_Library/CMakeLists.txt b/MDI_Library/CMakeLists.txt index 17ac73d1..6181e9e4 100644 --- a/MDI_Library/CMakeLists.txt +++ b/MDI_Library/CMakeLists.txt @@ -60,6 +60,10 @@ endif() if ( libtype STREQUAL "SHARED" ) set(BUILD_SHARED_LIBS ON) endif() +if ( (NOT BUILD_SHARED_LIBS) AND MDI_Python ) + message( WARNING "Python support requires that the MDI Library be compiled as a shared library. Turning on shared library build. To disable this warning, set -DBUILD_SHARED_LIBS=ON or -DMDI_Python=OFF." ) + set(BUILD_SHARED_LIBS ON) +endif() if (BUILD_SHARED_LIBS) set(mdi_STATIC_BUILD OFF) else() From e661fd8a873e8dd33437d199ae5f3c4ff8e54b2f Mon Sep 17 00:00:00 2001 From: Taylor Barnes Date: Tue, 7 Jan 2025 19:44:56 +0000 Subject: [PATCH 7/8] Improve build options --- CMakeLists.txt | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 87d43c8c..0aceced5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,21 +4,28 @@ cmake_minimum_required(VERSION 3.10) option(MDI_CXX "Build with CXX suport - ON (DEFAULT) or OFF)" ON) option(MDI_Fortran "Build with Fortran support - ON (DEFAULT) or OFF)" ON) option(MDI_Python "Build with Python support - ON (DEFAULT) or OFF)" ON) -set(MDI_USE_MPI "" CACHE STRING "Flag to use MPI - ON (DEFAULT) or OFF") - -option(python_package "on or off" OFF) -option(plugins "on or off" ON) -option(python_plugins "on or off" ${plugins}) -option(python_version "python version number" OFF) -option(test_codes "on or off" OFF) -option(test_drivers "on or off" ${test_codes}) -option(test_engines "on or off" ${test_codes}) -option(debug "on or off" OFF) +option(MDI_Python_PACKAGE "Flag to install MDI as a Python package" OFF) +option(MDI_PLUGINS "Flag to compile with support for MDI plugins" ON) +option(MDI_Python_PLUGINS "Flag to compile with support for MDI Python plugins" ${MDI_PLUGINS}) +option(MDI_TEST_CODES "Flag to compile MDI test codes" OFF) +option(MDI_TEST_DRIVERS "Flag to compile MDI test drivers" ${MDI_TEST_CODES}) +option(MDI_TEST_ENGINES "Flag to compile MDI test engines" ${MDI_TEST_CODES}) +option(MDI_DEBUG "Flag to compile MDI in debug mode" OFF) +set(MDI_USE_MPI "" CACHE STRING "Flag to use MPI - ON or OFF") +set(MDI_Python_VERSION "OFF" CACHE STRING "When linking against a build of Python, MDI will attempt to link against a build of Python corresponding to this version number.") # Deprecated Options option(language "Deprecated; use MDI_CXX, MDI_Fortran, and/or MDI_Python instead.") option(libtype "Deprecated; use BUILD_SHARED_LIBS instead.") set(mpi ${MDI_USE_MPI} CACHE STRING "Deprecated; use MDI_USE_MPI instead.") +set(python_package ${MDI_Python_PACKAGE} CACHE STRING "Deprecated; use MDI_Python_PACKAGE instead.") +set(plugins ${MDI_PLUGINS} CACHE STRING "Deprecated; use MDI_PLUGINS instead.") +set(python_plugins ${MDI_Python_PLUGINS} CACHE STRING "Deprecated; use MDI_Python_PLUGINS instead.") +set(python_version ${MDI_Python_VERSION} CACHE STRING "Deprecated; use MDI_Python_VERSION instead.") +set(test_codes ${MDI_TEST_CODES} CACHE STRING "Deprecated; use MDI_TEST_CODES instead.") +set(test_drivers ${MDI_TEST_DRIVERS} CACHE STRING "Deprecated; use MDI_TEST_DRIVERS instead.") +set(test_engines ${MDI_TEST_ENGINES} CACHE STRING "Deprecated; use MDI_TEST_ENGINES instead.") +set(debug ${MDI_DEBUG} CACHE STRING "Deprecated; use MDI_DEBUG instead.") set(use_C "") set(use_CXX "") From f7a733ad314819b16744dcd836e571178a38ff05 Mon Sep 17 00:00:00 2001 From: Taylor Barnes Date: Tue, 7 Jan 2025 20:21:04 +0000 Subject: [PATCH 8/8] Fix handling of deprecated CMake options --- CMakeLists.txt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0aceced5..7d3257df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,10 +19,23 @@ option(language "Deprecated; use MDI_CXX, MDI_Fortran, and/or MDI_Python instead option(libtype "Deprecated; use BUILD_SHARED_LIBS instead.") set(mpi ${MDI_USE_MPI} CACHE STRING "Deprecated; use MDI_USE_MPI instead.") set(python_package ${MDI_Python_PACKAGE} CACHE STRING "Deprecated; use MDI_Python_PACKAGE instead.") -set(plugins ${MDI_PLUGINS} CACHE STRING "Deprecated; use MDI_PLUGINS instead.") +set(plugins "" CACHE STRING "Deprecated; use MDI_PLUGINS instead.") +if ( plugins STREQUAL "" ) + set(plugins ${MDI_PLUGINS}) +else() + set(MDI_PLUGINS ${plugins}) + set(MDI_Python_PLUGINS ${plugins}) +endif() set(python_plugins ${MDI_Python_PLUGINS} CACHE STRING "Deprecated; use MDI_Python_PLUGINS instead.") set(python_version ${MDI_Python_VERSION} CACHE STRING "Deprecated; use MDI_Python_VERSION instead.") -set(test_codes ${MDI_TEST_CODES} CACHE STRING "Deprecated; use MDI_TEST_CODES instead.") +set(test_codes "" CACHE STRING "Deprecated; use MDI_TEST_CODES instead.") +if( test_codes STREQUAL "" ) + set(test_codes ${MDI_TEST_CODES}) +else() + set(MDI_TEST_CODES ${test_codes}) + set(MDI_TEST_DRIVERS ${test_codes}) + set(MDI_TEST_ENGINES ${test_codes}) +endif() set(test_drivers ${MDI_TEST_DRIVERS} CACHE STRING "Deprecated; use MDI_TEST_DRIVERS instead.") set(test_engines ${MDI_TEST_ENGINES} CACHE STRING "Deprecated; use MDI_TEST_ENGINES instead.") set(debug ${MDI_DEBUG} CACHE STRING "Deprecated; use MDI_DEBUG instead.")