Skip to content

Commit 18c392e

Browse files
committed
format CMakeLists.txt to have consistent style
1 parent 9daaecd commit 18c392e

5 files changed

Lines changed: 134 additions & 136 deletions

File tree

CMakeLists.txt

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,79 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
CMAKE_MINIMUM_REQUIRED(VERSION 3.15)
22

33
# Set the project name to your project name, my project isn't very descriptive
4-
project(myproject CXX)
5-
include(cmake/StandardProjectSettings.cmake)
6-
include(cmake/PreventInSourceBuilds.cmake)
4+
PROJECT(myproject CXX)
5+
INCLUDE(cmake/StandardProjectSettings.cmake)
6+
INCLUDE(cmake/PreventInSourceBuilds.cmake)
77

8-
include(cmake/CodeFormat.cmake)
8+
INCLUDE(cmake/CodeFormat.cmake)
99

1010
# Link this 'library' to set the c++ standard / compile-time options requested
11-
add_library(project_options INTERFACE)
12-
target_compile_features(project_options INTERFACE cxx_std_17)
11+
ADD_LIBRARY(project_options INTERFACE)
12+
TARGET_COMPILE_FEATURES(project_options INTERFACE cxx_std_17)
1313

14-
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
15-
option(ENABLE_BUILD_WITH_TIME_TRACE "Enable -ftime-trace to generate time tracing .json files on clang" OFF)
16-
if(ENABLE_BUILD_WITH_TIME_TRACE)
17-
target_compile_options(project_options INTERFACE -ftime-trace)
18-
endif()
19-
endif()
14+
IF(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
15+
OPTION(ENABLE_BUILD_WITH_TIME_TRACE "Enable -ftime-trace to generate time tracing .json files on clang" OFF)
16+
IF(ENABLE_BUILD_WITH_TIME_TRACE)
17+
TARGET_COMPILE_OPTIONS(project_options INTERFACE -ftime-trace)
18+
ENDIF()
19+
ENDIF()
2020

2121
# Link this 'library' to use the warnings specified in CompilerWarnings.cmake
22-
add_library(project_warnings INTERFACE)
22+
ADD_LIBRARY(project_warnings INTERFACE)
2323

2424
# enable cache system
25-
include(cmake/Cache.cmake)
25+
INCLUDE(cmake/Cache.cmake)
2626

2727
# standard compiler warnings
28-
include(cmake/CompilerWarnings.cmake)
29-
set_project_warnings(project_warnings)
28+
INCLUDE(cmake/CompilerWarnings.cmake)
29+
SET_PROJECT_WARNINGS(project_warnings)
3030

3131
# sanitizer options if supported by compiler
32-
include(cmake/Sanitizers.cmake)
33-
enable_sanitizers(project_options)
32+
INCLUDE(cmake/Sanitizers.cmake)
33+
ENABLE_SANITIZERS(project_options)
3434

3535
# enable doxygen
36-
include(cmake/Doxygen.cmake)
37-
enable_doxygen()
36+
INCLUDE(cmake/Doxygen.cmake)
37+
ENABLE_DOXYGEN()
3838

3939
# allow for static analysis options
40-
include(cmake/StaticAnalyzers.cmake)
40+
INCLUDE(cmake/StaticAnalyzers.cmake)
4141

42-
option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF)
43-
option(ENABLE_TESTING "Enable Test Builds" ON)
44-
option(ENABLE_FUZZING "Enable Fuzzing Builds" OFF)
42+
OPTION(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF)
43+
OPTION(ENABLE_TESTING "Enable Test Builds" ON)
44+
OPTION(ENABLE_FUZZING "Enable Fuzzing Builds" OFF)
4545

4646
# Very basic PCH example
47-
option(ENABLE_PCH "Enable Precompiled Headers" OFF)
48-
if(ENABLE_PCH)
49-
# This sets a global PCH parameter, each project will build its own PCH, which is a good idea if any #define's change
50-
#
51-
# consider breaking this out per project as necessary
52-
target_precompile_headers(
53-
project_options
54-
INTERFACE
55-
<vector>
56-
<string>
57-
<map>
58-
<utility>)
59-
endif()
47+
OPTION(ENABLE_PCH "Enable Precompiled Headers" OFF)
48+
IF(ENABLE_PCH)
49+
# This sets a global PCH parameter, each project will build its own PCH, which is a good idea if any #define's change
50+
#
51+
# consider breaking this out per project as necessary
52+
TARGET_PRECOMPILE_HEADERS(
53+
project_options
54+
INTERFACE
55+
<vector>
56+
<string>
57+
<map>
58+
<utility>)
59+
ENDIF()
6060

6161
# Set up some extra Conan dependencies based on our needs before loading Conan
62-
set(CONAN_EXTRA_REQUIRES "")
63-
set(CONAN_EXTRA_OPTIONS "")
62+
SET(CONAN_EXTRA_REQUIRES "")
63+
SET(CONAN_EXTRA_OPTIONS "")
6464

65-
include(cmake/Conan.cmake)
66-
run_conan()
65+
INCLUDE(cmake/Conan.cmake)
66+
RUN_CONAN()
6767

68-
if(ENABLE_TESTING)
69-
enable_testing()
70-
message("Building Tests. Be sure to check out test/constexpr_tests for constexpr testing")
71-
add_subdirectory(test)
72-
endif()
68+
IF(ENABLE_TESTING)
69+
ENABLE_TESTING()
70+
MESSAGE("Building Tests. Be sure to check out test/constexpr_tests for constexpr testing")
71+
ADD_SUBDIRECTORY(test)
72+
ENDIF()
7373

74-
if(ENABLE_FUZZING)
75-
message("Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
76-
add_subdirectory(fuzz_test)
77-
endif()
78-
79-
add_subdirectory(src)
74+
IF(ENABLE_FUZZING)
75+
MESSAGE("Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
76+
ADD_SUBDIRECTORY(fuzz_test)
77+
ENDIF()
8078

79+
ADD_SUBDIRECTORY(src)

fuzz_test/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# A fuzz test runs until it finds an error. This particular one is going to rely on libFuzzer.
22
#
33

4-
add_executable(fuzz_tester fuzz_tester.cpp)
5-
target_link_libraries(
6-
fuzz_tester
7-
PRIVATE project_options
8-
project_warnings
9-
CONAN_PKG::fmt
10-
-coverage
11-
-fsanitize=fuzzer,undefined,address)
12-
target_compile_options(fuzz_tester PRIVATE -fsanitize=fuzzer,undefined,address)
4+
ADD_EXECUTABLE(fuzz_tester fuzz_tester.cpp)
5+
TARGET_LINK_LIBRARIES(
6+
fuzz_tester
7+
PRIVATE project_options
8+
project_warnings
9+
CONAN_PKG::fmt
10+
-coverage
11+
-fsanitize=fuzzer,undefined,address)
12+
TARGET_COMPILE_OPTIONS(fuzz_tester PRIVATE -fsanitize=fuzzer,undefined,address)
1313

1414
# Allow short runs during automated testing to see if something new breaks
15-
set(FUZZ_RUNTIME
15+
SET(FUZZ_RUNTIME
1616
10
1717
CACHE STRING "Number of seconds to run fuzz tests during ctest run") # Default of 10 seconds
1818

19-
add_test(NAME fuzz_tester_run COMMAND fuzz_tester -max_total_time=${FUZZ_RUNTIME})
19+
ADD_TEST(NAME fuzz_tester_run COMMAND fuzz_tester -max_total_time=${FUZZ_RUNTIME})

test/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
add_subdirectory(catch2)
2-
add_subdirectory(gtest)
1+
ADD_SUBDIRECTORY(catch2)
2+
ADD_SUBDIRECTORY(gtest)

test/catch2/CMakeLists.txt

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
1-
include(CTest)
2-
include(Catch)
1+
INCLUDE(CTest)
2+
INCLUDE(Catch)
33

4-
add_library(catch_main STATIC catch_main.cpp)
5-
target_link_libraries(catch_main PUBLIC CONAN_PKG::catch2)
6-
target_link_libraries(catch_main PRIVATE project_options)
4+
ADD_LIBRARY(catch_main STATIC catch_main.cpp)
5+
TARGET_LINK_LIBRARIES(catch_main PUBLIC CONAN_PKG::catch2)
6+
TARGET_LINK_LIBRARIES(catch_main PRIVATE project_options)
77

8-
add_executable(catch_tests tests.cpp)
9-
target_link_libraries(catch_tests PRIVATE project_warnings project_options catch_main)
8+
ADD_EXECUTABLE(catch_tests tests.cpp)
9+
TARGET_LINK_LIBRARIES(catch_tests PRIVATE project_warnings project_options catch_main)
1010

1111
# automatically discover tests that are defined in catch based test files you can modify the unittests. Set TEST_PREFIX
1212
# to whatever you want, or use different for different binaries
13-
catch_discover_tests(
14-
catch_tests
15-
TEST_PREFIX
16-
"catch_unittests."
17-
REPORTER
18-
xml
19-
OUTPUT_DIR
20-
.
21-
OUTPUT_PREFIX
22-
"catch_unittests."
23-
OUTPUT_SUFFIX
24-
.xml)
13+
CATCH_DISCOVER_TESTS(
14+
catch_tests
15+
TEST_PREFIX
16+
"catch_unittests."
17+
REPORTER
18+
xml
19+
OUTPUT_DIR
20+
.
21+
OUTPUT_PREFIX
22+
"catch_unittests."
23+
OUTPUT_SUFFIX
24+
.xml)
2525

2626
# Add a file containing a set of constexpr tests
27-
add_executable(catch_constexpr_tests constexpr_tests.cpp)
28-
target_link_libraries(catch_constexpr_tests PRIVATE project_options project_warnings catch_main)
27+
ADD_EXECUTABLE(catch_constexpr_tests constexpr_tests.cpp)
28+
TARGET_LINK_LIBRARIES(catch_constexpr_tests PRIVATE project_options project_warnings catch_main)
2929

30-
catch_discover_tests(
31-
catch_constexpr_tests
32-
TEST_PREFIX
33-
"catch_constexpr."
34-
REPORTER
35-
xml
36-
OUTPUT_DIR
37-
.
38-
OUTPUT_PREFIX
39-
"catch_constexpr."
40-
OUTPUT_SUFFIX
41-
.xml)
30+
CATCH_DISCOVER_TESTS(
31+
catch_constexpr_tests
32+
TEST_PREFIX
33+
"catch_constexpr."
34+
REPORTER
35+
xml
36+
OUTPUT_DIR
37+
.
38+
OUTPUT_PREFIX
39+
"catch_constexpr."
40+
OUTPUT_SUFFIX
41+
.xml)
4242

4343
# Disable the constexpr portion of the test, and build again this allows us to have an executable that we can debug when
4444
# things go wrong with the constexpr testing
45-
add_executable(catch_relaxed_constexpr_tests constexpr_tests.cpp)
46-
target_link_libraries(catch_relaxed_constexpr_tests PRIVATE project_options project_warnings catch_main)
47-
target_compile_definitions(catch_relaxed_constexpr_tests PRIVATE -DCATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
45+
ADD_EXECUTABLE(catch_relaxed_constexpr_tests constexpr_tests.cpp)
46+
TARGET_LINK_LIBRARIES(catch_relaxed_constexpr_tests PRIVATE project_options project_warnings catch_main)
47+
TARGET_COMPILE_DEFINITIONS(catch_relaxed_constexpr_tests PRIVATE -DCATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
4848

49-
catch_discover_tests(
50-
catch_relaxed_constexpr_tests
51-
TEST_PREFIX
52-
"catch_relaxed_constexpr."
53-
REPORTER
54-
xml
55-
OUTPUT_DIR
56-
.
57-
OUTPUT_PREFIX
58-
"catch_relaxed_constexpr."
59-
OUTPUT_SUFFIX
60-
.xml)
49+
CATCH_DISCOVER_TESTS(
50+
catch_relaxed_constexpr_tests
51+
TEST_PREFIX
52+
"catch_relaxed_constexpr."
53+
REPORTER
54+
xml
55+
OUTPUT_DIR
56+
.
57+
OUTPUT_PREFIX
58+
"catch_relaxed_constexpr."
59+
OUTPUT_SUFFIX
60+
.xml)

test/gtest/CMakeLists.txt

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
include(CTest)
2-
include(GoogleTest)
1+
INCLUDE(CTest)
2+
INCLUDE(GoogleTest)
33

4-
add_library(gtest_main STATIC gtest_main.cpp)
5-
target_link_libraries(gtest_main PUBLIC CONAN_PKG::gtest)
6-
target_link_libraries(gtest_main PRIVATE project_options)
4+
ADD_LIBRARY(gtest_main STATIC gtest_main.cpp)
5+
TARGET_LINK_LIBRARIES(gtest_main PUBLIC CONAN_PKG::gtest)
6+
TARGET_LINK_LIBRARIES(gtest_main PRIVATE project_options)
77

8-
add_executable(gtest_tests tests.cpp)
9-
target_link_libraries(gtest_tests PRIVATE project_warnings project_options gtest_main)
8+
ADD_EXECUTABLE(gtest_tests tests.cpp)
9+
TARGET_LINK_LIBRARIES(gtest_tests PRIVATE project_warnings project_options gtest_main)
1010

1111
# automatically discover tests that are defined in gtest based test files you can modify the unittests. Set TEST_PREFIX
1212
# to whatever you want, or use different for different binaries
13-
gtest_discover_tests(
14-
gtest_tests
15-
TEST_PREFIX
16-
"gtest_unittests."
17-
XML_OUTPUT_DIR
18-
.)
13+
GTEST_DISCOVER_TESTS(
14+
gtest_tests
15+
TEST_PREFIX
16+
"gtest_unittests."
17+
XML_OUTPUT_DIR
18+
.)
1919

2020
# Add a file containing a set of constexpr tests
21-
add_executable(gtest_constexpr_tests constexpr_tests.cpp)
22-
target_link_libraries(gtest_constexpr_tests PRIVATE project_options project_warnings gtest_main)
21+
ADD_EXECUTABLE(gtest_constexpr_tests constexpr_tests.cpp)
22+
TARGET_LINK_LIBRARIES(gtest_constexpr_tests PRIVATE project_options project_warnings gtest_main)
2323

24-
gtest_discover_tests(
25-
gtest_constexpr_tests
26-
TEST_PREFIX
27-
"gtest_constexpr."
28-
XML_OUTPUT_DIR
29-
.)
24+
GTEST_DISCOVER_TESTS(
25+
gtest_constexpr_tests
26+
TEST_PREFIX
27+
"gtest_constexpr."
28+
XML_OUTPUT_DIR
29+
.)
3030

3131
# GTest doesn't support switching between constexpr and non-constexpr versions of tests.
32-

0 commit comments

Comments
 (0)