From aa504e6fdbe1af411bc5d346680f01d7465d8205 Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Tue, 5 Mar 2024 18:16:08 -0700 Subject: [PATCH 1/3] Support shared exodus library on windows --- packages/seacas/libraries/exodus/CMakeLists.txt | 11 +++++++---- .../seacas/libraries/exodus/include/exodusII.h | 7 +++++++ packages/seacas/scripts/CMakeLists.txt | 2 +- packages/seacas/scripts/exodus3.in.py | 17 ++++++++++++----- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/packages/seacas/libraries/exodus/CMakeLists.txt b/packages/seacas/libraries/exodus/CMakeLists.txt index 15860b2a8d..ad56f2903d 100644 --- a/packages/seacas/libraries/exodus/CMakeLists.txt +++ b/packages/seacas/libraries/exodus/CMakeLists.txt @@ -38,14 +38,17 @@ set_property(TARGET exodus PROPERTY C_STANDARD 99) if (SEACASExodus_ENABLE_SHARED) if (NOT BUILD_SHARED_LIBS) - TRIBITS_ADD_LIBRARY( + ADD_LIBRARY( exodus_shared SHARED - SOURCES ${SOURCES} ${DEP_SOURCES} - IMPORTEDLIBS ${TPL_Netcdf_LIBRARIES} + ${SOURCES} ${DEP_SOURCES} ) + target_include_directories(exodus_shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) + target_link_libraries(exodus_shared PUBLIC Netcdf::all_libs) set_property(TARGET exodus_shared PROPERTY C_STANDARD 99) - set_target_properties(exodus_shared PROPERTIES OUTPUT_NAME exodus) + # This keeps the library out of the `all_libs` targets... + set_target_properties(exodus_shared PROPERTIES TRIBITS_TESTONLY_LIB TRUE) + set_target_properties(exodus_shared PROPERTIES RUNTIME_OUTPUT_NAME exodus) INSTALL(TARGETS exodus_shared DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) endif() endif() diff --git a/packages/seacas/libraries/exodus/include/exodusII.h b/packages/seacas/libraries/exodus/include/exodusII.h index f3ab3b718d..9c9b1fa111 100644 --- a/packages/seacas/libraries/exodus/include/exodusII.h +++ b/packages/seacas/libraries/exodus/include/exodusII.h @@ -471,6 +471,13 @@ typedef struct ex_var_params } ex_var_params; /** @} */ +#ifndef EXODUS_EXPORT +#if defined(_WIN32) && defined(exodus_shared_EXPORTS) +#define EXODUS_EXPORT __declspec(dllexport) +#endif +#endif /* EXODUS_EXPORT */ + + #ifndef EXODUS_EXPORT #define EXODUS_EXPORT extern #endif /* EXODUS_EXPORT */ diff --git a/packages/seacas/scripts/CMakeLists.txt b/packages/seacas/scripts/CMakeLists.txt index d63de072ba..f417e77f4e 100644 --- a/packages/seacas/scripts/CMakeLists.txt +++ b/packages/seacas/scripts/CMakeLists.txt @@ -173,7 +173,7 @@ IF (${PROJECT_NAME}_ENABLE_SEACASExodus) INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/exomerge2.py DESTINATION lib) INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/exomerge3.py DESTINATION lib) - if (${CMAKE_PROJECT_NAME} STREQUAL "Seacas") + if (NOT WIN32 AND ${CMAKE_PROJECT_NAME} STREQUAL "Seacas") InstallSymLink(${EXODUSPY} ${CMAKE_INSTALL_PREFIX}/lib/exodus.py) InstallSymLink(${EXOMERGE} ${CMAKE_INSTALL_PREFIX}/lib/exomerge.py) endif() diff --git a/packages/seacas/scripts/exodus3.in.py b/packages/seacas/scripts/exodus3.in.py index 542121007e..3051622263 100644 --- a/packages/seacas/scripts/exodus3.in.py +++ b/packages/seacas/scripts/exodus3.in.py @@ -161,16 +161,23 @@ class ex_options(Enum): EX_NULLVERBOSE = 8 -ACCESS = os.getenv('ACCESS', '@ACCESSDIR@') -if os.uname()[0] == 'Darwin': - EXODUS_SO = f"{ACCESS}/@SEACAS_LIBDIR@/libexodus.dylib" +if os.name == 'nt': + so_prefix = '' + so_suffix = 'dll' else: - EXODUS_SO = f"{ACCESS}/@SEACAS_LIBDIR@/libexodus.so" + if os.uname()[0] == 'Darwin': + so_prefix = 'lib' + so_suffix = 'dylib' + else: + so_prefix = 'lib' + so_suffix = 'so' pip_path = os.path.dirname(__file__) -pip_so_path = os.path.join(pip_path, "libexodus.so") +pip_so_path = os.path.join(pip_path, f"{so_prefix}exodus.{so_suffix}") try: EXODUS_LIB = ctypes.cdll.LoadLibrary(pip_so_path) except Exception: + ACCESS = os.getenv('ACCESS', '@ACCESSDIR@') + EXODUS_SO = f"{ACCESS}/@SEACAS_LIBDIR@/{so_prefix}exodus.{so_suffix}" EXODUS_LIB = ctypes.cdll.LoadLibrary(EXODUS_SO) MAX_STR_LENGTH = 32 # match exodus default From 491011f87235c27dc625d2f96afd035f72ac427c Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Wed, 6 Mar 2024 07:19:18 -0700 Subject: [PATCH 2/3] Fix flake8 issue -- multiple spaces after operator --- packages/seacas/scripts/exodus3.in.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/seacas/scripts/exodus3.in.py b/packages/seacas/scripts/exodus3.in.py index 3051622263..a9c573c1e5 100644 --- a/packages/seacas/scripts/exodus3.in.py +++ b/packages/seacas/scripts/exodus3.in.py @@ -161,7 +161,7 @@ class ex_options(Enum): EX_NULLVERBOSE = 8 -if os.name == 'nt': +if os.name == 'nt': so_prefix = '' so_suffix = 'dll' else: From 4143a5622fc90652917d1ce36f7d6fbd26e11ab0 Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Wed, 6 Mar 2024 07:25:03 -0700 Subject: [PATCH 3/3] Minor style changes Reversed test just because of "feels" better Fixed some leftover bad formatting while in the file. --- packages/seacas/scripts/CMakeLists.txt | 34 +++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/seacas/scripts/CMakeLists.txt b/packages/seacas/scripts/CMakeLists.txt index f417e77f4e..0b0c4497b0 100644 --- a/packages/seacas/scripts/CMakeLists.txt +++ b/packages/seacas/scripts/CMakeLists.txt @@ -1,5 +1,5 @@ if (${CMAKE_PROJECT_NAME} STREQUAL "Seacas") -INCLUDE(InstallSymLink) + INCLUDE(InstallSymLink) endif() SET( ACCESSDIR ${CMAKE_INSTALL_PREFIX} ) @@ -8,11 +8,11 @@ SET( SEPARATOR "_") ASSERT_DEFINED(${PROJECT_NAME}_ENABLE_SEACASNemspread) ASSERT_DEFINED(${PROJECT_NAME}_ENABLE_SEACASNemslice) IF (${PROJECT_NAME}_ENABLE_SEACASNemspread AND ${PROJECT_NAME}_ENABLE_SEACASNemslice) -IF (${PROJECT_NAME}_ENABLE_Zoltan) - SET( DECOMP_DEFAULT rib ) -ELSE() - SET( DECOMP_DEFAULT inertial ) -ENDIF() + IF (${PROJECT_NAME}_ENABLE_Zoltan) + SET( DECOMP_DEFAULT rib ) + ELSE() + SET( DECOMP_DEFAULT inertial ) + ENDIF() CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/decomp.in @@ -73,16 +73,16 @@ TRIBITS_INCLUDE_DIRECTORIES( SET(HEADERS "") IF (NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") -APPEND_GLOB(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/getopt.seacas.c) -ASSERT_DEFINED(${PROJECT_NAME}_ENABLE_SEACASBlot) -ASSERT_DEFINED(${PROJECT_NAME}_ENABLE_SEACASFastq) -ASSERT_DEFINED(${PROJECT_NAME}_ENABLE_SEACASEpu) -IF (${PROJECT_NAME}_ENABLE_SEACASBlot OR - ${PROJECT_NAME}_ENABLE_SEACASFastq OR - ${PROJECT_NAME}_ENABLE_SEACASEpu) - ADD_EXECUTABLE(getopt.seacas ${SOURCES} ) - install_executable(getopt.seacas) -endif() + APPEND_GLOB(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/getopt.seacas.c) + ASSERT_DEFINED(${PROJECT_NAME}_ENABLE_SEACASBlot) + ASSERT_DEFINED(${PROJECT_NAME}_ENABLE_SEACASFastq) + ASSERT_DEFINED(${PROJECT_NAME}_ENABLE_SEACASEpu) + IF (${PROJECT_NAME}_ENABLE_SEACASBlot OR + ${PROJECT_NAME}_ENABLE_SEACASFastq OR + ${PROJECT_NAME}_ENABLE_SEACASEpu) + ADD_EXECUTABLE(getopt.seacas ${SOURCES} ) + install_executable(getopt.seacas) + endif() ENDIF() ASSERT_DEFINED(${PROJECT_NAME}_ENABLE_SEACASExodus) @@ -173,7 +173,7 @@ IF (${PROJECT_NAME}_ENABLE_SEACASExodus) INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/exomerge2.py DESTINATION lib) INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/exomerge3.py DESTINATION lib) - if (NOT WIN32 AND ${CMAKE_PROJECT_NAME} STREQUAL "Seacas") + if (${CMAKE_PROJECT_NAME} STREQUAL "Seacas" AND NOT WIN32) InstallSymLink(${EXODUSPY} ${CMAKE_INSTALL_PREFIX}/lib/exodus.py) InstallSymLink(${EXOMERGE} ${CMAKE_INSTALL_PREFIX}/lib/exomerge.py) endif()