Skip to content

Commit 7276438

Browse files
authored
Merge pull request #131 from cpp-best-practices/work_on_variables_and_naming
Work on variables and naming
2 parents 2fa1a63 + 15305b0 commit 7276438

13 files changed

Lines changed: 51 additions & 58 deletions

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
cmake_minimum_required(VERSION 3.21)
1+
cmake_minimum_required(VERSION 3.29)
2+
3+
# Disable modules support, this is broken with clang-tidy at the moment
4+
cmake_policy(SET CMP0155 OLD)
25

36
# This template attempts to be "fetch_content"-able
47
# so that it works well with tools like CPM or other
@@ -17,7 +20,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
1720
# Set the project name and language
1821
project(
1922
myproject
20-
VERSION 0.0.1
23+
VERSION 0.0.2
2124
DESCRIPTION ""
2225
HOMEPAGE_URL "%%myurl%%"
2326
LANGUAGES CXX C)

Dependencies.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ function(myproject_setup_dependencies)
99
# already been provided to us by a parent project
1010

1111
if(NOT TARGET fmtlib::fmtlib)
12-
cpmaddpackage("gh:fmtlib/fmt#11.1.4")
12+
cpmaddpackage("gh:fmtlib/fmt#12.1.0")
1313
endif()
1414

1515
if(NOT TARGET spdlog::spdlog)
1616
cpmaddpackage(
1717
NAME
1818
spdlog
1919
VERSION
20-
1.15.2
20+
1.17.0
2121
GITHUB_REPOSITORY
2222
"gabime/spdlog"
2323
OPTIONS
2424
"SPDLOG_FMT_EXTERNAL ON")
2525
endif()
2626

2727
if(NOT TARGET Catch2::Catch2WithMain)
28-
cpmaddpackage("gh:catchorg/Catch2@3.8.1")
28+
cpmaddpackage("gh:catchorg/Catch2@3.12.0")
2929
endif()
3030

3131
if(NOT TARGET CLI11::CLI11)
32-
cpmaddpackage("gh:CLIUtils/CLI11@2.5.0")
32+
cpmaddpackage("gh:CLIUtils/CLI11@2.6.1")
3333
endif()
3434

3535
if(NOT TARGET ftxui::screen)
36-
cpmaddpackage("gh:ArthurSonzogni/FTXUI@6.0.2")
36+
cpmaddpackage("gh:ArthurSonzogni/FTXUI@6.1.9")
3737
endif()
3838

3939
if(NOT TARGET tools::tools)

ProjectOptions.cmake

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ macro(myproject_setup_options)
7373
if(NOT PROJECT_IS_TOP_LEVEL OR myproject_PACKAGING_MAINTAINER_MODE)
7474
option(myproject_ENABLE_IPO "Enable IPO/LTO" OFF)
7575
option(myproject_WARNINGS_AS_ERRORS "Treat Warnings As Errors" OFF)
76-
option(myproject_ENABLE_USER_LINKER "Enable user-selected linker" OFF)
7776
option(myproject_ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" OFF)
7877
option(myproject_ENABLE_SANITIZER_LEAK "Enable leak sanitizer" OFF)
7978
option(myproject_ENABLE_SANITIZER_UNDEFINED "Enable undefined sanitizer" OFF)
@@ -87,7 +86,6 @@ macro(myproject_setup_options)
8786
else()
8887
option(myproject_ENABLE_IPO "Enable IPO/LTO" ON)
8988
option(myproject_WARNINGS_AS_ERRORS "Treat Warnings As Errors" ON)
90-
option(myproject_ENABLE_USER_LINKER "Enable user-selected linker" OFF)
9189
option(myproject_ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" ${SUPPORTS_ASAN})
9290
option(myproject_ENABLE_SANITIZER_LEAK "Enable leak sanitizer" OFF)
9391
option(myproject_ENABLE_SANITIZER_UNDEFINED "Enable undefined sanitizer" ${SUPPORTS_UBSAN})
@@ -104,7 +102,6 @@ macro(myproject_setup_options)
104102
mark_as_advanced(
105103
myproject_ENABLE_IPO
106104
myproject_WARNINGS_AS_ERRORS
107-
myproject_ENABLE_USER_LINKER
108105
myproject_ENABLE_SANITIZER_ADDRESS
109106
myproject_ENABLE_SANITIZER_LEAK
110107
myproject_ENABLE_SANITIZER_UNDEFINED
@@ -170,13 +167,10 @@ macro(myproject_local_options)
170167
""
171168
"")
172169

173-
# Linker and sanitizers not supported in Emscripten
174-
if(NOT EMSCRIPTEN)
175-
if(myproject_ENABLE_USER_LINKER)
176-
include(cmake/Linker.cmake)
177-
myproject_configure_linker(myproject_options)
178-
endif()
170+
include(cmake/Linker.cmake)
171+
# Must configure each target with linker options, we're avoiding setting it globally for now
179172

173+
if(NOT EMSCRIPTEN)
180174
include(cmake/Sanitizers.cmake)
181175
myproject_enable_sanitizers(
182176
myproject_options

cmake/CPM.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#
33
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
44

5-
set(CPM_DOWNLOAD_VERSION 0.40.8)
6-
set(CPM_HASH_SUM "78ba32abdf798bc616bab7c73aac32a17bbd7b06ad9e26a6add69de8f3ae4791")
5+
set(CPM_DOWNLOAD_VERSION 0.42.1)
6+
set(CPM_HASH_SUM "f3a6dcc6a04ce9e7f51a127307fa4f699fb2bade357a8eb4c5b45df76e1dc6a5")
77

88
if(CPM_SOURCE_CACHE)
99
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")

cmake/Linker.cmake

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
macro(myproject_configure_linker project_name)
2-
include(CheckCXXCompilerFlag)
3-
4-
set(USER_LINKER_OPTION
5-
"lld"
2+
set(myproject_USER_LINKER_OPTION
3+
"DEFAULT"
64
CACHE STRING "Linker to be used")
7-
set(USER_LINKER_OPTION_VALUES "lld" "gold" "bfd" "mold")
8-
set_property(CACHE USER_LINKER_OPTION PROPERTY STRINGS ${USER_LINKER_OPTION_VALUES})
5+
set(myproject_USER_LINKER_OPTION_VALUES "DEFAULT" "SYSTEM" "LLD" "GOLD" "BFD" "MOLD" "SOLD" "APPLE_CLASSIC" "MSVC")
6+
set_property(CACHE myproject_USER_LINKER_OPTION PROPERTY STRINGS ${myproject_USER_LINKER_OPTION_VALUES})
97
list(
108
FIND
11-
USER_LINKER_OPTION_VALUES
12-
${USER_LINKER_OPTION}
13-
USER_LINKER_OPTION_INDEX)
9+
myproject_USER_LINKER_OPTION_VALUES
10+
${myproject_USER_LINKER_OPTION}
11+
myproject_USER_LINKER_OPTION_INDEX)
1412

15-
if(${USER_LINKER_OPTION_INDEX} EQUAL -1)
13+
if(${myproject_USER_LINKER_OPTION_INDEX} EQUAL -1)
1614
message(
1715
STATUS
18-
"Using custom linker: '${USER_LINKER_OPTION}', explicitly supported entries are ${USER_LINKER_OPTION_VALUES}")
19-
endif()
20-
21-
if(NOT myproject_ENABLE_USER_LINKER)
22-
return()
16+
"Using custom linker: '${myproject_USER_LINKER_OPTION}', explicitly supported entries are ${myproject_USER_LINKER_OPTION_VALUES}")
2317
endif()
2418

25-
set(LINKER_FLAG "-fuse-ld=${USER_LINKER_OPTION}")
26-
27-
check_cxx_compiler_flag(${LINKER_FLAG} CXX_SUPPORTS_USER_LINKER)
28-
if(CXX_SUPPORTS_USER_LINKER)
29-
target_compile_options(${project_name} INTERFACE ${LINKER_FLAG})
30-
endif()
19+
set_target_properties(${project_name} PROPERTIES LINKER_TYPE "${myproject_USER_LINKER_OPTION}")
3120
endmacro()

cmake/StandardProjectSettings.cmake

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1919

2020
# Enhance error reporting and compiler messages
2121
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
22-
if(WIN32)
23-
# On Windows cuda nvcc uses cl and not clang
2422
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fcolor-diagnostics> $<$<COMPILE_LANGUAGE:CXX>:-fcolor-diagnostics>)
25-
else()
26-
add_compile_options(-fcolor-diagnostics)
27-
endif()
2823
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
29-
if(WIN32)
30-
# On Windows cuda nvcc uses cl and not gcc
3124
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fdiagnostics-color=always>
3225
$<$<COMPILE_LANGUAGE:CXX>:-fdiagnostics-color=always>)
33-
else()
34-
add_compile_options(-fdiagnostics-color=always)
35-
endif()
3626
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER 1900)
3727
add_compile_options(/diagnostics:column)
3828
else()
@@ -42,4 +32,4 @@ endif()
4232

4333
# run vcvarsall when msvc is used
4434
include("${CMAKE_CURRENT_LIST_DIR}/VCEnvironment.cmake")
45-
run_vcvarsall()
35+
myproject_run_vcvarsall()

cmake/StaticAnalyzers.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ macro(myproject_enable_cppcheck WARNINGS_AS_ERRORS CPPCHECK_OPTIONS)
4747
list(APPEND CMAKE_CXX_CPPCHECK --error-exitcode=2)
4848
endif()
4949
else()
50-
message(${WARNING_MESSAGE} "cppcheck requested but executable not found")
50+
message(WARNING "cppcheck requested but executable not found")
5151
endif()
5252
endmacro()
5353

@@ -100,7 +100,7 @@ macro(myproject_enable_clang_tidy target WARNINGS_AS_ERRORS)
100100
message("Also setting clang-tidy globally")
101101
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_OPTIONS})
102102
else()
103-
message(${WARNING_MESSAGE} "clang-tidy requested but executable not found")
103+
message(WARNING "clang-tidy requested but executable not found")
104104
endif()
105105
endmacro()
106106

@@ -109,6 +109,6 @@ macro(myproject_enable_include_what_you_use)
109109
if(INCLUDE_WHAT_YOU_USE)
110110
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${INCLUDE_WHAT_YOU_USE})
111111
else()
112-
message(${WARNING_MESSAGE} "include-what-you-use requested but executable not found")
112+
message(WARNING "include-what-you-use requested but executable not found")
113113
endif()
114114
endmacro()

cmake/Tests.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function(myproject_enable_coverage project_name)
22
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
3-
target_compile_options(${project_name} INTERFACE --coverage -O0 -g)
3+
target_compile_options(${project_name} INTERFACE --coverage -g)
44
target_link_libraries(${project_name} INTERFACE --coverage)
55
endif()
66
endfunction()

cmake/VCEnvironment.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include("${CMAKE_CURRENT_LIST_DIR}/Utilities.cmake")
22

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

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

@@ -43,7 +43,7 @@ function(run_vcvarsall)
4343

4444
if(EXISTS ${VCVARSALL_FILE})
4545
# detect the architecture
46-
detect_architecture()
46+
myproject_detect_architecture()
4747

4848
# run vcvarsall and print the environment variables
4949
message(STATUS "Running `${VCVARSALL_FILE} ${VCVARSALL_ARCH}` to set up the MSVC environment")

fuzz_test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ target_link_libraries(
1313
-fsanitize=fuzzer)
1414
target_compile_options(fuzz_tester PRIVATE -fsanitize=fuzzer)
1515

16+
17+
myproject_configure_linker(fuzz_tester)
18+
1619
# Allow short runs during automated testing to see if something new breaks
1720
set(FUZZ_RUNTIME
1821
10

0 commit comments

Comments
 (0)