summaryrefslogtreecommitdiff
path: root/cmake/utils
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/utils')
-rw-r--r--cmake/utils/AddCompileFlags.cmake21
-rw-r--r--cmake/utils/CMakeUninstall.cmake.in36
-rw-r--r--cmake/utils/CompilerUtils.cmake10
-rw-r--r--cmake/utils/DebugTargets.cmake16
-rw-r--r--cmake/utils/DisableTestLogging.cmake23
-rw-r--r--cmake/utils/FindProtobufC.cmake36
-rw-r--r--cmake/utils/GenCoverage.cmake6
-rw-r--r--cmake/utils/TestUtils.cmake34
8 files changed, 102 insertions, 80 deletions
diff --git a/cmake/utils/AddCompileFlags.cmake b/cmake/utils/AddCompileFlags.cmake
index 8f3877d9..b81ccc67 100644
--- a/cmake/utils/AddCompileFlags.cmake
+++ b/cmake/utils/AddCompileFlags.cmake
@@ -1,17 +1,6 @@
-# - MACRO_ADD_COMPILE_FLAGS(<_target> "flags...")
+# - add_compile_flags(<target> <flags>...)
+# Add compile flags to a target using modern CMake
-# Copyright (c) 2006, Oswald Buddenhagen, <ossi@kde.org>
-#
-# Redistribution and use is allowed according to the terms of the BSD license.
-
-macro(add_compile_flags _target _flg)
-
- get_target_property(_flags ${_target} COMPILE_FLAGS)
- if (_flags)
- set(_flags "${_flags} ${_flg}")
- else (_flags)
- set(_flags "${_flg}")
- endif (_flags)
- set_target_properties(${_target} PROPERTIES COMPILE_FLAGS "${_flags}")
-
-endmacro(add_compile_flags)
+macro(add_compile_flags _target)
+ target_compile_options(${_target} PRIVATE ${ARGN})
+endmacro()
diff --git a/cmake/utils/CMakeUninstall.cmake.in b/cmake/utils/CMakeUninstall.cmake.in
index 985b31b2..b8bba5fd 100644
--- a/cmake/utils/CMakeUninstall.cmake.in
+++ b/cmake/utils/CMakeUninstall.cmake.in
@@ -1,29 +1,21 @@
-if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
+if (NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
-endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
+endif()
file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
-foreach(file ${files})
+foreach (file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
- if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
- if(CMAKE_VERSION VERSION_LESS "3.28.0")
- exec_program(
- "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
- OUTPUT_VARIABLE rm_out
- RETURN_VALUE rm_retval
- )
- else()
- execute_process(
- COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}"
- RESULT_VARIABLE rm_out
- ERROR_VARIABLE rm_retval
- )
- endif ()
- if(NOT "${rm_retval}" STREQUAL "" AND NOT "${rm_retval}" STREQUAL 0)
+ if (IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+ execute_process(
+ COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}"
+ RESULT_VARIABLE rm_out
+ ERROR_VARIABLE rm_retval
+ )
+ if (NOT "${rm_retval}" STREQUAL "" AND NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
- endif(NOT "${rm_retval}" STREQUAL "" AND NOT "${rm_retval}" STREQUAL 0)
- else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+ endif()
+ else()
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
- endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
-endforeach(file)
+ endif()
+endforeach ()
diff --git a/cmake/utils/CompilerUtils.cmake b/cmake/utils/CompilerUtils.cmake
index 7c8b022f..35548f4f 100644
--- a/cmake/utils/CompilerUtils.cmake
+++ b/cmake/utils/CompilerUtils.cmake
@@ -1,13 +1,13 @@
include(CheckCCompilerFlag)
function(test_and_set_c_compiler_flag_global _flag)
-
string(REGEX REPLACE "-" "_" _sflag ${_flag})
- set(CMAKE_REQUIRED_FLAGS ${_flag})
+ string(REGEX REPLACE "=" "_" _sflag ${_sflag})
+ # Use -Werror during test so clang rejects unknown flags
+ set(CMAKE_REQUIRED_FLAGS "-Werror ${_flag}")
check_c_compiler_flag(${_flag} COMPILER_SUPPORTS_FLAG_${_sflag})
if(COMPILER_SUPPORTS_FLAG_${_sflag})
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flag}" PARENT_SCOPE)
+ add_compile_options(${_flag})
endif()
-
-endfunction(test_and_set_c_compiler_flag_global)
+endfunction()
diff --git a/cmake/utils/DebugTargets.cmake b/cmake/utils/DebugTargets.cmake
new file mode 100644
index 00000000..78899213
--- /dev/null
+++ b/cmake/utils/DebugTargets.cmake
@@ -0,0 +1,16 @@
+# Utility functions for Ouroboros target configuration
+set(OUROBOROS_DEBUG_CONFIGS
+ Debug
+ DebugASan
+ DebugTSan
+ DebugLSan
+ DebugUSan
+ DebugAnalyzer
+)
+
+# Add CONFIG_OUROBOROS_DEBUG definition for debug build types
+function(ouroboros_target_debug_definitions target)
+ list(JOIN OUROBOROS_DEBUG_CONFIGS "," _configs)
+ target_compile_definitions(${target} PRIVATE
+ "$<$<CONFIG:${_configs}>:CONFIG_OUROBOROS_DEBUG>")
+endfunction()
diff --git a/cmake/utils/DisableTestLogging.cmake b/cmake/utils/DisableTestLogging.cmake
index a7e90b38..40c16668 100644
--- a/cmake/utils/DisableTestLogging.cmake
+++ b/cmake/utils/DisableTestLogging.cmake
@@ -1,22 +1,11 @@
-set(DISABLE_TESTS_LOGGING TRUE CACHE BOOL "Disable Ouroboros log output in tests")
-if (DISABLE_TESTS_LOGGING)
- message(STATUS "Ouroboros logging in test output disabled")
-else ()
- message(STATUS "Ouroboros logging in test output enabled")
-endif ()
-
-set(DISABLE_TESTS_CORE_DUMPS TRUE CACHE BOOL "Enable core dumps for tests (useful for debugging)")
-if (DISABLE_TESTS_CORE_DUMPS)
- message(STATUS "Core dumps in tests enabled")
-else ()
- message(STATUS "Core dumps in tests disabled")
-endif ()
+# Macro to apply test logging settings to a target
+# Configuration options are in cmake/config/tests.cmake
macro(disable_test_logging_for_target target)
- if (DISABLE_TESTS_LOGGING)
+ if(DISABLE_TESTS_LOGGING)
target_compile_definitions(${target} PRIVATE OUROBOROS_DISABLE_LOGGING)
- endif ()
- if (DISABLE_TESTS_CORE_DUMPS)
+ endif()
+ if(DISABLE_TESTS_CORE_DUMPS)
target_compile_definitions(${target} PRIVATE DISABLE_TESTS_CORE_DUMPS)
- endif ()
+ endif()
endmacro()
diff --git a/cmake/utils/FindProtobufC.cmake b/cmake/utils/FindProtobufC.cmake
index ff892b5b..4632dfcb 100644
--- a/cmake/utils/FindProtobufC.cmake
+++ b/cmake/utils/FindProtobufC.cmake
@@ -1,22 +1,22 @@
-function(PROTOBUF_GENERATE_C SRCS HDRS)
- if (NOT ARGN)
- message(SEND_ERROR "Error: PROTOBUF_GENERATE_C() called without any proto files")
+function(protobuf_generate_c SRCS HDRS)
+ if(NOT ARGN)
+ message(SEND_ERROR "Error: protobuf_generate_c() called without any proto files")
return()
- endif ()
+ endif()
- if (PROTOBUF_GENERATE_C_APPEND_PATH)
+ if(PROTOBUF_GENERATE_C_APPEND_PATH)
# Create an include path for each file specified
foreach (FIL ${ARGN})
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
get_filename_component(ABS_PATH ${ABS_FIL} PATH)
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
- if (${_contains_already} EQUAL -1)
+ if(${_contains_already} EQUAL -1)
list(APPEND _protobuf_include_path -I ${ABS_PATH})
- endif ()
+ endif()
endforeach ()
- else ()
+ else()
set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
- endif ()
+ endif()
set(${SRCS})
set(${HDRS})
@@ -42,33 +42,37 @@ function(PROTOBUF_GENERATE_C SRCS HDRS)
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
endfunction()
-# By default have PROTOBUF_GENERATE_C macro pass -I to protoc
+# By default have protobuf_generate_c function pass -I to protoc
# for each directory where a proto file is referenced.
-if (NOT DEFINED PROTOBUF_GENERATE_C_APPEND_PATH)
+if(NOT DEFINED PROTOBUF_GENERATE_C_APPEND_PATH)
set(PROTOBUF_GENERATE_C_APPEND_PATH TRUE)
-endif ()
+endif()
-# Find library
find_library(PROTOBUF_C_LIBRARY
NAMES libprotobuf-c.so libprotobuf-c libprotobuf-c.dylib
)
mark_as_advanced(PROTOBUF_C_LIBRARY)
-# Find the include directory
find_path(PROTOBUF_C_INCLUDE_DIR
google/protobuf-c/protobuf-c.h
)
mark_as_advanced(PROTOBUF_C_INCLUDE_DIR)
-# Find the protoc-c Executable
find_program(PROTOBUF_PROTOC_C_EXECUTABLE
NAMES protoc protoc-c
DOC "The Google Protocol Buffers C Compiler"
)
mark_as_advanced(PROTOBUF_PROTOC_C_EXECUTABLE)
-find_package(PackageHandleStandardArgs)
+include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ProtobufC DEFAULT_MSG
PROTOBUF_C_LIBRARY PROTOBUF_C_INCLUDE_DIR PROTOBUF_PROTOC_C_EXECUTABLE)
set(PROTOBUF_C_INCLUDE_DIRS ${PROTOBUF_C_INCLUDE_DIR})
+
+if(ProtobufC_FOUND AND NOT TARGET ProtobufC::ProtobufC)
+ add_library(ProtobufC::ProtobufC UNKNOWN IMPORTED)
+ set_target_properties(ProtobufC::ProtobufC PROPERTIES
+ IMPORTED_LOCATION "${PROTOBUF_C_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${PROTOBUF_C_INCLUDE_DIR}")
+endif()
diff --git a/cmake/utils/GenCoverage.cmake b/cmake/utils/GenCoverage.cmake
index 65f5d8ba..0ae11ee8 100644
--- a/cmake/utils/GenCoverage.cmake
+++ b/cmake/utils/GenCoverage.cmake
@@ -57,8 +57,8 @@ function(create_informational_target)
)
endfunction()
-macro(create_coverage_target)
- if(HAVE_GCOV AND ENABLE_COVERAGE)
+function(create_coverage_target)
+ if(HAVE_GCOV AND NOT DISABLE_COVERAGE)
get_html_coverage_commands(HTML_COVERAGE_COMMANDS)
add_custom_target(coverage
@@ -91,4 +91,4 @@ macro(create_coverage_target)
"Coverage not available"
)
endif()
-endmacro()
+endfunction()
diff --git a/cmake/utils/TestUtils.cmake b/cmake/utils/TestUtils.cmake
index e40bdda1..e602690c 100644
--- a/cmake/utils/TestUtils.cmake
+++ b/cmake/utils/TestUtils.cmake
@@ -3,4 +3,36 @@ function(compute_test_prefix)
file(RELATIVE_PATH _prefix "${CMAKE_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}")
string(REGEX REPLACE "/tests$" "" _prefix "${_prefix}")
set(TEST_PREFIX "${_prefix}" PARENT_SCOPE)
-endfunction(compute_test_prefix)
+endfunction()
+
+# Register tests from a test executable with the test framework
+# Usage: ouroboros_register_tests(TARGET <target> TESTS <test_list> [ENVIRONMENT <env>])
+# The TESTS argument should be the test list variable created by create_test_sourcelist
+function(ouroboros_register_tests)
+ cmake_parse_arguments(PARSE_ARGV 0 ARG "" "TARGET;ENVIRONMENT" "TESTS")
+
+ if(NOT ARG_TARGET)
+ message(FATAL_ERROR "ouroboros_register_tests: TARGET required")
+ endif()
+
+ if(NOT ARG_TESTS)
+ message(FATAL_ERROR "ouroboros_register_tests: TESTS required")
+ endif()
+
+ # First entry is the test driver, skip it
+ set(_tests ${ARG_TESTS})
+ list(POP_FRONT _tests)
+
+ foreach (test_src ${_tests})
+ get_filename_component(test_name ${test_src} NAME_WE)
+ add_test(${TEST_PREFIX}/${test_name}
+ ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET} ${test_name})
+ # All Ouroboros tests support skip return code
+ set_property(TEST ${TEST_PREFIX}/${test_name} PROPERTY SKIP_RETURN_CODE 1)
+ # Optional environment variables
+ if(ARG_ENVIRONMENT)
+ set_property(TEST ${TEST_PREFIX}/${test_name}
+ PROPERTY ENVIRONMENT "${ARG_ENVIRONMENT}")
+ endif()
+ endforeach ()
+endfunction()