FindHDF5: Fix h5cc arg parsing to work with homebrew on Mac
This commit is contained in:
parent
e31084e657
commit
87c1cd9c51
|
@ -267,8 +267,21 @@ endfunction()
|
||||||
# return_value argument, the text output is stored to the output variable.
|
# return_value argument, the text output is stored to the output variable.
|
||||||
macro( _HDF5_invoke_compiler language output return_value version)
|
macro( _HDF5_invoke_compiler language output return_value version)
|
||||||
set(${version})
|
set(${version})
|
||||||
|
if(HDF5_USE_STATIC_LIBRARIES)
|
||||||
|
set(lib_type_args -noshlib)
|
||||||
|
else()
|
||||||
|
set(lib_type_args -shlib)
|
||||||
|
endif()
|
||||||
|
set(scratch_dir ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hdf5)
|
||||||
|
if("${language}" STREQUAL "C")
|
||||||
|
set(test_file ${scratch_dir}/cmake_hdf5_test.c)
|
||||||
|
elseif("${language}" STREQUAL "CXX")
|
||||||
|
set(test_file ${scratch_dir}/cmake_hdf5_test.cxx)
|
||||||
|
elseif("${language}" STREQUAL "Fortran")
|
||||||
|
set(test_file ${scratch_dir}/cmake_hdf5_test.f90)
|
||||||
|
endif()
|
||||||
exec_program( ${HDF5_${language}_COMPILER_EXECUTABLE}
|
exec_program( ${HDF5_${language}_COMPILER_EXECUTABLE}
|
||||||
ARGS -show
|
ARGS -show ${lib_type_args} ${test_file}
|
||||||
OUTPUT_VARIABLE ${output}
|
OUTPUT_VARIABLE ${output}
|
||||||
RETURN_VALUE ${return_value}
|
RETURN_VALUE ${return_value}
|
||||||
)
|
)
|
||||||
|
@ -302,44 +315,59 @@ macro( _HDF5_parse_compile_line
|
||||||
libraries_hl)
|
libraries_hl)
|
||||||
|
|
||||||
# Match the include paths
|
# Match the include paths
|
||||||
string( REGEX MATCHALL "-I([^\" ]+)" include_path_flags
|
set( RE " -I *([^\" ]+|\"[^\"]+\")")
|
||||||
"${${compile_line_var}}"
|
string( REGEX MATCHALL "${RE}" include_path_flags "${${compile_line_var}}")
|
||||||
)
|
foreach( IPATH IN LISTS include_path_flags )
|
||||||
foreach( IPATH ${include_path_flags} )
|
string( REGEX REPLACE "${RE}" "\\1" IPATH "${IPATH}" )
|
||||||
string( REGEX REPLACE "^-I" "" IPATH ${IPATH} )
|
|
||||||
string( REPLACE "//" "/" IPATH ${IPATH} )
|
|
||||||
list( APPEND ${include_paths} ${IPATH} )
|
list( APPEND ${include_paths} ${IPATH} )
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# Match the definitions
|
# Match the definitions
|
||||||
string( REGEX MATCHALL "-D[^ ]*" definition_flags "${${compile_line_var}}" )
|
set( RE " -D([^ ]*)")
|
||||||
foreach( DEF ${definition_flags} )
|
string( REGEX MATCHALL "${RE}" definition_flags "${${compile_line_var}}" )
|
||||||
|
foreach( DEF IN LISTS definition_flags )
|
||||||
|
string( REGEX REPLACE "${RE}" "\\1" DEF "${DEF}" )
|
||||||
list( APPEND ${definitions} ${DEF} )
|
list( APPEND ${definitions} ${DEF} )
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# Match the library paths
|
# Match the library paths
|
||||||
string( REGEX MATCHALL "-L([^\" ]+|\"[^\"]+\")" library_path_flags
|
set( RE " -L *([^\" ]+|\"[^\"]+\")")
|
||||||
"${${compile_line_var}}"
|
string( REGEX MATCHALL "${RE}" library_path_flags "${${compile_line_var}}")
|
||||||
)
|
foreach( LPATH IN LISTS library_path_flags )
|
||||||
|
string( REGEX REPLACE "${RE}" "\\1" LPATH "${LPATH}" )
|
||||||
foreach( LPATH ${library_path_flags} )
|
|
||||||
string( REGEX REPLACE "^-L" "" LPATH ${LPATH} )
|
|
||||||
string( REPLACE "//" "/" LPATH ${LPATH} )
|
|
||||||
list( APPEND ${library_paths} ${LPATH} )
|
list( APPEND ${library_paths} ${LPATH} )
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# now search for the library names specified in the compile line (match -l...)
|
# now search for the lib names specified in the compile line (match -l...)
|
||||||
# match only -l's preceded by a space or comma
|
# match only -l's preceded by a space or comma
|
||||||
# this is to exclude directory names like xxx-linux/
|
set( RE " -l *([^\" ]+|\"[^\"]+\")")
|
||||||
string( REGEX MATCHALL "[, ]-l([^\", ]+)" library_name_flags
|
string( REGEX MATCHALL "${RE}" library_name_flags "${${compile_line_var}}")
|
||||||
"${${compile_line_var}}" )
|
foreach( LNAME IN LISTS library_name_flags )
|
||||||
# strip the -l from all of the library flags and add to the search list
|
string( REGEX REPLACE "${RE}" "\\1" LNAME "${LNAME}" )
|
||||||
foreach( LIB ${library_name_flags} )
|
if(LNAME MATCHES ".*hl")
|
||||||
string( REGEX REPLACE "^[, ]-l" "" LIB ${LIB} )
|
list(APPEND ${libraries_hl} ${LNAME})
|
||||||
if(LIB MATCHES ".*_hl")
|
|
||||||
list(APPEND ${libraries_hl} ${LIB})
|
|
||||||
else()
|
else()
|
||||||
list(APPEND ${libraries} ${LIB})
|
list(APPEND ${libraries} ${LNAME})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# now search for full library paths with no flags
|
||||||
|
set( RE " ([^\" ]+|\"[^\"]+\")")
|
||||||
|
string( REGEX MATCHALL "${RE}" library_name_noflags "${${compile_line_var}}")
|
||||||
|
foreach( LIB IN LISTS library_name_noflags )
|
||||||
|
string( REGEX REPLACE "${RE}" "\\1" LIB "${LIB}" )
|
||||||
|
get_filename_component(LIB "${LIB}" ABSOLUTE)
|
||||||
|
if(NOT EXISTS ${LIB} OR IS_DIRECTORY ${LIB})
|
||||||
|
continue()
|
||||||
|
endif()
|
||||||
|
get_filename_component(LPATH ${LIB} DIRECTORY)
|
||||||
|
get_filename_component(LNAME ${LIB} NAME_WE)
|
||||||
|
string( REGEX REPLACE "^lib" "" LNAME ${LNAME} )
|
||||||
|
list( APPEND ${library_paths} ${LPATH} )
|
||||||
|
if(LNAME MATCHES ".*hl")
|
||||||
|
list(APPEND ${libraries_hl} ${LNAME})
|
||||||
|
else()
|
||||||
|
list(APPEND ${libraries} ${LNAME})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
@ -459,6 +487,14 @@ if(NOT HDF5_FOUND AND NOT HDF5_ROOT)
|
||||||
HDF5_${__lang}_HL_LIBRARY_NAMES
|
HDF5_${__lang}_HL_LIBRARY_NAMES
|
||||||
)
|
)
|
||||||
set(HDF5_${__lang}_LIBRARIES)
|
set(HDF5_${__lang}_LIBRARIES)
|
||||||
|
|
||||||
|
set(_HDF5_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||||
|
if(HDF5_USE_STATIC_LIBRARIES)
|
||||||
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||||
|
else()
|
||||||
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||||
|
endif()
|
||||||
|
|
||||||
foreach(L IN LISTS HDF5_${__lang}_LIBRARY_NAMES)
|
foreach(L IN LISTS HDF5_${__lang}_LIBRARY_NAMES)
|
||||||
find_library(HDF5_${__lang}_LIBRARY_${L} ${L} ${HDF5_${__lang}_LIBRARY_DIRS})
|
find_library(HDF5_${__lang}_LIBRARY_${L} ${L} ${HDF5_${__lang}_LIBRARY_DIRS})
|
||||||
if(HDF5_${__lang}_LIBRARY_${L})
|
if(HDF5_${__lang}_LIBRARY_${L})
|
||||||
|
@ -478,6 +514,9 @@ if(NOT HDF5_FOUND AND NOT HDF5_ROOT)
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_HDF5_CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||||
|
|
||||||
set(HDF5_${__lang}_FOUND True)
|
set(HDF5_${__lang}_FOUND True)
|
||||||
mark_as_advanced(HDF5_${__lang}_DEFINITIONS)
|
mark_as_advanced(HDF5_${__lang}_DEFINITIONS)
|
||||||
mark_as_advanced(HDF5_${__lang}_INCLUDE_DIRS)
|
mark_as_advanced(HDF5_${__lang}_INCLUDE_DIRS)
|
||||||
|
|
Loading…
Reference in New Issue