ovni/CMakeLists.txt

109 lines
3.2 KiB
CMake
Raw Normal View History

2024-02-14 14:10:18 +01:00
# Copyright (c) 2021-2024 Barcelona Supercomputing Center (BSC)
2022-09-19 12:39:02 +02:00
# SPDX-License-Identifier: GPL-3.0-or-later
2021-11-03 08:47:02 +01:00
cmake_minimum_required(VERSION 3.20)
2021-11-03 08:47:02 +01:00
2024-05-09 16:10:43 +02:00
project(OVNI LANGUAGES C VERSION 1.9.1)
2021-11-03 08:47:02 +01:00
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
2021-11-03 08:47:02 +01:00
add_compile_options(-Wall -Wextra -Wformat
-Wmissing-prototypes -Wstrict-prototypes
#-Wconversion -Wsign-conversion
-Wold-style-definition -pedantic
-Werror
)
2023-04-13 17:16:31 +02:00
set(CMAKE_C_VISIBILITY_PRESET hidden)
2021-11-03 08:47:02 +01:00
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED TRUE)
2021-11-03 08:47:02 +01:00
set(CMAKE_C_EXTENSIONS FALSE)
option(ENABLE_DEBUG_LOG "Enable debug messages (very verbose)")
2023-05-30 18:16:08 +02:00
option(ENABLE_ALL_TESTS "Forces the execution of all tests")
2023-07-26 17:13:28 +02:00
set(OVNI_GIT_COMMIT "unknown" CACHE STRING "Set the git commit")
if("${OVNI_GIT_COMMIT}" STREQUAL "unknown")
message(WARNING "OVNI_GIT_COMMIT is unknown, please specify the git commit")
endif()
if(ENABLE_DEBUG_LOG)
add_definitions(-DENABLE_DEBUG)
endif()
add_definitions(-D_POSIX_C_SOURCE=200809L)
2021-11-18 14:52:03 +01:00
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
2021-11-19 17:41:10 +01:00
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Asan UBsan." FORCE)
2021-11-18 14:52:03 +01:00
endif(NOT CMAKE_BUILD_TYPE)
include(GNUInstallDirs)
set(OVNI_CONFIG_RELDIR "${CMAKE_INSTALL_DATADIR}/ovni")
set(OVNI_CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${OVNI_CONFIG_RELDIR}")
2021-11-03 08:47:02 +01:00
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_available OUTPUT error LANGUAGES C)
# Enable IPO by default, if available
2022-12-19 13:06:00 +01:00
if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
if(ipo_available)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO is not supported, disabling")
endif()
endif()
if(NOT CMAKE_INTERPROCEDURAL_OPTIMIZATION)
message(WARNING "IPO is not enabled, expect performance penalty")
2021-11-03 08:47:02 +01:00
endif()
2021-11-18 14:52:03 +01:00
# Extra build type for AddressSanitizer (Asan)
set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_DEBUG} \
-fsanitize=address \
-fno-optimize-sibling-calls \
-fsanitize-address-use-after-scope \
-fno-omit-frame-pointer"
CACHE STRING "Flags used by the C compiler during AddressSanitizer builds." FORCE)
2021-11-19 17:41:10 +01:00
set(CMAKE_C_FLAGS_UBSAN "${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined"
CACHE STRING "Flags used by the C compiler during UndefinedBehaviorSanitizer builds." FORCE)
find_program(IWYU NAMES include-what-you-use iwyu)
if(IWYU)
set(IWYU_CMD ${IWYU} -Xiwyu --no_comments)
set(CMAKE_C_INCLUDE_WHAT_YOU_USE ${IWYU_CMD})
2023-03-22 19:05:48 +01:00
message(STATUS "IWYU found")
else()
message(WARNING "IWYU not found, skipping")
endif()
2022-09-29 12:35:25 +02:00
# Required for clock_gettime() in glibc <= 2.17
include(CheckLibraryExists)
check_library_exists(c clock_gettime "" HAVE_CLOCK_GETTIME)
if (NOT HAVE_CLOCK_GETTIME)
check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME_RT)
if (HAVE_CLOCK_GETTIME_RT)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lrt")
set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} -lrt")
else()
message(FATAL_ERROR "cannot find clock_gettime()")
endif()
endif()
add_subdirectory(include)
2022-09-29 15:45:52 +02:00
add_subdirectory(src)
2021-11-03 08:47:02 +01:00
2022-09-29 15:45:52 +02:00
include(CTest)
if(BUILD_TESTING)
add_subdirectory(test)
2021-11-29 14:43:40 +01:00
endif()
install(DIRECTORY cfg/ DESTINATION "${OVNI_CONFIG_RELDIR}")
2023-11-02 18:18:39 +01:00
include(FeatureSummary)
feature_summary(WHAT ALL)