Skip to content
Merged
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
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
cmake_minimum_required(VERSION 3.21)
cmake_minimum_required(VERSION 3.29)

# Disable modules support, this is broken with clang-tidy at the moment
cmake_policy(SET CMP0155 OLD)

# This template attempts to be "fetch_content"-able
# so that it works well with tools like CPM or other
Expand All @@ -17,7 +20,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
# Set the project name and language
project(
myproject
VERSION 0.0.1
VERSION 0.0.2
DESCRIPTION ""
HOMEPAGE_URL "%%myurl%%"
LANGUAGES CXX C)
Expand Down
10 changes: 5 additions & 5 deletions Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ function(myproject_setup_dependencies)
# already been provided to us by a parent project

if(NOT TARGET fmtlib::fmtlib)
cpmaddpackage("gh:fmtlib/fmt#11.1.4")
cpmaddpackage("gh:fmtlib/fmt#12.1.0")
endif()

if(NOT TARGET spdlog::spdlog)
cpmaddpackage(
NAME
spdlog
VERSION
1.15.2
1.17.0
GITHUB_REPOSITORY
"gabime/spdlog"
OPTIONS
"SPDLOG_FMT_EXTERNAL ON")
endif()

if(NOT TARGET Catch2::Catch2WithMain)
cpmaddpackage("gh:catchorg/Catch2@3.8.1")
cpmaddpackage("gh:catchorg/Catch2@3.12.0")
endif()

if(NOT TARGET CLI11::CLI11)
cpmaddpackage("gh:CLIUtils/CLI11@2.5.0")
cpmaddpackage("gh:CLIUtils/CLI11@2.6.1")
endif()

if(NOT TARGET ftxui::screen)
cpmaddpackage("gh:ArthurSonzogni/FTXUI@6.0.2")
cpmaddpackage("gh:ArthurSonzogni/FTXUI@6.1.9")
endif()

if(NOT TARGET tools::tools)
Expand Down
12 changes: 3 additions & 9 deletions ProjectOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ macro(myproject_setup_options)
if(NOT PROJECT_IS_TOP_LEVEL OR myproject_PACKAGING_MAINTAINER_MODE)
option(myproject_ENABLE_IPO "Enable IPO/LTO" OFF)
option(myproject_WARNINGS_AS_ERRORS "Treat Warnings As Errors" OFF)
option(myproject_ENABLE_USER_LINKER "Enable user-selected linker" OFF)
option(myproject_ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" OFF)
option(myproject_ENABLE_SANITIZER_LEAK "Enable leak sanitizer" OFF)
option(myproject_ENABLE_SANITIZER_UNDEFINED "Enable undefined sanitizer" OFF)
Expand All @@ -87,7 +86,6 @@ macro(myproject_setup_options)
else()
option(myproject_ENABLE_IPO "Enable IPO/LTO" ON)
option(myproject_WARNINGS_AS_ERRORS "Treat Warnings As Errors" ON)
option(myproject_ENABLE_USER_LINKER "Enable user-selected linker" OFF)
option(myproject_ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" ${SUPPORTS_ASAN})
option(myproject_ENABLE_SANITIZER_LEAK "Enable leak sanitizer" OFF)
option(myproject_ENABLE_SANITIZER_UNDEFINED "Enable undefined sanitizer" ${SUPPORTS_UBSAN})
Expand All @@ -104,7 +102,6 @@ macro(myproject_setup_options)
mark_as_advanced(
myproject_ENABLE_IPO
myproject_WARNINGS_AS_ERRORS
myproject_ENABLE_USER_LINKER
myproject_ENABLE_SANITIZER_ADDRESS
myproject_ENABLE_SANITIZER_LEAK
myproject_ENABLE_SANITIZER_UNDEFINED
Expand Down Expand Up @@ -170,13 +167,10 @@ macro(myproject_local_options)
""
"")

# Linker and sanitizers not supported in Emscripten
if(NOT EMSCRIPTEN)
if(myproject_ENABLE_USER_LINKER)
include(cmake/Linker.cmake)
myproject_configure_linker(myproject_options)
endif()
include(cmake/Linker.cmake)
# Must configure each target with linker options, we're avoiding setting it globally for now

if(NOT EMSCRIPTEN)
include(cmake/Sanitizers.cmake)
myproject_enable_sanitizers(
myproject_options
Expand Down
4 changes: 2 additions & 2 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.40.8)
set(CPM_HASH_SUM "78ba32abdf798bc616bab7c73aac32a17bbd7b06ad9e26a6add69de8f3ae4791")
set(CPM_DOWNLOAD_VERSION 0.42.1)
set(CPM_HASH_SUM "f3a6dcc6a04ce9e7f51a127307fa4f699fb2bade357a8eb4c5b45df76e1dc6a5")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
Expand Down
31 changes: 10 additions & 21 deletions cmake/Linker.cmake
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
macro(myproject_configure_linker project_name)
include(CheckCXXCompilerFlag)

set(USER_LINKER_OPTION
"lld"
set(myproject_USER_LINKER_OPTION
"DEFAULT"
CACHE STRING "Linker to be used")
set(USER_LINKER_OPTION_VALUES "lld" "gold" "bfd" "mold")
set_property(CACHE USER_LINKER_OPTION PROPERTY STRINGS ${USER_LINKER_OPTION_VALUES})
set(myproject_USER_LINKER_OPTION_VALUES "DEFAULT" "SYSTEM" "LLD" "GOLD" "BFD" "MOLD" "SOLD" "APPLE_CLASSIC" "MSVC")
set_property(CACHE myproject_USER_LINKER_OPTION PROPERTY STRINGS ${myproject_USER_LINKER_OPTION_VALUES})
list(
FIND
USER_LINKER_OPTION_VALUES
${USER_LINKER_OPTION}
USER_LINKER_OPTION_INDEX)
myproject_USER_LINKER_OPTION_VALUES
${myproject_USER_LINKER_OPTION}
myproject_USER_LINKER_OPTION_INDEX)

if(${USER_LINKER_OPTION_INDEX} EQUAL -1)
if(${myproject_USER_LINKER_OPTION_INDEX} EQUAL -1)
message(
STATUS
"Using custom linker: '${USER_LINKER_OPTION}', explicitly supported entries are ${USER_LINKER_OPTION_VALUES}")
endif()

if(NOT myproject_ENABLE_USER_LINKER)
return()
"Using custom linker: '${myproject_USER_LINKER_OPTION}', explicitly supported entries are ${myproject_USER_LINKER_OPTION_VALUES}")
endif()

set(LINKER_FLAG "-fuse-ld=${USER_LINKER_OPTION}")

check_cxx_compiler_flag(${LINKER_FLAG} CXX_SUPPORTS_USER_LINKER)
if(CXX_SUPPORTS_USER_LINKER)
target_compile_options(${project_name} INTERFACE ${LINKER_FLAG})
endif()
set_target_properties(${project_name} PROPERTIES LINKER_TYPE "${myproject_USER_LINKER_OPTION}")
endmacro()
12 changes: 1 addition & 11 deletions cmake/StandardProjectSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Enhance error reporting and compiler messages
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
if(WIN32)
# On Windows cuda nvcc uses cl and not clang
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fcolor-diagnostics> $<$<COMPILE_LANGUAGE:CXX>:-fcolor-diagnostics>)
else()
add_compile_options(-fcolor-diagnostics)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(WIN32)
# On Windows cuda nvcc uses cl and not gcc
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fdiagnostics-color=always>
$<$<COMPILE_LANGUAGE:CXX>:-fdiagnostics-color=always>)
else()
add_compile_options(-fdiagnostics-color=always)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER 1900)
add_compile_options(/diagnostics:column)
else()
Expand All @@ -42,4 +32,4 @@ endif()

# run vcvarsall when msvc is used
include("${CMAKE_CURRENT_LIST_DIR}/VCEnvironment.cmake")
run_vcvarsall()
myproject_run_vcvarsall()
6 changes: 3 additions & 3 deletions cmake/StaticAnalyzers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ macro(myproject_enable_cppcheck WARNINGS_AS_ERRORS CPPCHECK_OPTIONS)
list(APPEND CMAKE_CXX_CPPCHECK --error-exitcode=2)
endif()
else()
message(${WARNING_MESSAGE} "cppcheck requested but executable not found")
message(WARNING "cppcheck requested but executable not found")
endif()
endmacro()

Expand Down Expand Up @@ -100,7 +100,7 @@ macro(myproject_enable_clang_tidy target WARNINGS_AS_ERRORS)
message("Also setting clang-tidy globally")
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_OPTIONS})
else()
message(${WARNING_MESSAGE} "clang-tidy requested but executable not found")
message(WARNING "clang-tidy requested but executable not found")
endif()
endmacro()

Expand All @@ -109,6 +109,6 @@ macro(myproject_enable_include_what_you_use)
if(INCLUDE_WHAT_YOU_USE)
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${INCLUDE_WHAT_YOU_USE})
else()
message(${WARNING_MESSAGE} "include-what-you-use requested but executable not found")
message(WARNING "include-what-you-use requested but executable not found")
endif()
endmacro()
2 changes: 1 addition & 1 deletion cmake/Tests.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function(myproject_enable_coverage project_name)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
target_compile_options(${project_name} INTERFACE --coverage -O0 -g)
target_compile_options(${project_name} INTERFACE --coverage -g)
target_link_libraries(${project_name} INTERFACE --coverage)
endif()
endfunction()
6 changes: 3 additions & 3 deletions cmake/VCEnvironment.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include("${CMAKE_CURRENT_LIST_DIR}/Utilities.cmake")

macro(detect_architecture)
macro(myproject_detect_architecture)
# detect the architecture
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" CMAKE_SYSTEM_PROCESSOR_LOWER)
if(CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL x86 OR CMAKE_SYSTEM_PROCESSOR_LOWER MATCHES "^i[3456]86$")
Expand All @@ -25,7 +25,7 @@ macro(detect_architecture)
endmacro()

# Run vcvarsall.bat and set CMake environment variables
function(run_vcvarsall)
function(myproject_run_vcvarsall)
# if MSVC but VSCMD_VER is not set, which means vcvarsall has not run
if(MSVC AND "$ENV{VSCMD_VER}" STREQUAL "")

Expand All @@ -43,7 +43,7 @@ function(run_vcvarsall)

if(EXISTS ${VCVARSALL_FILE})
# detect the architecture
detect_architecture()
myproject_detect_architecture()

# run vcvarsall and print the environment variables
message(STATUS "Running `${VCVARSALL_FILE} ${VCVARSALL_ARCH}` to set up the MSVC environment")
Expand Down
3 changes: 3 additions & 0 deletions fuzz_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ target_link_libraries(
-fsanitize=fuzzer)
target_compile_options(fuzz_tester PRIVATE -fsanitize=fuzzer)


myproject_configure_linker(fuzz_tester)

# Allow short runs during automated testing to see if something new breaks
set(FUZZ_RUNTIME
10
Expand Down
3 changes: 3 additions & 0 deletions src/ftxui_sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ target_link_system_libraries(
ftxui::dom
ftxui::component)


myproject_configure_linker(intro)

target_include_directories(intro PRIVATE "${CMAKE_BINARY_DIR}/configured_files/include")

# Apply WASM-specific configuration
Expand Down
2 changes: 2 additions & 0 deletions src/sample_library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ endif()

target_compile_features(sample_library PUBLIC cxx_std_${CMAKE_CXX_STANDARD})

myproject_configure_linker(sample_library)

set_target_properties(
sample_library
PROPERTIES VERSION ${PROJECT_VERSION}
Expand Down
11 changes: 10 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.15...3.23)

project(CmakeConfigPackageTests LANGUAGES CXX)
project(CmakeConfigPackageTests
VERSION ${PROJECT_VERSION}
LANGUAGES CXX)

# ---- Test as standalone project the exported config package ----

Expand Down Expand Up @@ -37,6 +39,8 @@ target_link_libraries(
myproject::sample_library
Catch2::Catch2WithMain)

myproject_configure_linker(tests)

if(WIN32 AND BUILD_SHARED_LIBS)
add_custom_command(
TARGET tests
Expand Down Expand Up @@ -69,6 +73,8 @@ target_link_libraries(
myproject::sample_library
Catch2::Catch2WithMain)

myproject_configure_linker(constexpr_tests)

catch_discover_tests(
constexpr_tests
TEST_PREFIX
Expand All @@ -93,6 +99,9 @@ target_link_libraries(
Catch2::Catch2WithMain)
target_compile_definitions(relaxed_constexpr_tests PRIVATE -DCATCH_CONFIG_RUNTIME_STATIC_REQUIRE)

myproject_configure_linker(relaxed_constexpr_tests)


catch_discover_tests(
relaxed_constexpr_tests
TEST_PREFIX
Expand Down
Loading