Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 48 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required(VERSION 3.27)
cmake_minimum_required(VERSION 3.27...3.31)

project(beman_optional26 VERSION 0.0.0 LANGUAGES CXX)

# Includes
include(CTest)
include(FetchContent)

set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets)
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds are not allowed!")
endif()

option(
OPTIONAL26_ENABLE_TESTING
"Enable building tests and test infrastructure"
${PROJECT_IS_TOP_LEVEL}
)

# Includes
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

set(TARGET_PACKAGE_NAME ${PROJECT_NAME})
set(TARGETS_EXPORT_NAME ${TARGET_PACKAGE_NAME}-targets)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_PACKAGE_NAME})

# Build the tests if enabled via the option OPTIONAL26_ENABLE_TESTING
if(OPTIONAL26_ENABLE_TESTING)
include(FetchContent)

enable_testing()

# Fetch GoogleTest
FetchContent_Declare(
googletest
Expand All @@ -33,9 +43,16 @@ endif()

# Create the library target and named header set for beman_optional26
add_library(beman_optional26 STATIC)
add_library(beman_optional26::beman_optional26 ALIAS beman_optional26)
target_sources(
beman_optional26
PUBLIC FILE_SET beman_optional26_headers TYPE HEADERS BASE_DIRS src include
PUBLIC FILE_SET beman_optional26_includes TYPE HEADERS BASE_DIRS src include
# FILES ... ?
)

set_target_properties(
beman_optional26
PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON
)

if(OPTIONAL26_ENABLE_TESTING)
Expand All @@ -48,6 +65,7 @@ if(OPTIONAL26_ENABLE_TESTING)
FILE_SET beman_optional26_test_headers
TYPE HEADERS
BASE_DIRS src
# FILES ... ?
)
endif()

Expand All @@ -66,3 +84,26 @@ add_custom_target(
COMMAND mkdir -p coverage
COMMAND gcovr --config gcovr.cfg .
)

# install
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake
VERSION ${CMAKE_PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

configure_package_config_file(
cmake/Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}.cmake
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)

set(CPACK_GENERATOR TGZ)
include(CPack)
16 changes: 13 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 29,
"minor": 27,
"patch": 2
},
"configurePresets": [
Expand All @@ -14,7 +14,13 @@
"binaryDir": "${sourceDir}/.build/${presetName}",
"installDir": "${sourceDir}/.install/${presetName}",
"cacheVariables": {
"CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Debug;Tsan;Asan"
"CMAKE_PREFIX_PATH": {
"type": "path",
"value": "${sourceDir}/.install/${presetName}"
},
"CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Debug;Tsan;Asan",
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
"CMAKE_SKIP_TEST_ALL_DEPENDENCY": false
}
},
{
Expand Down Expand Up @@ -85,7 +91,11 @@
{
"name": "common",
"hidden": true,
"configuration": "Asan"
"configuration": "Asan",
"targets": [
"all_verify_interface_header_sets",
"install"
]
},
{
"name": "system",
Expand Down
22 changes: 16 additions & 6 deletions etc/clang-flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,22 @@ set(CMAKE_CXX_FLAGS_TSAN
"C++ TSAN Flags"
FORCE
)
set(CMAKE_CXX_FLAGS_ASAN
"-O3 -g -DNDEBUG -fsanitize=address,undefined,leak"
CACHE STRING
"C++ ASAN Flags"
FORCE
)
if(APPLE)
set(CMAKE_CXX_FLAGS_ASAN
"-O3 -g -DNDEBUG -fsanitize=address,undefined"
CACHE STRING
"C++ ASAN Flags"
FORCE
)
else()
set(CMAKE_CXX_FLAGS_ASAN
"-O3 -g -DNDEBUG -fsanitize=address,undefined,leak"
CACHE STRING
"C++ ASAN Flags"
FORCE
)
endif()

set(CMAKE_CXX_FLAGS_GCOV
"-O0 -fno-inline -g --coverage"
CACHE STRING
Expand Down
21 changes: 15 additions & 6 deletions etc/gcc-flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@ set(CMAKE_CXX_FLAGS_TSAN
"C++ TSAN Flags"
FORCE
)
set(CMAKE_CXX_FLAGS_ASAN
"-O3 -g -DNDEBUG -fsanitize=address,undefined,leak"
CACHE STRING
"C++ ASAN Flags"
FORCE
)
if(APPLE)
set(CMAKE_CXX_FLAGS_ASAN
"-O3 -g -DNDEBUG -fsanitize=address,undefined"
CACHE STRING
"C++ ASAN Flags"
FORCE
)
else()
set(CMAKE_CXX_FLAGS_ASAN
"-O3 -g -DNDEBUG -fsanitize=address,undefined,leak"
CACHE STRING
"C++ ASAN Flags"
FORCE
)
endif()

set(CMAKE_CXX_FLAGS_GCOV
"-O0 -fno-inline -g --coverage -fprofile-abs-path"
Expand Down
6 changes: 1 addition & 5 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# cmake-format: on

set(BEMAN_OPTIONAL26_LIBRARY "beman_optional26")

include(GNUInstallDirs)

# List of all buildable examples.
set(EXAMPLES
concept_checks
Expand All @@ -25,7 +21,7 @@ foreach(example ${EXAMPLES})
target_sources(${example} PRIVATE ${example}.cpp)

# Link example with the library.
target_link_libraries(${example} "${BEMAN_OPTIONAL26_LIBRARY}")
target_link_libraries(${example} beman_optional26::beman_optional26)

# Install .
install(
Expand Down
12 changes: 11 additions & 1 deletion src/beman/optional26/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ target_sources(beman_optional26 PUBLIC optional.cpp detail/iterator.cpp)
# The library is empty -- exclude it
install(
TARGETS beman_optional26
EXPORT ${TARGETS_EXPORT_NAME}
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT beman_optional26_library
EXCLUDE_FROM_ALL
FILE_SET beman_optional26_includes
)

install(
Expand All @@ -20,6 +21,15 @@ install(
COMPONENT beman_optional26_development
)

# FIXME: install TARGETS target beman_optional26 is exported
# but not all of its interface file sets are installed
# install(
# EXPORT ${TARGETS_EXPORT_NAME}
# FILE ${TARGETS_EXPORT_NAME}.cmake
# DESTINATION "${INSTALL_CONFIGDIR}"
# NAMESPACE beman_optional26::
# )

# Tests
if(OPTIONAL26_ENABLE_TESTING)
add_subdirectory(tests)
Expand Down
7 changes: 5 additions & 2 deletions src/beman/optional26/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ target_sources(

target_link_libraries(
beman_optional26_test
PRIVATE beman_optional26 GTest::gtest GTest::gtest_main
PRIVATE beman_optional26::beman_optional26 GTest::gtest GTest::gtest_main
)

# Issue #32: Re-enable ASAN run CI/clang-19.
Expand All @@ -43,7 +43,10 @@ gtest_add_tests(TARGET beman_optional26_test "" AUTO)

add_library(constructor_fails test_constructor_fail.cpp)

target_link_libraries(constructor_fails PRIVATE beman_optional26)
target_link_libraries(
constructor_fails
PRIVATE beman_optional26::beman_optional26
)

set_target_properties(
constructor_fails
Expand Down