Skip to content
Snippets Groups Projects
Commit 62b32dce authored by Mathieu Westphal's avatar Mathieu Westphal
Browse files

CMake: Add proper support for optional linking to netcdf and eccodes

parent ff8e438e
No related branches found
No related tags found
2 merge requests!137CMake: Fix cdi-config.cmake for CMake compatibility,!134CMake: Improvements from kitware
...@@ -17,6 +17,7 @@ if(${CDI_PTHREAD}) ...@@ -17,6 +17,7 @@ if(${CDI_PTHREAD})
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
set_target_properties(Threads::Threads PROPERTIES THREADS_PREFER_PTHREAD_FLAG TRUE) set_target_properties(Threads::Threads PROPERTIES THREADS_PREFER_PTHREAD_FLAG TRUE)
list(APPEND cdi_compile_defs HAVE_PTHREAD=1) list(APPEND cdi_compile_defs HAVE_PTHREAD=1)
list(APPEND cdi_linked_libs pthread)
endif() endif()
# enable default internal libs # enable default internal libs
...@@ -53,6 +54,7 @@ if(${CDI_ECCODES} OR eccodes_ROOT) ...@@ -53,6 +54,7 @@ if(${CDI_ECCODES} OR eccodes_ROOT)
if (${eccodes_FOUND}) if (${eccodes_FOUND})
list(APPEND cdi_compile_defs HAVE_LIBGRIB_API=${eccodes_FOUND}) list(APPEND cdi_compile_defs HAVE_LIBGRIB_API=${eccodes_FOUND})
message(VERBOSE "added compile definition HAVE_LIBGRIB_API=${eccodes_FOUND}") message(VERBOSE "added compile definition HAVE_LIBGRIB_API=${eccodes_FOUND}")
list(APPEND cdi_linked_libs eccodes)
else() else()
message(WARNING "eccodes not found, compiling without eccodes") message(WARNING "eccodes not found, compiling without eccodes")
endif () endif ()
...@@ -70,6 +72,7 @@ if(${CDI_NETCDF} OR netCDF_ROOT ) ...@@ -70,6 +72,7 @@ if(${CDI_NETCDF} OR netCDF_ROOT )
HAVE_LIBGRIB_API=${netCDF_FOUND} HAVE_LIBGRIB_API=${netCDF_FOUND}
HAVE_LIBGRIB=${netCDF_FOUND} HAVE_LIBGRIB=${netCDF_FOUND}
) )
list(APPEND cdi_linked_libs netCDF::netcdf)
else() else()
message(WARNING "netcdf target not found, compiling without netcdf") message(WARNING "netcdf target not found, compiling without netcdf")
endif () endif ()
......
...@@ -7,6 +7,6 @@ target_include_directories(cdi PRIVATE ...@@ -7,6 +7,6 @@ target_include_directories(cdi PRIVATE
$<INSTALL_INTERFACE:include $<INSTALL_INTERFACE:include
) )
target_link_libraries(cdi PRIVATE cdilib netCDF::netcdf pthread) target_link_libraries(cdi PRIVATE cdilib ${cdi_linked_libs})
target_include_directories(cdi PRIVATE "${PROJECT_BINARY_DIR}/src/config.h") target_include_directories(cdi PRIVATE "${PROJECT_BINARY_DIR}/src/config.h")
target_compile_definitions(cdi PRIVATE ${cdi_netcdf_definitions}) target_compile_definitions(cdi PRIVATE ${cdi_netcdf_definitions})
...@@ -199,7 +199,7 @@ add_library(cdilib ...@@ -199,7 +199,7 @@ add_library(cdilib
) )
target_include_directories(cdilib PRIVATE "${PROJECT_BINARY_DIR}/src/config.h") target_include_directories(cdilib PRIVATE "${PROJECT_BINARY_DIR}/src/config.h")
target_link_libraries(cdilib eccodes netCDF::netcdf) target_link_libraries(cdilib ${cdi_linked_libs})
target_compile_definitions(cdilib PRIVATE PACKAGE_NAME="${PROJECT_NAME}" VERSION="${CMAKE_PROJECT_VERSION}" ${cdi_compile_defs}) target_compile_definitions(cdilib PRIVATE PACKAGE_NAME="${PROJECT_NAME}" VERSION="${CMAKE_PROJECT_VERSION}" ${cdi_compile_defs})
add_library(cdilib::cdilib ALIAS cdilib) add_library(cdilib::cdilib ALIAS cdilib)
......
...@@ -31,11 +31,11 @@ list(APPEND test_lib_src ...@@ -31,11 +31,11 @@ list(APPEND test_lib_src
add_library(test_lib ${test_lib_src}) add_library(test_lib ${test_lib_src})
target_include_directories(test_lib PRIVATE ../src/) target_include_directories(test_lib PRIVATE ../src/)
target_link_libraries(test_lib PRIVATE cdilib eccodes) target_link_libraries(test_lib PRIVATE cdilib ${cdi_linked_libs})
foreach(target ${current_targets}) foreach(target ${current_targets})
target_include_directories(${target} PRIVATE ../src/) target_include_directories(${target} PRIVATE ../src/)
target_link_libraries(${target} PRIVATE cdilib test_lib ${netCDF_LIBRARIES} ) target_link_libraries(${target} PRIVATE cdilib test_lib ${cdi_linked_libs})
add_test(NAME ${target} COMMAND ${target}) add_test(NAME ${target} COMMAND ${target})
if(labels_${target}) if(labels_${target})
set_property(TEST ${target} PROPERTY LABELS labels_${target}) set_property(TEST ${target} PROPERTY LABELS labels_${target})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment