FastSignals: Normalize CMake files.

This commit is contained in:
Joao Matos
2025-06-14 10:55:38 +01:00
committed by tritao
parent c045cd68c9
commit dd24bd47e2
2 changed files with 19 additions and 32 deletions

View File

@@ -2,24 +2,11 @@ cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(FastSignals)
# Use `-DBUILD_TESTING=OFF` to disable testing/benchmarking.
enable_testing()
include(cmake/functions.cmake)
add_subdirectory(libfastsignals)
if(BUILD_TESTING)
# add_subdirectory(tests/benchmark)
# add_subdirectory(tests/libfastsignals_bench)
#add_subdirectory(tests/libfastsignals_stress_tests)
if(BUILD_FASTSIGNALS_TESTING)
add_subdirectory(tests/libfastsignals_stress_tests)
add_subdirectory(tests/libfastsignals_unit_tests)
endif()
# Trace variables, both environment and internal.
execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "environment")
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()

View File

@@ -1,39 +1,39 @@
# В текущей версии CMake не может включить режим C++17 в некоторых компиляторах.
# Функция использует обходной манёвр.
# In the current version, CMake cannot enable C++17 mode for some compilers.
# This function uses a workaround.
function(custom_enable_cxx17 TARGET)
# Включаем C++17 везде, где CMake может.
target_compile_features(${TARGET} PUBLIC cxx_std_17)
# Включаем режим C++latest в Visual Studio
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set_target_properties(${TARGET} PROPERTIES COMPILE_FLAGS "/std:c++latest")
# Включаем компоновку с libc++, libc++experimental и pthread для Clang
# Enable C++17 where CMake can.
target_compile_features(${TARGET} PUBLIC cxx_std_17)
# Enable C++latest mode in Visual Studio
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set_target_properties(${TARGET} PROPERTIES COMPILE_FLAGS "/std:c++latest")
# Enable linking with libc++, libc++experimental, and pthread for Clang
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set_target_properties(${TARGET} PROPERTIES COMPILE_FLAGS "-stdlib=libc++ -pthread")
set_target_properties(${TARGET} PROPERTIES COMPILE_FLAGS "-stdlib=libc++ -pthread")
target_link_libraries(${TARGET} c++experimental pthread)
endif()
endfunction(custom_enable_cxx17)
# Функция добавляет цель-библиотеку.
# Function to add a library target.
function(custom_add_library_from_dir TARGET)
# Собираем файлы с текущего каталога
# Gather files from the current directory
file(GLOB TARGET_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
add_library(${TARGET} ${TARGET_SRC})
endfunction()
# Функция добавляет цель исполняемого файла.
# Function to add an executable target.
function(custom_add_executable_from_dir TARGET)
# Собираем файлы с текущего каталога
# Gather files from the current directory
file(GLOB TARGET_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
add_executable(${TARGET} ${TARGET_SRC})
endfunction()
# Функция добавляет цель исполняемого файла, содержащего тесты библиотеки.
# Function to add an executable target containing tests for a library.
function(custom_add_test_from_dir TARGET LIBRARY)
custom_add_executable_from_dir(${TARGET})
# Добавляем путь к заголовку фреймворка Catch
# Add path to Catch framework header
target_include_directories(${TARGET} PRIVATE "${CMAKE_SOURCE_DIR}/libs/catch")
# Добавляем компоновку с проверяемой библиотекой
# Link with the library being tested
target_link_libraries(${TARGET} ${LIBRARY})
# Регистрируем исполняемый файл в CMake как набор тестов.
# Register the executable with CMake as a test set
add_test(${TARGET} ${TARGET})
endfunction()