Skip to content

Commit 2829f8c

Browse files
committed
CMakeLists.txt: remove usages of PROJECT_NAME as a target name (bad practice)
1 parent 841a245 commit 2829f8c

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

build/CMake/CMakeLists.txt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
3939
set(CMAKE_CXX_EXTENSIONS OFF)
4040

4141
# Alternatively we could have set the required C++ standard for a particular build target
42-
# target_compile_features(${PROJECT_NAME} PUBLIC c_std_17)
42+
# target_compile_features(test-executable PUBLIC c_std_17)
4343

4444
# Store the paths to some interesting directories in variables
4545
# (the repository's root is two folders higher than this CMakeLists file)
@@ -61,8 +61,9 @@ foreach (file ${SOURCE_FILES})
6161
print_message("source file = ${file}")
6262
endforeach()
6363

64-
# Defines a build target - the executable file and its dependencies (the source files collected above)
65-
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
64+
# Defines a build target - the executable file and its dependencies (the source files collected above).
65+
# First argument to add_executable is the name of the target.
66+
add_executable(test-executable ${SOURCE_FILES})
6667

6768
# Include CMake's FetchContent module
6869
include(FetchContent)
@@ -82,21 +83,21 @@ FetchContent_Declare(
8283
# This step is what CMake refers to as "populating the content" — turning the declaration into actual usable files.
8384
FetchContent_MakeAvailable(Catch2)
8485
# Link to the Catch2 static library
85-
target_link_libraries(${PROJECT_NAME} PRIVATE Catch2::Catch2WithMain)
86+
target_link_libraries(test-executable PRIVATE Catch2::Catch2WithMain)
8687

8788
if (VISUAL_STUDIO)
8889
# set our project as the startup project in the Visual Studio solution
8990
set_property(
9091
DIRECTORY "${PROJECT_SOURCE_DIR}"
91-
PROPERTY VS_STARTUP_PROJECT "${PROJECT_NAME}")
92+
PROPERTY VS_STARTUP_PROJECT "test-executable")
9293

9394
# set Visual Studio Debug working directory to the repository's root directory
9495
set_target_properties(
95-
${PROJECT_NAME} PROPERTIES
96+
test-executable PROPERTIES
9697
VS_DEBUGGER_WORKING_DIRECTORY "${ROOT_DIR}")
9798
else() # CYGWIN MSYS2 *NIX environment is assumed below
9899
# Linking to libstdc++fs is required for use of the Filesystem library extensions in <experimental/filesystem>
99-
target_link_libraries(${PROJECT_NAME} PRIVATE "stdc++fs")
100+
target_link_libraries(test-executable PRIVATE "stdc++fs")
100101

101102
# extract standard libraries' search paths from the compiler
102103
execute_process(
@@ -111,15 +112,15 @@ else() # CYGWIN MSYS2 *NIX environment is assumed below
111112
print_message("CXX_STD_LIB_PATHS = ${CXX_STD_LIB_PATHS}")
112113

113114
# embed library search directories into the executable
114-
get_target_property(RPATH ${PROJECT_NAME} BUILD_RPATH)
115+
get_target_property(RPATH test-executable BUILD_RPATH)
115116
list(APPEND RPATH ${CXX_STD_LIB_PATHS})
116117

117118
set_target_properties(
118-
${PROJECT_NAME} PROPERTIES
119+
test-executable PROPERTIES
119120
BUILD_RPATH "${RPATH}")
120121

121122
set_target_properties(
122-
${PROJECT_NAME} PROPERTIES
123+
test-executable PROPERTIES
123124
INSTALL_RPATH "${RPATH}")
124125
endif()
125126

@@ -130,14 +131,14 @@ enable_testing()
130131

131132
# define tests
132133
add_test(
133-
NAME ${PROJECT_NAME}
134-
COMMAND $<TARGET_FILE:${PROJECT_NAME}>
134+
NAME test-executable
135+
COMMAND $<TARGET_FILE:test-executable>
135136
WORKING_DIRECTORY ${TEST_DIR})
136137

137138
print_message("-------------------- INSTALLATION --------------------")
138139

139140
# install the executable file to ${CMAKE_INSTALL_PREFIX}
140-
install(TARGETS ${PROJECT_NAME}
141+
install(TARGETS test-executable
141142
CONFIGURATIONS Release
142143
PERMISSIONS OWNER_READ
143144
GROUP_READ

0 commit comments

Comments
 (0)