Skip to content

Commit 24e92f8

Browse files
committed
fixing windows link regression in hdf5
1 parent 5f9a403 commit 24e92f8

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,12 @@ include_directories(
190190
file(GLOB_RECURSE CPP_FILES "src/c++/*.cpp")
191191
file(GLOB_RECURSE HPP_FILES "include/*.hpp")
192192
file(GLOB_RECURSE PYBIND_CPP_FILES "src/c++/*_pybind.cpp")
193+
set(CORE_PYTHON_ONLY_SRC
194+
${CMAKE_SOURCE_DIR}/src/c++/io/cgns/node_pycgns_converter.cpp
195+
)
193196
set(CORE_SHARED_SRC ${CPP_FILES} ${HPP_FILES})
194197
list(REMOVE_ITEM CORE_SHARED_SRC ${PYBIND_CPP_FILES})
198+
list(REMOVE_ITEM CORE_SHARED_SRC ${CORE_PYTHON_ONLY_SRC})
195199

196200
if (MSVC)
197201
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
@@ -228,7 +232,6 @@ elseif(UNIX OR MSVC)
228232
endif()
229233

230234
target_compile_definitions(core_shared PRIVATE BUILDING_NODE_LIBRARY)
231-
target_link_libraries(core_shared PUBLIC pybind11::module)
232235

233236

234237
if(ENABLE_HDF5_IO)
@@ -237,13 +240,21 @@ if(ENABLE_HDF5_IO)
237240
if(MSVC)
238241
# Copy HDF5 DLLs into the wheel output directory so they're bundled in the .whl
239242
set(HDF5_DLL "${HDF5_ROOT}/bin/hdf5.dll")
243+
if(DEFINED HDF5_C_LIBRARY AND EXISTS "${HDF5_C_LIBRARY}")
244+
set(HDF5_IMPLIB "${HDF5_C_LIBRARY}")
245+
else()
246+
set(HDF5_IMPLIB "${HDF5_ROOT}/lib/hdf5.lib")
247+
endif()
240248
if(EXISTS "${HDF5_DLL}")
241249
message(STATUS "Copying HDF5 DLL: ${HDF5_DLL}")
242250
file(COPY "${HDF5_DLL}" DESTINATION ${VERSIONED_OUTPUT_DIR})
243251
set(HDF5_DLL_IN_OUTPUT "${VERSIONED_OUTPUT_DIR}/hdf5.dll")
244252
else()
245253
message(FATAL_ERROR "Required HDF5 DLL not found: ${HDF5_DLL}")
246-
endif()
254+
endif()
255+
if(NOT EXISTS "${HDF5_IMPLIB}")
256+
message(FATAL_ERROR "Required HDF5 import library not found: ${HDF5_IMPLIB}")
257+
endif()
247258
endif()
248259

249260
if(UNIX AND NOT APPLE)
@@ -282,12 +293,17 @@ endif()
282293

283294
pybind11_add_module(core MODULE
284295
src/c++/core_pybind.cpp
296+
${CORE_PYTHON_ONLY_SRC}
285297
)
286298
target_link_libraries(core PRIVATE core_shared)
287299
add_dependencies(core core_shared)
288300
if(APPLE)
289301
target_link_options(core PRIVATE "-Wl,-force_load,$<TARGET_FILE:core_shared>")
290302
endif()
303+
if(ENABLE_HDF5_IO)
304+
target_include_directories(core PRIVATE ${HDF5_INCLUDE_DIRS})
305+
target_link_libraries(core PRIVATE ${HDF5_LIBRARIES})
306+
endif()
291307

292308
pybind11_add_module(_cgns MODULE src/c++/cgns_pybind.cpp)
293309
target_link_libraries(_cgns PRIVATE core_shared)
@@ -299,6 +315,7 @@ endif()
299315
install(TARGETS core_shared EXPORT noderTargets DESTINATION ${NODER_PACKAGE_DIR})
300316
if(MSVC AND ENABLE_HDF5_IO)
301317
install(FILES "${HDF5_DLL_IN_OUTPUT}" DESTINATION ${NODER_PACKAGE_DIR})
318+
install(FILES "${HDF5_IMPLIB}" DESTINATION ${NODER_PACKAGE_DIR})
302319
endif()
303320

304321
install(TARGETS core DESTINATION ${NODER_PACKAGE_DIR})

cmake/noderConfig.cmake.in

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
include(CMakeFindDependencyMacro)
44

5-
find_dependency(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
6-
7-
if(NOT pybind11_FOUND)
8-
execute_process(
9-
COMMAND "${Python3_EXECUTABLE}" -m pybind11 --cmakedir
10-
OUTPUT_VARIABLE _noder_pybind11_cmakedir
11-
OUTPUT_STRIP_TRAILING_WHITESPACE
12-
RESULT_VARIABLE _noder_pybind11_status
13-
)
14-
if(_noder_pybind11_status EQUAL 0 AND EXISTS "${_noder_pybind11_cmakedir}")
15-
list(PREPEND CMAKE_PREFIX_PATH "${_noder_pybind11_cmakedir}")
5+
if("@ENABLE_HDF5_IO@" STREQUAL "ON" AND WIN32)
6+
set(_noder_hdf5_dll "${PACKAGE_PREFIX_DIR}/noder/hdf5.dll")
7+
set(_noder_hdf5_implib "${PACKAGE_PREFIX_DIR}/noder/hdf5.lib")
8+
if(EXISTS "${_noder_hdf5_dll}" AND EXISTS "${_noder_hdf5_implib}")
9+
if(NOT TARGET hdf5::hdf5-shared)
10+
add_library(hdf5::hdf5-shared SHARED IMPORTED)
11+
set_target_properties(hdf5::hdf5-shared PROPERTIES
12+
IMPORTED_IMPLIB "${_noder_hdf5_implib}"
13+
IMPORTED_LOCATION "${_noder_hdf5_dll}"
14+
)
15+
endif()
16+
else()
17+
find_dependency(HDF5 REQUIRED COMPONENTS C)
1618
endif()
1719
endif()
1820

19-
find_dependency(pybind11 CONFIG REQUIRED)
20-
2121
include("${CMAKE_CURRENT_LIST_DIR}/noderTargets.cmake")
2222

2323
set_and_check(noder_PACKAGE_DIR "@PACKAGE_NODER_PACKAGE_DIR@")

include/io/cgns/node_pycgns_converter.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ namespace py = pybind11;
1515
* @param node Root node to convert.
1616
* @return Nested list representation.
1717
*/
18-
NODE_EXPORT py::list nodeToPyCGNS(const std::shared_ptr<Node>& node);
18+
py::list nodeToPyCGNS(const std::shared_ptr<Node>& node);
1919

2020
/**
2121
* @brief Convert a Python CGNS-like nested list to a Node hierarchy.
2222
* @param pyList Nested list representation.
2323
* @return Converted root node.
2424
*/
25-
NODE_EXPORT std::shared_ptr<Node> pyCGNSToNode(const py::list& pyList);
25+
std::shared_ptr<Node> pyCGNSToNode(const py::list& pyList);
2626

2727
# endif

0 commit comments

Comments
 (0)