Skip to content

Commit ccf0eff

Browse files
EstebanDugueperoux2aothms
authored andcommitted
cmake: Simplify hdf5 linkage
1 parent 169c439 commit ccf0eff

8 files changed

Lines changed: 100 additions & 94 deletions

File tree

.github/workflows/ci-ifcopenshell-docker.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ jobs:
6363
-DMPFR_INCLUDE_DIR=/usr/include \
6464
-DGMP_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
6565
-DMPFR_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
66-
-DHDF5_INCLUDE_DIR=/usr/include/hdf5/serial \
6766
-DGLTF_SUPPORT=On \
6867
-DJSON_INCLUDE_DIR=/usr/include \
6968
-DEIGEN_DIR=/usr/include/eigen3 \

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ jobs:
118118
-DUSE_MMAP=On \
119119
"-DSCHEMA_VERSIONS=2x3;4;4x3_add2" \
120120
-DGLTF_SUPPORT=On \
121+
-DJSON_INCLUDE_DIR=/usr/include \
122+
-DCGAL_INCLUDE_DIR=/usr/include \
123+
-DGMP_INCLUDE_DIR=/usr/include \
124+
-DMPFR_INCLUDE_DIR=/usr/include \
125+
-DGMP_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
126+
-DMPFR_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
127+
-DEIGEN_DIR=/usr/include/eigen3 \
121128
-DWITH_ROCKSDB=On \
122129
../cmake
123130
sudo make -j $(nproc)

.github/workflows/release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ jobs:
6565
-DMPFR_INCLUDE_DIR=/usr/include \
6666
-DGMP_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
6767
-DMPFR_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
68-
-DHDF5_INCLUDE_DIR=/usr/include/hdf5/serial \
6968
-DOPENCOLLADA_INCLUDE_DIR=/usr/include/opencollada \
7069
-DOPENCOLLADA_LIBRARY_DIR=/usr/lib/opencollada/ \
7170
../cmake

cmake/CMakeLists.txt

Lines changed: 5 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ endif()
104104

105105
project(IfcOpenShell VERSION ${RELEASE_VERSION})
106106

107+
# Make sure CMake modules in this project are found first
108+
list(PREPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
109+
107110
if(MINIMAL_BUILD)
108111
message(STATUS "Setting options for minimal build")
109112
set(BUILD_GEOMSERVER OFF)
@@ -730,91 +733,7 @@ endif()
730733

731734

732735
if(HDF5_SUPPORT)
733-
if("${HDF5_INCLUDE_DIR}" STREQUAL "")
734-
message(STATUS "No HDF5 include directory specified")
735-
else()
736-
set(HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIR}" CACHE FILEPATH "HDF5 header files")
737-
endif()
738-
739-
if("${HDF5_LIBRARY_DIR}" STREQUAL "")
740-
message(STATUS "No HDF5 library directory specified")
741-
else()
742-
set(HDF5_LIBRARY_DIR "${HDF5_LIBRARY_DIR}" CACHE FILEPATH "HDF5 library files")
743-
endif()
744-
745-
if(HDF5_LIBRARY_DIR)
746-
# result of the HDF5 ctest package
747-
# Find zlib using cmake find_library. How should this be implemented?
748-
# FIND_LIBRARY(NAMES z libz libz_debug PATHS ... NO_DEFAULT_PATH)
749-
if("$ENV{CONDA_BUILD}" STREQUAL "")
750-
# result of the HDF5 ctest package
751-
if(WIN32)
752-
set(zlib_post lib)
753-
set(lib_ext lib)
754-
else()
755-
set(lib_ext a)
756-
endif()
757-
758-
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
759-
set(debug_postfix "_debug")
760-
endif()
761-
762-
set(HDF5_LIBRARIES
763-
"${HDF5_LIBRARY_DIR}/libhdf5_cpp${debug_postfix}.${lib_ext}"
764-
"${HDF5_LIBRARY_DIR}/libhdf5${debug_postfix}.${lib_ext}"
765-
"${HDF5_LIBRARY_DIR}/libz${zlib_post}${debug_postfix}.${lib_ext}"
766-
"${HDF5_LIBRARY_DIR}/libsz${debug_postfix}.${lib_ext}"
767-
"${HDF5_LIBRARY_DIR}/libaec${debug_postfix}.${lib_ext}"
768-
)
769-
770-
else()
771-
message(STATUS "Packaging hdf5 and zlib for conda distribution")
772-
773-
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
774-
# macOS
775-
set(zlib_post libz)
776-
set(lib_ext dylib)
777-
set(HDF5_LIBRARIES
778-
"${HDF5_LIBRARY_DIR}/libhdf5_cpp.${lib_ext}"
779-
"${HDF5_LIBRARY_DIR}/libhdf5.${lib_ext}"
780-
"${HDF5_LIBRARY_DIR}/${zlib_post}.${lib_ext}"
781-
)
782-
else()
783-
# linux and windows
784-
# Find HDF5 package
785-
find_package(HDF5 REQUIRED COMPONENTS C CXX)
786-
# Find ZLIB package
787-
find_package(ZLIB REQUIRED)
788-
# Include directories
789-
include_directories(${HDF5_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS})
790-
# Link libraries
791-
set(HDF5_LIBRARIES ${HDF5_LIBRARIES} ${ZLIB_LIBRARIES})
792-
message(STATUS "HDF5 libraries: ${HDF5_LIBRARIES}")
793-
endif()
794-
endif()
795-
endif()
796-
797-
if(NOT HDF5_INCLUDE_DIR OR NOT HDF5_LIBRARY_DIR)
798-
# First try to find it as a config.
799-
find_package(HDF5 CONFIG)
800-
if(HDF5_DIR)
801-
message(STATUS "HDF5: found config at '${HDF5_DIR}'.")
802-
set(HDF5_LIBRARIES hdf5_cpp-static)
803-
else()
804-
# If it failed, still try to find as a module.
805-
# E.g. on Ubuntu `libhdf5-dev` doesn't provie hdf5-config.cmake.
806-
# Will automatically fill HDF5_LIBRARIES and HDF5_INCLUDE_DIR.
807-
find_package(HDF5 COMPONENTS CXX)
808-
if(NOT HDF5_INCLUDE_DIR)
809-
message(
810-
FATAL_ERROR
811-
"HDF5_INCLUDE_DIR is not provided (current value: '${HDF5_INCLUDE_DIR}'). "
812-
"HDF5_LIBRARY_DIR is not provided (current value: '${HDF5_LIBRARY_DIR}'). "
813-
"Also could not find HDF5 package (neither module or config)."
814-
)
815-
endif()
816-
endif()
817-
endif()
736+
find_package(HDF5 REQUIRED COMPONENTS C CXX)
818737

819738
add_definitions(-DWITH_HDF5)
820739
set(SWIG_DEFINES ${SWIG_DEFINES} -DWITH_HDF5)
@@ -948,7 +867,7 @@ endif()
948867

949868

950869
include_directories(${INCLUDE_DIRECTORIES} ${OCC_INCLUDE_DIR} ${OPENCOLLADA_INCLUDE_DIRS}
951-
${Boost_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIR} ${JSON_INCLUDE_DIR} ${HDF5_INCLUDE_DIR}
870+
${Boost_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIR} ${JSON_INCLUDE_DIR} ${HDF5_INCLUDE_DIRS}
952871
${EIGEN_DIR} ${CGAL_INCLUDE_DIR} ${GMP_INCLUDE_DIR} ${MPFR_INCLUDE_DIR} ${USD_INCLUDE_DIR}
953872
${TBB_INCLUDE_DIR}
954873
)

cmake/CMakePresets.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
"MPFR_LIBRARY_DIR": "$env{LIBRARY_PREFIX}/lib",
5252
"Boost_LIBRARY_DIR": "$env{LIBRARY_PREFIX}/lib",
5353
"Boost_INCLUDE_DIR": "$env{LIBRARY_PREFIX}/include",
54-
"HDF5_INCLUDE_DIR": "$env{LIBRARY_PREFIX}/include",
55-
"HDF5_LIBRARY_DIR": "$env{LIBRARY_PREFIX}/lib",
5654
"ZLIB_INCLUDE_DIR": "$env{LIBRARY_PREFIX}/include"
5755
}
5856
},

cmake/HDF5Config.cmake

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# To avoid cyclic calls to this file
2+
list(REMOVE_ITEM CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
3+
4+
if("${HDF5_INCLUDE_DIR}" STREQUAL "")
5+
message(STATUS "No HDF5 include directory specified")
6+
else()
7+
set(HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIR}" CACHE FILEPATH "HDF5 header files")
8+
endif()
9+
10+
if("${HDF5_LIBRARY_DIR}" STREQUAL "")
11+
message(STATUS "No HDF5 library directory specified")
12+
else()
13+
set(HDF5_LIBRARY_DIR "${HDF5_LIBRARY_DIR}" CACHE FILEPATH "HDF5 library files")
14+
endif()
15+
16+
if(HDF5_LIBRARY_DIR)
17+
# result of the HDF5 ctest package
18+
# Find zlib using cmake find_library. How should this be implemented?
19+
# FIND_LIBRARY(NAMES z libz libz_debug PATHS ... NO_DEFAULT_PATH)
20+
if("$ENV{CONDA_BUILD}" STREQUAL "")
21+
# result of the HDF5 ctest package
22+
if(WIN32)
23+
set(zlib_post lib)
24+
set(lib_ext lib)
25+
else()
26+
set(lib_ext a)
27+
endif()
28+
29+
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
30+
set(debug_postfix "_debug")
31+
endif()
32+
33+
set(HDF5_LIBRARIES
34+
"${HDF5_LIBRARY_DIR}/libhdf5_cpp${debug_postfix}.${lib_ext}"
35+
"${HDF5_LIBRARY_DIR}/libhdf5${debug_postfix}.${lib_ext}"
36+
"${HDF5_LIBRARY_DIR}/libz${zlib_post}${debug_postfix}.${lib_ext}"
37+
"${HDF5_LIBRARY_DIR}/libsz${debug_postfix}.${lib_ext}"
38+
"${HDF5_LIBRARY_DIR}/libaec${debug_postfix}.${lib_ext}"
39+
)
40+
41+
else()
42+
message(STATUS "Packaging hdf5 and zlib for conda distribution")
43+
44+
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
45+
# macOS
46+
set(zlib_post libz)
47+
set(lib_ext dylib)
48+
set(HDF5_LIBRARIES
49+
"${HDF5_LIBRARY_DIR}/libhdf5_cpp.${lib_ext}"
50+
"${HDF5_LIBRARY_DIR}/libhdf5.${lib_ext}"
51+
"${HDF5_LIBRARY_DIR}/${zlib_post}.${lib_ext}"
52+
)
53+
else()
54+
# linux and windows
55+
# Find HDF5 package
56+
find_package(HDF5 REQUIRED COMPONENTS C CXX)
57+
# Find ZLIB package
58+
find_package(ZLIB REQUIRED)
59+
# Include directories
60+
include_directories(${HDF5_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS})
61+
# Link libraries
62+
set(HDF5_LIBRARIES ${HDF5_LIBRARIES} ${ZLIB_LIBRARIES})
63+
message(STATUS "HDF5 libraries: ${HDF5_LIBRARIES}")
64+
endif()
65+
endif()
66+
endif()
67+
68+
if(NOT HDF5_INCLUDE_DIR OR NOT HDF5_LIBRARY_DIR)
69+
# First try to find it as a config.
70+
find_package(HDF5 CONFIG)
71+
if(HDF5_DIR)
72+
message(STATUS "HDF5: found config at '${HDF5_DIR}'.")
73+
set(HDF5_LIBRARIES hdf5_cpp-static)
74+
else()
75+
# If it failed, still try to find as a module.
76+
# E.g. on Ubuntu `libhdf5-dev` doesn't provie hdf5-config.cmake.
77+
# Will automatically fill HDF5_LIBRARIES and HDF5_INCLUDE_DIR.
78+
find_package(HDF5 COMPONENTS CXX)
79+
if(NOT HDF5_INCLUDE_DIR)
80+
message(
81+
FATAL_ERROR
82+
"HDF5_INCLUDE_DIR is not provided (current value: '${HDF5_INCLUDE_DIR}'). "
83+
"HDF5_LIBRARY_DIR is not provided (current value: '${HDF5_LIBRARY_DIR}'). "
84+
"Also could not find HDF5 package (neither module or config)."
85+
)
86+
endif()
87+
endif()
88+
endif()

conda/build.bat

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ cmake -G "Ninja" ^
2424
-D MPFR_LIBRARY_DIR:FILEPATH="%LIBRARY_PREFIX%\lib" ^
2525
-D COLLADA_SUPPORT=OFF ^
2626
-D HDF5_SUPPORT=ON ^
27-
-D HDF5_INCLUDE_DIR="%LIBRARY_PREFIX%\include" ^
28-
-D HDF5_LIBRARY_DIR="%LIBRARY_PREFIX%\lib" ^
2927
-D JSON_INCLUDE_DIR="%LIBRARY_PREFIX%\include" ^
3028
-D PYTHON_INCLUDE_DIR=%PREFIX%\include ^
3129
-D PYTHON_EXECUTABLE:FILEPATH=%PREFIX%\python.exe ^

conda/build.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ cmake ${CMAKE_ARGS} -G Ninja \
2626
-DOCC_INCLUDE_DIR=$PREFIX/include/opencascade \
2727
-DOCC_LIBRARY_DIR=$PREFIX/lib \
2828
-DHDF5_SUPPORT:BOOL=ON \
29-
-DHDF5_INCLUDE_DIR=$PREFIX/include \
30-
-DHDF5_LIBRARY_DIR=$PREFIX/lib \
3129
-DJSON_INCLUDE_DIR=$PREFIX/include \
3230
-DCGAL_INCLUDE_DIR=$PREFIX/include \
3331
-DLIBXML2_INCLUDE_DIR=$PREFIX/include/libxml2 \

0 commit comments

Comments
 (0)