Skip to content

Commit

Permalink
Merge pull request #154 from scivision/develop
Browse files Browse the repository at this point in the history
cmake:SC_ENABLE_MPI cache var like SC_HAVE_ZLIB for global scope
  • Loading branch information
cburstedde authored Jan 4, 2024
2 parents 2ad9bdd + 7629fbe commit 214217c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
32 changes: 14 additions & 18 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ find_package(Threads)

find_package(jansson CONFIG)
if(TARGET jansson::jansson)
set(SC_HAVE_JSON 1)
set(SC_HAVE_JSON 1 CACHE BOOL "JSON features enabled")
else()
set(SC_HAVE_JSON 0)
set(SC_HAVE_JSON 0 CACHE BOOL "JSON features disabled")
endif()
# --- set global compile environment

Expand All @@ -68,7 +68,8 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_LIBRARIES)

if(MPI_FOUND)
if(mpi)
set(SC_ENABLE_MPI 1) # need this temporary for sc_config.h, we unset below
set(CMAKE_REQUIRED_LIBRARIES MPI::MPI_C)
set(SC_CC \"${MPI_C_COMPILER}\")
set(SC_CPP ${MPI_C_COMPILER})
Expand All @@ -94,7 +95,7 @@ set(SC_CPPFLAGS \"\")

set(SC_LDFLAGS \"${MPI_C_LINK_FLAGS}\")

if(zlib)
if(SC_HAVE_ZLIB)
set(SC_LIBS \"${ZLIB_LIBRARIES}\ m\")
else()
set(SC_LIBS \"m\")
Expand All @@ -103,14 +104,13 @@ endif()
set(SC_ENABLE_PTHREAD ${CMAKE_USE_PTHREADS_INIT})
set(SC_ENABLE_MEMALIGN 1)

if(MPI_FOUND)
set(SC_ENABLE_MPI 1)
if(mpi)
check_symbol_exists(MPI_COMM_TYPE_SHARED mpi.h SC_ENABLE_MPICOMMSHARED)
# perform check to set SC_ENABLE_MPIIO
include(cmake/check_mpiio.cmake)
check_symbol_exists(MPI_Init_thread mpi.h SC_ENABLE_MPITHREAD)
check_symbol_exists(MPI_Win_allocate_shared mpi.h SC_ENABLE_MPIWINSHARED)
endif(MPI_FOUND)
endif()


check_symbol_exists(realloc stdlib.h SC_ENABLE_USE_REALLOC)
Expand Down Expand Up @@ -216,23 +216,19 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/sc_config.h.in ${PROJECT_BINARY_DIR}/in

# --- sanity check of MPI sc_config.h

unset(SC_ENABLE_MPI)
# so we don't override cache var check below that's propagated to parent projects

# check if libsc was configured properly
set(CMAKE_REQUIRED_FLAGS)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_LIBRARIES)
set(CMAKE_REQUIRED_DEFINITIONS)

# libsc and current project must both be compiled with/without MPI
check_symbol_exists(SC_ENABLE_MPI ${PROJECT_BINARY_DIR}/include/sc_config.h SC_has_mpi)
check_symbol_exists(SC_ENABLE_MPIIO ${PROJECT_BINARY_DIR}/include/sc_config.h SC_has_mpi_io)
check_symbol_exists(SC_ENABLE_MPI ${PROJECT_BINARY_DIR}/include/sc_config.h SC_ENABLE_MPI)
check_symbol_exists(SC_ENABLE_MPIIO ${PROJECT_BINARY_DIR}/include/sc_config.h SC_ENABLE_MPIIO)

if(SC_ENABLE_MPI)
# a sign the current project is using MPI
if(NOT (SC_has_mpi AND SC_has_mpi_io))
message(FATAL_ERROR "MPI used, but sc_config.h is not configured for MPI")
endif()
else()
if(SC_has_mpi OR SC_has_mpi_io)
message(FATAL_ERROR "MPI not used, but sc_config.h is configured for MPI")
endif()
if(mpi AND NOT (SC_ENABLE_MPI AND SC_ENABLE_MPIIO))
message(FATAL_ERROR "libsc MPI support was requested, but not configured in ${PROJECT_BINARY_DIR}/include/sc_config.h")
endif()
4 changes: 2 additions & 2 deletions cmake/pkgconf.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# --- generate pkg-config .pc
set(pc_req_private "")
if(mpi)
if(SC_ENABLE_MPI)
string(APPEND pc_req_private " ompi ompi-c zlib")
elseif(zlib)
elseif(SC_HAVE_ZLIB)
string(APPEND pc_req_private " zlib")
endif()

Expand Down

0 comments on commit 214217c

Please sign in to comment.