Skip to content

Commit

Permalink
Merge branch 'develop' into cmake-enable-valgrind
Browse files Browse the repository at this point in the history
  • Loading branch information
cburstedde committed Oct 27, 2023
2 parents 5d98f44 + 8a1397b commit a9d464d
Show file tree
Hide file tree
Showing 20 changed files with 1,332 additions and 211 deletions.
26 changes: 13 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
cmake_minimum_required(VERSION 3.14...3.25)
cmake_minimum_required(VERSION 3.14...3.28)

include(cmake/git.cmake)

include(cmake/init_build_type.cmake)

project(SC
LANGUAGES C
HOMEPAGE_URL https://www.p4est.org/
Expand All @@ -10,12 +12,7 @@ VERSION ${PROJECT_VERSION})

enable_testing()

include(cmake/init_build_type.cmake)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(debug_build ON)
else()
set(debug_build OFF)
endif()
set(CMAKE_C_STANDARD 99)

include(cmake/options.cmake)
message(STATUS "libsc ${PROJECT_VERSION} "
Expand All @@ -38,7 +35,6 @@ target_include_directories(libb64 PRIVATE libb64)

# --- sc
add_library(sc $<TARGET_OBJECTS:iniparser> $<TARGET_OBJECTS:libb64>)
target_compile_features(sc PRIVATE c_std_99)
set_property(TARGET sc PROPERTY EXPORT_NAME SC)
set_property(TARGET sc PROPERTY VERSION ${PROJECT_VERSION})
target_include_directories(sc
Expand All @@ -51,6 +47,7 @@ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
target_link_libraries(sc PUBLIC
$<$<BOOL:${SC_ENABLE_MPI}>:MPI::MPI_C>
$<$<BOOL:${SC_HAVE_ZLIB}>:ZLIB::ZLIB>
$<$<BOOL:${SC_HAVE_JSON}>:jansson::jansson>
$<$<BOOL:${SC_NEED_M}>:m>
)

Expand All @@ -59,7 +56,7 @@ add_library(SC::SC INTERFACE IMPORTED GLOBAL)
target_link_libraries(SC::SC INTERFACE sc)

install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/ ${PROJECT_BINARY_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
TYPE INCLUDE
FILES_MATCHING PATTERN "*.h"
)

Expand All @@ -70,16 +67,18 @@ install(TARGETS sc
RUNTIME DESTINATION bin)

add_subdirectory(src)
add_subdirectory(example)

if(BUILD_TESTING)

if(TEST_WITH_VALGRIND)
include(cmake/valgrind.cmake)
else()
set(VALGRIND_COMMAND)
endif()

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.22)
add_subdirectory(example)
endif()

add_subdirectory(test)
endif(BUILD_TESTING)

Expand All @@ -94,9 +93,10 @@ include(cmake/install.cmake)

include(FeatureSummary)

add_feature_info(MPI mpi "MPI features of libsc")
add_feature_info(MPI SC_ENABLE_MPI "MPI features of libsc")
add_feature_info(OpenMP openmp "OpenMP features of libsc")
add_feature_info(ZLIB zlib "ZLIB features of libsc")
add_feature_info(ZLIB SC_HAVE_ZLIB "ZLIB features of libsc")
add_feature_info(shared BUILD_SHARED_LIBS "shared libsc library")
add_feature_info(json SC_HAVE_JSON "JSON features of libsc")

feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)
28 changes: 13 additions & 15 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is the `README` file for `libsc`.

The SC Library provides support for parallel scientific applications.

Copyright (C) 2010 The University of Texas System
Copyright (C) 2010 The University of Texas System
Additional copyright (C) 2011 individual authors

`libsc` is written by Carsten Burstedde, Lucas C. Wilcox, Tobin Isaac, and
Expand Down Expand Up @@ -67,11 +67,18 @@ For faster builds that work on Windows as well as MacOS and Linux, and
that are easily usable from other CMake projects, libsc can be built directly,
or used via FetchContent or ExternalProject from other CMake projects.

MPI and OpenMP are enabled by default, and the default build configuration is Release:
MPI and OpenMP are enabled by default, and the default build configuration is RelWithDebInfo:

cmake -B build
cmake --build build --parallel

To enable JSON via jansson, first install
[jansson CMake project](https://github.com/akheron/jansson), then specify path where you
installed jansson to CMake, say ~/local:

cmake -B build -Djansson_ROOT=~/local
cmake --build build --parallel

To disable MPI:

cmake -B build -Dmpi=no
Expand All @@ -86,8 +93,7 @@ To compile with debug options:

Optionally, run self-tests:

cd build
ctest
ctest --test-dir build

Optionally, install `libsc` like:

Expand All @@ -96,17 +102,9 @@ Optionally, install `libsc` like:

The optional examples can be built and tested like:

cd example
cmake -B build
cmake --build build
cd build
ctest

Here are a few compilers known to work with `libsc` via CMake:

* GCC or Clang (Linux, MacOS, Windows)
* Intel Classic `icc` (Linux, MacOS)
* Intel NextGen LLVM `icx` (Linux, MacOS, Windows).
cmake -S example -B example/build -DSC_ROOT=~/local
cmake --build example/build
ctest --test-dir example/build

#### Distribution packages

Expand Down
21 changes: 11 additions & 10 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@ endif()
if(zlib)
message(STATUS "Using builtin zlib")
include(${CMAKE_CURRENT_LIST_DIR}/zlib.cmake)
set(SC_HAVE_ZLIB true)
else()
find_package(ZLIB)
if(ZLIB_FOUND)
message(STATUS "Using system zlib : ${ZLIB_VERSION_STRING}")
set(SC_HAVE_ZLIB true)
else()
message(STATUS "Zlib disabled (not found). Consider using cmake \"-Dzlib=ON\" to turn on builtin zlib.")
set(SC_HAVE_ZLIB false)
endif()
endif()
if(TARGET ZLIB::ZLIB)
set(SC_HAVE_ZLIB 1)
else()
set(SC_HAVE_ZLIB 0)
endif()

find_package(Threads)

include(${CMAKE_CURRENT_LIST_DIR}/jansson.cmake)

find_package(jansson CONFIG)
if(TARGET jansson::jansson)
set(SC_HAVE_JSON 1)
else()
set(SC_HAVE_JSON 0)
endif()
# --- set global compile environment

# Build all targets with -fPIC so that libsc itself can be linked as a
Expand Down Expand Up @@ -174,11 +180,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
endif()
endif()

if(zlib)
set(CMAKE_REQUIRED_LIBRARIES ZLIB::ZLIB)
set(SC_HAVE_ZLIB true)
endif()

check_type_size(int SC_SIZEOF_INT BUILTIN_TYPES_ONLY)
check_type_size("unsigned int" SC_SIZEOF_UNSIGNED_INT BUILTIN_TYPES_ONLY)
check_type_size(long SC_SIZEOF_LONG BUILTIN_TYPES_ONLY)
Expand Down
4 changes: 4 additions & 0 deletions cmake/config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ if(SC_ENABLE_MPI)
find_dependency(MPI COMPONENTS C)
endif()

if(SC_HAVE_JSON)
find_dependency(jansson CONFIG)
endif()

check_required_components(@PROJECT_NAME@)
17 changes: 11 additions & 6 deletions cmake/init_build_type.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# set default build type to "RelWithDebInfo"
set(default_build_type "RelWithDebInfo")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
set(sc_default_build_type "RelWithDebInfo")

if(NOT CMAKE_BUILD_TYPE)
if(DEFINED ENV{CMAKE_BUILD_TYPE})
set(CMAKE_BUILD_TYPE $ENV{CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build." FORCE)
endif()
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "${sc_default_build_type}" CACHE STRING "Choose the type of build." FORCE)
message(STATUS "Set build type to '${CMAKE_BUILD_TYPE}' as none was specified.")
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
Expand Down
42 changes: 0 additions & 42 deletions cmake/jansson.cmake

This file was deleted.

9 changes: 3 additions & 6 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/local" CACHE PATH "Install top-level directory" FORCE)
endif()

# Rpath options necessary for shared library install to work correctly in user projects
set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_FULL_LIBDIR})
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH true)
set_property(DIRECTORY PROPERTY EP_UPDATE_DISCONNECTED true)

# Necessary for shared library with Visual Studio / Windows oneAPI
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS true)

# --- auto-ignore build directory
if(NOT EXISTS ${PROJECT_BINARY_DIR}/.gitignore)
file(WRITE ${PROJECT_BINARY_DIR}/.gitignore "*")
if(NOT PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
file(GENERATE OUTPUT .gitignore CONTENT "*")
endif()
48 changes: 15 additions & 33 deletions cmake/zlib.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# build Zlib to ensure compatibility.
# We use Zlib 2.x for speed and robustness.
include(GNUInstallDirs)
include(ExternalProject)

# option to chose if we want to download zlib sources, or use a local archive file
option(LIBSC_USE_ZLIB_ARCHIVE "Turn ON if you want to use a local archive of zlib sources (default: OFF)." OFF)

# select which version of zlib will be build
if (NOT DEFINED LIBS_BUILD_ZLIB_VERSION)
set(LIBSC_BUILD_ZLIB_VERSION 2.0.6)
endif()

# default zlib source archive
if (NOT DEFINED LIBSC_BUILD_ZLIB_ARCHIVE_FILE)
set(LIBSC_BUILD_ZLIB_ARCHIVE_FILE https://github.com/zlib-ng/zlib-ng/archive/refs/tags/${LIBSC_BUILD_ZLIB_VERSION}.tar.gz CACHE STRING "zlib source archive (URL or local filepath).")
if (NOT DEFINED SC_BUILD_ZLIB_ARCHIVE_FILE)
if (NOT DEFINED SC_BUILD_ZLIB_VERSION)
set(SC_BUILD_ZLIB_VERSION 2.1.3)
endif()
set(SC_BUILD_ZLIB_ARCHIVE_FILE https://github.com/zlib-ng/zlib-ng/archive/refs/tags/${SC_BUILD_ZLIB_VERSION}.tar.gz CACHE STRING "zlib source archive (URL or local filepath).")
endif()

set(ZLIB_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include)
Expand All @@ -38,31 +31,20 @@ set(zlib_cmake_args
-DCMAKE_BUILD_TYPE=Release
-DZLIB_COMPAT:BOOL=on
-DZLIB_ENABLE_TESTS:BOOL=off
-DZLIBNG_ENABLE_TESTS:BOOL=off
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
)

if(LIBSC_USE_ZLIB_ARCHIVE)
ExternalProject_Add(ZLIB
URL ${LIBSC_BUILD_ZLIB_ARCHIVE_FILE}
CMAKE_ARGS ${zlib_cmake_args}
BUILD_BYPRODUCTS ${ZLIB_LIBRARIES}
TLS_VERIFY true
CONFIGURE_HANDLED_BY_BUILD ON
INACTIVITY_TIMEOUT 60
)
else()
ExternalProject_Add(ZLIB
GIT_REPOSITORY https://github.com/zlib-ng/zlib-ng.git
GIT_TAG ${LIBSC_BUILD_ZLIB_VERSION}
GIT_SHALLOW true
CMAKE_ARGS ${zlib_cmake_args}
BUILD_BYPRODUCTS ${ZLIB_LIBRARIES}
TLS_VERIFY true
CONFIGURE_HANDLED_BY_BUILD ON
INACTIVITY_TIMEOUT 60
)
endif()
ExternalProject_Add(ZLIB
URL ${SC_BUILD_ZLIB_ARCHIVE_FILE}
CMAKE_ARGS ${zlib_cmake_args}
BUILD_BYPRODUCTS ${ZLIB_LIBRARIES}
TLS_VERIFY true
CONFIGURE_HANDLED_BY_BUILD ON
INACTIVITY_TIMEOUT 60
)


# --- imported target

Expand Down
2 changes: 1 addition & 1 deletion config/sc_autotools.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ libsc_CFLAGS=@CPPFLAGS@ @CFLAGS@

have_mpi=@HAVE_PKG_MPI@
have_json=@SC_HAVE_JSON@
build_zlib=no
debug_build=@SC_ENABLE_DEBUG@
build_zlib=no

Name: libsc
Description: The SC library supports parallel scientific applications.
Expand Down
2 changes: 1 addition & 1 deletion config/sc_include.m4
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ if (jreal == json_real (.5)) { json_decref (jreal); }
[Define to 1 if json_integer and json_real link])
$1_HAVE_JSON="yes"],
[$1_HAVE_JSON=])
AC_SUBST([$1_HAVE_JSON])
])

dnl SC_CHECK_LIB(LIBRARY LIST, FUNCTION, TOKEN, PREFIX)
Expand Down Expand Up @@ -380,7 +381,6 @@ AC_CHECK_PROG([$1_HAVE_DOT], [dot], [YES], [NO])
SC_CHECK_MATH([$1])
SC_CHECK_ZLIB([$1])
SC_CHECK_JSON([$1])
AC_SUBST([SC_HAVE_JSON])
dnl SC_CHECK_LIB([lua53 lua5.3 lua52 lua5.2 lua51 lua5.1 lua5 lua],
dnl [lua_createtable], [LUA], [$1])
dnl SC_CHECK_BLAS_LAPACK([$1])
Expand Down
Loading

0 comments on commit a9d464d

Please sign in to comment.