BigWhoop/CMakeLists.txt

203 lines
11 KiB
Text
Raw Normal View History

#*================================================================================================*#
#| |#
#| /$$$$$$$ /$$ /$$ /$$ /$$ |#
#| | $$__ $$|__/ | $$ /$ | $$| $$ |#
#| | $$ \ $$ /$$ /$$$$$$ | $$ /$$$| $$| $$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ |#
#| | $$$$$$$ | $$ /$$__ $$ | $$/$$ $$ $$| $$__ $$ /$$__ $$ /$$__ $$ /$$__ $$ |#
#| | $$__ $$| $$| $$ \ $$ | $$$$_ $$$$| $$ \ $$| $$ \ $$| $$ \ $$| $$ \ $$ |#
#| | $$ \ $$| $$| $$ | $$ | $$$/ \ $$$| $$ | $$| $$ | $$| $$ | $$| $$ | $$ |#
#| | $$$$$$$/| $$| $$$$$$$ | $$/ \ $$| $$ | $$| $$$$$$/| $$$$$$/| $$$$$$$/ |#
#| |_______/ |__/ \____ $$ |__/ \__/|__/ |__/ \______/ \______/ | $$____/ |#
#| /$$ \ $$ | $$ |#
#| | $$$$$$/ | $$ |#
#| \______/ |__/ |#
#| |#
#| DESCRIPTION: |#
#| ------------ |#
#| |#
#| Defines the global cmake script for the Big Whoop compression algorithm. |#
#| |#
#| -------------------------------------------------------------------------------------------- |#
#| Copyright (c) 2023, High Performance Computing Center - University of Stuttgart |#
#| |#
#| Redistribution and use in source and binary forms, with or without modification, are |#
#| permitted provided that the following conditions are met: |#
#| |#
#| (1) Redistributions of source code must retain the above copyright notice, this list of |#
#| conditions and the following disclaimer. |#
#| |#
#| (2) Redistributions in binary form must reproduce the above copyright notice, this list |#
#| of conditions and the following disclaimer in the documentation and/or other |#
#| materials provided with the distribution. |#
#| |#
#| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS |#
#| OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |#
#| MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |#
#| COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |#
#| EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |#
#| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |#
#| HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |#
#| TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |#
#| EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |#
#| |#
#*================================================================================================*#
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Check if the version requirement for cmake is met. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
cmake_minimum_required(VERSION 3.5.1)
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Set the project name and description. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
project(BWC LANGUAGES C)
set(PROJECT_DESCRIPTION "Compression algorithm for IEEE 754 datasets")
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Check that the current build is not a in-source build. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
message(FATAL_ERROR "In-source builds are prohibited. Please create a separate build directory")
endif()
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Save the bwc.c file in a temporary variable and match #
# the current version number with a regular expression. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/src/library/libbwc.c _bwc_c_contents)
string(REGEX MATCH "V[ \t]+([0-9]+).([0-9]+).([0-9]+)" _ ${ver} ${_bwc_c_contents})
2023-06-20 11:43:33 +00:00
set(BWC_VERSION_MAJOR ${CMAKE_MATCH_1})
set(BWC_VERSION_MINOR ${CMAKE_MATCH_2})
set(BWC_VERSION_PATCH ${CMAKE_MATCH_3})
set(BWC_VERSION "${BWC_VERSION_MAJOR}.${BWC_VERSION_MINOR}.${BWC_VERSION_PATCH}")
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Setup a user-specified option used to control the sample #
# precision during compression. The standard option is #
# set to double precision. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
set(PREC "Double" CACHE STRING "User-specified option used to control\
the precision during compression")
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Inlude the GNU standard installation directories module #
# to set up the output directories. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
include(GNUInstallDirs)
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Set up the output directories for the Big Whoop library #
# and utility binaries. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
list(INSERT CMAKE_MODULE_PATH 0 "${BWC_SOURCE_DIR}/cmake")
if(${TOOL})
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BWC_SOURCE_DIR}/${CMAKE_INSTALL_BINDIR})
endif()
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BWC_SOURCE_DIR}/${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BWC_SOURCE_DIR}/${CMAKE_INSTALL_LIBDIR})
endif()
#----------------------------------------------------------#
# Set the target installation directory of the config-file #
# packaging configuration files. #
#----------------------------------------------------------#
set(CMAKE_INSTALL_CMAKEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/bwc
CACHE PATH "Installation directory for config-file package cmake files")
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Suggest the C standard (C99) used by the compiler. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 11)
endif()
message(STATUS "Compiling with C standard: ${CMAKE_C_STANDARD}")
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Suggest the C++ standard (CXX98) used by the compiler. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Suggest C++98
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
message(STATUS "Compiling with C++ standard: ${CMAKE_CXX_STANDARD}")
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Check if the OpenMP package is available for the current #
# setup and set the appropriate C/C++ flags. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
endif()
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Add all necessary compiler warnings for debugging. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif()
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Include the CMake dependent option macro. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
include(CMakeDependentOption)
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Set the -fPIC compile option for static libraries. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
get_property(SHARED_LIBS_SUPPORTED GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
cmake_dependent_option(BUILD_SHARED_LIBS
"Whether or not to build shared libraries" ON
"SHARED_LIBS_SUPPORTED" OFF)
if(SHARED_LIBS_SUPPORTED)
cmake_dependent_option(BWC_ENABLE_PIC
"Build with Position Independent Code" ON
"NOT BUILD_SHARED_LIBS" ON)
endif()
if(BWC_ENABLE_PIC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Add the project source code. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
add_subdirectory(src/library)
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
# Add the utilities source code if requested. #
#----------------------------------------------------------#
2023-06-20 11:43:33 +00:00
if(${TOOL})
add_subdirectory(src/tools)
else()
set(ignoreMe "${BUILD_EAS3}${BUILD_NETCDF}")
endif()
#----------------------------------------------------------#
# Config-file packaging #
#----------------------------------------------------------#
export(TARGETS bwclib NAMESPACE bwc:: FILE "bwc-targets.cmake")
configure_file(${PROJECT_SOURCE_DIR}/bwc-config.cmake.in
"${PROJECT_BINARY_DIR}/bwc-config.cmake" @ONLY)
configure_file(${PROJECT_SOURCE_DIR}/bwc-config-version.cmake.in
"${PROJECT_BINARY_DIR}/bwc-config-version.cmake" @ONLY)
install( FILES "${PROJECT_BINARY_DIR}/bwc-config.cmake"
"${PROJECT_BINARY_DIR}/bwc-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_CMAKEDIR})
install( EXPORT bwc-targets
NAMESPACE bwc::
DESTINATION ${CMAKE_INSTALL_CMAKEDIR})