Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Ensure all libraries link against MPI if needed #2758

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libdap2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ SET(dap2_SOURCES constraints.c dapcvt.c dapodom.c daputil.c ncdaperr.c cdf.c cac

add_library(dap2 OBJECT ${dap2_SOURCES})

IF(STATUS_PARALLEL)
target_link_libraries(dap2 PUBLIC MPI::MPI_C)
ENDIF(STATUS_PARALLEL)

###
# Options related to the man page generation.
###
Expand Down
4 changes: 4 additions & 0 deletions libdap4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ SET(dap4_SOURCES d4curlfunctions.c d4fix.c d4data.c d4file.c d4parser.c d4meta.c

add_library(dap4 OBJECT ${dap4_SOURCES})

IF(STATUS_PARALLEL)
target_link_libraries(dap4 PUBLIC MPI::MPI_C)
ENDIF(STATUS_PARALLEL)

###
# Options related to the man page generation.
###
Expand Down
10 changes: 3 additions & 7 deletions libdispatch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@ IF(REGEDIT)
ENDIF(REGEDIT)

add_library(dispatch OBJECT ${libdispatch_SOURCES})
IF(MPI_C_INCLUDE_PATH)
target_include_directories(dispatch PUBLIC ${MPI_C_INCLUDE_PATH})
ENDIF(MPI_C_INCLUDE_PATH)

IF(MPI_C_LIBRARIES)
target_link_libraries(dispatch PUBLIC ${MPI_C_LIBRARIES})
ENDIF(MPI_C_LIBRARIES)
IF(STATUS_PARALLEL)
target_link_libraries(dispatch PUBLIC MPI::MPI_C)
ENDIF(STATUS_PARALLEL)

IF(ENABLE_NCZARR)
target_include_directories(dispatch PUBLIC ../libnczarr)
Expand Down
6 changes: 3 additions & 3 deletions libhdf5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ ENDIF()
# the netCDF library.
add_library(netcdfhdf5 OBJECT ${libnchdf5_SOURCES})

IF(MPI_C_INCLUDE_PATH)
target_include_directories(netcdfhdf5 PUBLIC ${MPI_C_INCLUDE_PATH})
ENDIF(MPI_C_INCLUDE_PATH)
IF(STATUS_PARALLEL)
target_link_libraries(netcdfhdf5 PUBLIC MPI::MPI_C)
ENDIF(STATUS_PARALLEL)

# Remember to package this file for CMake builds.
ADD_EXTRA_DIST(${libnchdf5_SOURCES} CMakeLists.txt)
7 changes: 4 additions & 3 deletions liblib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ ENDFOREACH()

ADD_LIBRARY(netcdf nc_initialize.c ${LARGS} )

IF(MPI_C_INCLUDE_PATH)
target_include_directories(netcdf PUBLIC ${MPI_C_INCLUDE_PATH})
ENDIF(MPI_C_INCLUDE_PATH)
IF(STATUS_PARALLEL)
# TODO: Make PUBLIC when other dependencies have PUBLIC/PRIVATE specified
target_link_libraries(netcdf MPI::MPI_C)
ENDIF(STATUS_PARALLEL)

IF(MOD_NETCDF_NAME)
SET_TARGET_PROPERTIES(netcdf PROPERTIES LIBRARY_OUTPUT_NAME ${NETCDF_LIB_NAME})
Expand Down
7 changes: 3 additions & 4 deletions libnczarr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ add_library(nczarr OBJECT ${libnczarr_SOURCES})

TARGET_INCLUDE_DIRECTORIES(nczarr PUBLIC ../libncpoco)

IF(MPI_C_INCLUDE_PATH)
target_include_directories(nczarr PUBLIC ${MPI_C_INCLUDE_PATH})
ENDIF(MPI_C_INCLUDE_PATH)
IF(STATUS_PARALLEL)
target_link_libraries(nczarr PUBLIC MPI::MPI_C)
ENDIF(STATUS_PARALLEL)

# Remember to package this file for CMake builds.
ADD_EXTRA_DIST(${libnczarr_SOURCES} CMakeLists.txt)

6 changes: 3 additions & 3 deletions libsrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ ENDIF(ENABLE_BYTERANGE)

add_library(netcdf3 OBJECT ${libsrc_SOURCES})

IF(MPI_C_INCLUDE_PATH)
target_include_directories(netcdf3 PUBLIC ${MPI_C_INCLUDE_PATH})
ENDIF(MPI_C_INCLUDE_PATH)
IF(STATUS_PARALLEL)
target_link_libraries(netcdf3 PUBLIC MPI::MPI_C)
ENDIF(STATUS_PARALLEL)

# The C API man page.

Expand Down
6 changes: 3 additions & 3 deletions libsrc4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ nc4internal.c nc4type.c nc4var.c ncfunc.c ncindex.c nc4cache.c)

add_library(netcdf4 OBJECT ${libsrc4_SOURCES})

IF(MPI_C_INCLUDE_PATH)
target_include_directories(netcdf4 PUBLIC ${MPI_C_INCLUDE_PATH})
ENDIF(MPI_C_INCLUDE_PATH)
IF(STATUS_PARALLEL)
target_link_libraries(netcdf4 PUBLIC MPI::MPI_C)
ENDIF(STATUS_PARALLEL)

# Files for make dist
FILE(GLOB libsrc4_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.sh)
Expand Down
5 changes: 5 additions & 0 deletions netCDFConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ set(netCDF_HAS_DAP4 @HAS_DAP4@)
set(netCDF_HAS_DISKLESS @HAS_DISKLESS@)
set(netCDF_HAS_MMAP @HAS_MMAP@)
set(netCDF_HAS_JNA @HAS_JNA@)

if (@HAS_PARALLEL@)
include(CMakeFindDependencyMacro)
find_dependency(MPI @MPI_C_VERSION@ EXACT)
endif()
4 changes: 4 additions & 0 deletions oc2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ SET(oc_SOURCES oc.c daplex.c dapparse.c dapy.c occompile.c occurlfunctions.c ocd

add_library(oc2 OBJECT ${oc_SOURCES})

IF(STATUS_PARALLEL)
target_link_libraries(oc2 PUBLIC MPI::MPI_C)
ENDIF(STATUS_PARALLEL)

# Apparently fails under cmake
#set(ocprint_FILES ocprint.c )
#ADD_EXECUTABLE(ocprint ${ocprint_FILES})
Expand Down
6 changes: 5 additions & 1 deletion plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ MACRO(buildplugin TARGET TARGETLIB)
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES RUNTIME_OUTPUT_NAME ${MANGLELIB})
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES PREFIX "") # Critical that this be set to ""
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES SUFFIX ".${PLUGINEXT}")
TARGET_LINK_LIBRARIES(${TARGET} ${ALL_TLL_LIBS};${ARGN})
TARGET_LINK_LIBRARIES(${TARGET} PUBLIC ${ALL_TLL_LIBS};${ARGN})
IF(MSVC)
target_compile_options(${TARGET} PRIVATE /Zi)
# Tell linker to include symbol data
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF")
# Set file name & location
set_target_properties(${TARGET} PROPERTIES COMPILE_PDB_NAME ${TARGET} COMPILE_PDB_OUTPUT_DIR ${CMAKE_BINARY_DIR})
ENDIF()

IF(STATUS_PARALLEL)
target_link_libraries(${TARGET} PUBLIC MPI::MPI_C)
ENDIF(STATUS_PARALLEL)
ENDMACRO()

buildplugin(h5misc "h5misc")
Expand Down