Skip to content

Commit 30cb237

Browse files
Fixed some strange behavior in FindHDF4.cmake
1 parent 23100e6 commit 30cb237

3 files changed

Lines changed: 69 additions & 65 deletions

File tree

CMakeLists.txt

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ set (NXLTVERSINFO "${NEXUS_VERSION_MAJOR}:${NEXUS_VERSION_MINOR}:${NEXUS_VERSION
8282
#-----------------------------------------------------------------------------
8383
# define command line options by which the user can configure the build
8484
#-----------------------------------------------------------------------------
85-
option(ENABLE_HDF5 "Build with HDF5 support" ON)
86-
option(ENABLE_HDF4 "Build with HDF4 support" OFF)
87-
option(ENABLE_MXML "Build with XML support" OFF)
88-
option(ENABLE_CONTRIB "Build the user contributions" OFF)
85+
option(ENABLE_HDF5 "Build with HDF5 support" ON)
86+
option(ENABLE_HDF4 "Build with HDF4 support" OFF)
87+
option(ENABLE_MXML "Build with XML support" OFF)
88+
option(ENABLE_CONTRIB "Build the user contributions" OFF)
8989
option(ENABLE_FORTRAN90 "Build the Fortran 90 bindings" OFF)
9090
option(ENABLE_FORTRAN77 "Build the Fortran 77 bindings" OFF)
9191
option(ENABLE_JAVA "Build Java bindings" OFF)
@@ -125,6 +125,9 @@ include(FindPkgConfig)
125125
#------------------------------------------------------------------------------
126126
set(NAPI_LINK_LIBS)
127127

128+
#------------------------------------------------------------------------------
129+
# if requested by the user - check for MXMLlibraries
130+
#------------------------------------------------------------------------------
128131
if(ENABLE_MXML)
129132
include(FindMXML)
130133
# the required libraries are appended to
@@ -135,11 +138,14 @@ else()
135138
message(STATUS "Build without MXML support!")
136139
endif()
137140

141+
#------------------------------------------------------------------------------
142+
# if requested by the user - check for HDF4 libraries
143+
#------------------------------------------------------------------------------
138144
if(ENABLE_HDF4)
139145
include(FindHDF4)
140146

141-
message(STATUS "HDF4 library found in: ${HDF4_LIBRARY_DIR}")
142-
message(STATUS "HDF4 headers found in: ${HDF4_INCLUDE_DIR}")
147+
message(STATUS "HDF4 library found in: ${HDF4_LIBRARY_DIRS}")
148+
message(STATUS "HDF4 headers found in: ${HDF4_INCLUDE_DIRS}")
143149

144150
# the required libraries are appended to
145151
# NAPI_LINK_LIBS by this module
@@ -148,6 +154,9 @@ else()
148154
message(STATUS "Build without HDF4 support!")
149155
endif()
150156

157+
#------------------------------------------------------------------------------
158+
# if requested by the user - check for HDF5 libraries
159+
#------------------------------------------------------------------------------
151160
if(ENABLE_HDF5)
152161

153162
message (STATUS "${HDF5_COMPONENTS}")
@@ -172,6 +181,11 @@ else()
172181
message(STATUS "Build without HDF5 support!")
173182
endif()
174183

184+
message(STATUS "Link with: ${NAPI_LINK_LIBS}")
185+
186+
#------------------------------------------------------------------------------
187+
# enable FORTRAN bindings if requested by the user
188+
#------------------------------------------------------------------------------
175189
if(ENABLE_FORTRAN90 OR ENABLE_FORTRAN77)
176190
enable_language(Fortran)
177191
endif()
@@ -222,11 +236,11 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NX_CFLAGS}")
222236
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NX_CFLAGS}")
223237

224238
# Recurse into the subdirectories.
225-
add_subdirectory (include)
226-
add_subdirectory (src)
227-
add_subdirectory (test)
228-
add_subdirectory (bindings)
229-
add_subdirectory (scripts)
239+
add_subdirectory (include) #install header files
240+
add_subdirectory (src) #build the binaries
241+
add_subdirectory (test) #build the tests
242+
add_subdirectory (bindings) #build the language bindings
243+
add_subdirectory (scripts) #install pkg-config files
230244

231245
#on user request utility applications will be built
232246
if(ENABLE_APPS)

cmake_include/FindHDF4.cmake

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,45 +25,45 @@
2525
#
2626
#=============================================================================
2727

28-
<<<<<<< HEAD
29-
find_library(HDF4_LIBRARIES NAMES df mfhdf PATH_SUFFIXES hdf)
30-
find_library(HDF4_DF_LIBRARY NAMES df PATH_SUFFIXES hdf)
31-
find_library(HDF4_MFHDF_LIBRARY NAMES mfhdf PATH_SUFFIXES hdf)
32-
message(STATUS "DF library found: ${HDF4_DF_LIBRARY}")
33-
message(STATUS "MFHDF library found: ${HDF4_MFHDF_LIBRARY}")
34-
35-
message(STATUS "HDF4 libraries: ${HDF4_LIBRARIES}")
36-
=======
37-
set(HDF4_LIBRARIES df mfhdf)
3828

3929
#------------------------------------------------------------------------------
4030
# find the runtime binaries of the HDF4 library
4131
#------------------------------------------------------------------------------
42-
find_library(HDF4_LIBRARIES NAMES df mfhdf
32+
find_library(HDF4_DF_LIBRARY NAMES df hdf
4333
HINTS ENV HDF4_ROOT
4434
PATH_SUFFIXES hdf)
35+
36+
37+
if(HDF4_DF_LIBRARY MATCHES HDF4_DF_LIBRARY-NOTFOUND)
38+
message(FATAL_ERROR "Could not find HDF4 DF library!")
39+
else()
40+
get_filename_component(HDF4_LIBRARY_DIRS ${HDF4_DF_LIBRARY} PATH)
41+
message(STATUS "Found HDF4 DF library: ${HDF4_DF_LIBRARY}")
42+
message(STATUS "HDF4 libary path: ${HDF4_LIBRARY_DIRS}")
43+
endif()
44+
45+
find_library(HDF4_MFHDF_LIBRARY NAMES mfhdf
46+
HINTS ENV HDF4_ROOT
47+
PATH_SUFFIXES hdf)
4548

46-
find_library(_HDF4_DF_LIBRARY NAMES df hdf
47-
HINTS ENV
48-
HDF4_ROOT PATH_SUFFIXES hdf)
49-
>>>>>>> 336bba8dd4b92aa97c0684b1285f94d575b23f8a
49+
if(HDF4_MFHDF_LIBRARY MATCHES HDF4_MFHDF_LIBRARY-NOTFOUND)
50+
message(FATAL_ERROR "Could not find HDF5 MFHDF library!")
51+
else()
52+
message(STATUS "Found HDF4 MFHDF library: ${HDF4_MFHDF_LIBRARY}")
53+
endif()
5054

51-
#if the binaries have been found their parent directory has to be
52-
#extracted from the total path
53-
get_filename_component(HDF4_LIBRARY_DIRS ${_HDF4_DF_LIBRARY} PATH)
5455

5556
#------------------------------------------------------------------------------
5657
# find the HDF4 header file
5758
#------------------------------------------------------------------------------
58-
find_path (HDF4_INCLUDE_DIR mfhdf.h HINTS ENV HDF4_ROOT PATH_SUFFIXES hdf)
59-
60-
include ( FindPackageHandleStandardArgs )
61-
find_package_handle_standard_args( HDF4 DEFAULT_MSG HDF4_LIBRARIES HDF4_INCLUDE_DIR )
62-
63-
if(NOT HDF4_FOUND)
64-
#the user has explicitely requested HDF4 support but the required libraries
65-
#could not be found
66-
message(FATAL_ERROR "User requested HDF4 not found!")
59+
find_path(HDF4_INCLUDE_DIRS mfhdf.h
60+
HINTS ENV HDF4_ROOT
61+
PATH_SUFFIXES hdf)
62+
63+
if(HDF4_INCLUDE_DIRS MATCHES HDF4_INCLUDE_DIRS-NOTFOUND)
64+
message(FATAL_ERROR "Could not find HDF4 header files")
65+
else()
66+
message(STATUS "Found HDF4 header files in: ${HDF4_INCLUDE_DIRS}")
6767
endif()
6868

6969
#------------------------------------------------------------------------------
@@ -74,6 +74,6 @@ find_package(JPEG REQUIRED)
7474
#------------------------------------------------------------------------------
7575
# add libraries to the link list for NAPI
7676
#------------------------------------------------------------------------------
77-
list(APPEND NAPI_LINK_LIBS ${_HDF4_DF_LIBRARY} mfhdf jpeg)
78-
include_directories ( SYSTEM ${HDF4_INCLUDE_DIR} )
77+
list(APPEND NAPI_LINK_LIBS ${HDF4_DF_LIBRARY} ${HDF4_MFHDF_LIBRARY} jpeg)
78+
include_directories ( SYSTEM ${HDF4_INCLUDE_DIRS} )
7979
link_directories(${HDF4_LIBRARY_DIRS})

test/CMakeLists.txt

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,16 @@ link_directories(${HDF5_LIBRARY_DIRS}
4242
#------------------------------------------------------------------------------
4343
if(WITH_HDF5)
4444
add_executable(napi_test_hdf5 napi_test.c)
45-
target_link_libraries(napi_test_hdf5 NeXus_Shared_Library
46-
${NAPI_LINK_LIBS})
45+
target_link_libraries(napi_test_hdf5 NeXus_Shared_Library)
4746
add_test(NAME "NAPI-C-HDF5-test" COMMAND napi_test_hdf5)
4847
add_executable(napi_attra_test_hdf5 napi_attra_test.c)
49-
target_link_libraries(napi_attra_test_hdf5 NeXus_Shared_Library
50-
${NAPI_LINK_LIBS})
48+
target_link_libraries(napi_attra_test_hdf5 NeXus_Shared_Library)
5149
add_test(NAME "NAPI-C-HDF5-attra-test" COMMAND napi_attra_test_hdf5)
5250
endif()
5351

5452
if(WITH_HDF4)
5553
add_executable(napi_test_hdf4 napi_test.c)
56-
target_link_libraries(napi_test_hdf4 NeXus_Shared_Library
57-
${NAPI_LINK_LIBS})
54+
target_link_libraries(napi_test_hdf4 NeXus_Shared_Library)
5855
add_test(NAME "NAPI-C-HDF4-test"
5956
COMMAND napi_test_hdf4)
6057
add_executable(napi_attra_test_hdf4 napi_attra_test.c)
@@ -65,18 +62,17 @@ endif()
6562

6663
if(WITH_MXML)
6764
add_executable(napi_test-xml napi_test.c)
68-
target_link_libraries(napi_test-xml NeXus_Shared_Library
69-
${NAPI_LINK_LIBS})
65+
target_link_libraries(napi_test-xml NeXus_Shared_Library)
7066
add_test(NAME "NAPI-C-MXML-test"
7167
COMMAND napi_test-xml)
68+
7269
add_executable(napi_test-xml-table napi_test.c)
73-
target_link_libraries(napi_test-xml-table NeXus_Shared_Library
74-
${NAPI_LINK_LIBS})
70+
target_link_libraries(napi_test-xml-table NeXus_Shared_Library)
7571
add_test(NAME "NAPI-C-MXML-TABLE-test"
7672
COMMAND napi_test-xml-table)
73+
7774
add_executable(napi_attra_test_xml napi_attra_test.c)
78-
target_link_libraries(napi_attra_test_xml NeXus_Shared_Library
79-
${NAPI_LINK_LIBS})
75+
target_link_libraries(napi_attra_test_xml NeXus_Shared_Library)
8076
add_test(NAME "NAPI-C-MXML-attra-test" COMMAND napi_attra_test_xml)
8177
set_tests_properties("NAPI-C-MXML-attra-test" PROPERTIES WILL_FAIL TRUE)
8278
endif()
@@ -85,16 +81,15 @@ endif()
8581
# (most probably a) regression test
8682
#------------------------------------------------------------------------------
8783
add_executable(leak_test1 leak_test1.c)
88-
target_link_libraries(leak_test1 NeXus_Shared_Library ${NAPI_LINK_LIBS})
84+
target_link_libraries(leak_test1 NeXus_Shared_Library)
8985
add_test(NAME "NAPI-C-leak-test-1"
9086
COMMAND leak_test1)
9187

9288
#------------------------------------------------------------------------------
9389
# Add test for unlimited dimensions
9490
#------------------------------------------------------------------------------
9591
add_executable(test_nxunlimited test_nxunlimited.c)
96-
target_link_libraries(test_nxunlimited NeXus_Shared_Library
97-
${NAPI_LINK_LIBS})
92+
target_link_libraries(test_nxunlimited NeXus_Shared_Library)
9893
add_test(NAME "NAPI-C-test-nxunlimited"
9994
COMMAND test_nxunlimited)
10095

@@ -108,22 +103,19 @@ if(ENABLE_CXX)
108103

109104
if(WITH_HDF5)
110105
add_executable(napi_test_cpp-hdf5 napi_test_cpp.cxx)
111-
target_link_libraries(napi_test_cpp-hdf5 NeXus_CPP_Shared_Library
112-
${NAPI_LINK_LIBS})
106+
target_link_libraries(napi_test_cpp-hdf5 NeXus_CPP_Shared_Library)
113107
add_test(NAME "NAPI-C++-HDF5-test" COMMAND napi_test_cpp-hdf5)
114108
endif()
115109

116110
if(WITH_HDF4)
117111
add_executable(napi_test_cpp-hdf4 napi_test_cpp.cxx)
118-
target_link_libraries(napi_test_cpp-hdf4 NeXus_CPP_Shared_Library
119-
${NAPI_LINK_LIBS})
112+
target_link_libraries(napi_test_cpp-hdf4 NeXus_CPP_Shared_Library)
120113
add_test(NAME "NAPI-C++-HDF4-test" COMMAND napi_test_cpp-hdf4)
121114
endif()
122115

123116
if(WITH_MXML)
124117
add_executable(napi_test_cpp-xml napi_test_cpp.cxx)
125-
target_link_libraries(napi_test_cpp-xml NeXus_CPP_Shared_Library
126-
${NAPI_LINK_LIBS})
118+
target_link_libraries(napi_test_cpp-xml NeXus_CPP_Shared_Library)
127119
add_test(NAME "NAPI-C++-MXML-test" COMMAND napi_test_cpp-xml)
128120

129121
# add_executable(napi_test_cpp-xml-table napi_test_cpp.cxx)
@@ -137,14 +129,12 @@ if(ENABLE_CXX)
137129
# build leak tests
138130
#--------------------------------------------------------------------------
139131
add_executable(leak_test2 leak_test2.cxx)
140-
target_link_libraries(leak_test2 NeXus_CPP_Shared_Library
141-
${NAPI_LINK_LIBS})
132+
target_link_libraries(leak_test2 NeXus_CPP_Shared_Library)
142133
add_test(NAME "NAPI-C++-leak-test-2"
143134
COMMAND leak_test2)
144135

145136
add_executable(leak_test3 leak_test3.cxx)
146-
target_link_libraries(leak_test3 NeXus_CPP_Shared_Library
147-
${NAPI_LINK_LIBS})
137+
target_link_libraries(leak_test3 NeXus_CPP_Shared_Library)
148138
add_test(NAME "NAPI-C++-leak-test-3"
149139
COMMAND leak_test3)
150140
endif()

0 commit comments

Comments
 (0)