Skip to content

Commit 9088c7e

Browse files
committed
CMakeLists.txt
1 parent 6913165 commit 9088c7e

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

CMakeLists.txt

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
cmake_minimum_required(VERSION 3.15) # Has to be 3.15+ because of this: https://cmake.org/cmake/help/latest/policy/CMP0057.html
2-
project(cpputils LANGUAGES CXX)
2+
3+
set(TARGET_NAME cpputils)
4+
project(${TARGET_NAME} LANGUAGES CXX)
35

46
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
57

@@ -28,49 +30,61 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "")
2830
set(CMAKE_C_FLAGS_RELWITHDEBINFO "")
2931

3032
# Set the library as static
31-
add_library(cpputils STATIC ${SOURCES} ${HEADERS})
33+
add_library(${TARGET_NAME} STATIC ${SOURCES} ${HEADERS})
34+
35+
# Set output directory to the desired one, without the Release/Debug sudirs that MSBuild adds by default
36+
if (DEFINED OUTPUT_DIR)
37+
get_property(current_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS)
38+
foreach(TARGET ${current_targets})
39+
set_target_properties(${TARGET} PROPERTIES
40+
RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR}/$<0:>
41+
LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR}/$<0:>
42+
ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIR}/$<0:>
43+
)
44+
endforeach()
45+
endif()
3246

33-
target_sources(cpputils PRIVATE
47+
target_sources(${TARGET_NAME} PRIVATE
3448
system/ctimeelapsed.cpp
3549
system/processfilepath.cpp
3650
system/consoleapplicationexithandler.cpp
3751
system/timing.cpp
3852
)
3953

4054
if (WIN32)
41-
target_sources(cpputils PRIVATE
55+
target_sources(${TARGET_NAME} PRIVATE
4256
system/win_utils.cpp
4357
)
4458
endif()
4559

4660
# Add include directories
47-
target_include_directories(cpputils PUBLIC
61+
target_include_directories(${TARGET_NAME} PUBLIC
4862
${CMAKE_CURRENT_LIST_DIR}/
4963
${CMAKE_CURRENT_LIST_DIR}/../cpp-template-utils/
5064
)
5165

5266
# Platform-specific flags
5367
if(MSVC)
5468
# Visual Studio specific flags
55-
target_compile_options(cpputils PRIVATE
69+
target_compile_options(${TARGET_NAME} PRIVATE
5670
$<$<CONFIG:Debug>:/Ob2>
5771
$<$<OR:$<CONFIG:RelWithDebInfo>,$<CONFIG:Release>>:/GS- /O2>
5872
/MP /Zi
5973
/std:c++latest /permissive- /Zc:__cplusplus /Zc:char8_t
6074
/W4 /FS /Gy
6175
)
62-
target_link_options(cpputils PRIVATE
76+
target_link_options(${TARGET_NAME} PRIVATE
6377
$<$<OR:$<CONFIG:RelWithDebInfo>,$<CONFIG:Release>>:/OPT:REF /OPT:ICF>
6478
$<$<CONFIG:Debug>:/INCREMENTAL>
6579
/DEBUG:FASTLINK
6680
)
67-
target_compile_definitions(cpputils PRIVATE
81+
target_compile_definitions(${TARGET_NAME} PRIVATE
6882
WIN32_LEAN_AND_MEAN
6983
NOMINMAX
7084
)
7185
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
7286
# Unix-like specific flags
73-
target_compile_options(cpputils PRIVATE
87+
target_compile_options(${TARGET_NAME} PRIVATE
7488
-std=c++2b
7589
-pedantic-errors
7690
-Wall -Wextra -Wdelete-non-virtual-dtor -Werror=duplicated-cond
@@ -85,14 +99,14 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
8599
-Wno-missing-include-dirs -Wno-undef
86100
$<$<OR:$<CONFIG:RelWithDebInfo>,$<CONFIG:Release>>:-O3>
87101
)
88-
target_link_options(cpputils PRIVATE -fuse-ld=gold)
102+
target_link_options(${TARGET_NAME} PRIVATE -fuse-ld=gold)
89103

90104
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
91-
target_compile_options(cpputils PRIVATE -fconcepts)
105+
target_compile_options(${TARGET_NAME} PRIVATE -fconcepts)
92106
endif()
93107

94108
# Add defines based on configuration
95-
target_compile_definitions(cpputils PRIVATE
109+
target_compile_definitions(${TARGET_NAME} PRIVATE
96110
"$<$<CONFIG:Release>:NDEBUG=1>"
97111
"$<$<CONFIG:Debug>:_DEBUG>"
98112
)

0 commit comments

Comments
 (0)