-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
85 lines (74 loc) · 3.16 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
cmake_minimum_required(VERSION 3.21)
# Create Project
project(MySort VERSION 0.1)
# ==================================================================================================
# Compiler and Linker Configuration
# --------------------------------------------------------------------------------------------------
# Set C++ standard to C++23
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(STACK_SIZE 268435456)
# MSVC
if(MSVC AND WIN32)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zi")
add_compile_options(/permissive- /Zc:forScope)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:${STACK_SIZE}")
# Clang
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Set different compile options for Release and Debug modes
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
if(WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,/STACK:${STACK_SIZE}")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-zstack-size=${STACK_SIZE}")
endif()
# GCC
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Set different compile options for Release and Debug modes
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
if(WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,${STACK_SIZE}")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-zstack-size=${STACK_SIZE}")
endif()
else()
message(FATAL_ERROR "Unsupported compiler")
endif()
# ==================================================================================================
# ==================================================================================================
# Target Configuration
# --------------------------------------------------------------------------------------------------
# Set the Target Name and Add Executable
set(TARGET_NAME mysort)
file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
add_executable(${TARGET_NAME} ${SOURCES})
# Specify Build Type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# Define Macros According to Build Type
if(CMAKE_BUILD_TYPE STREQUAL "Release")
target_compile_definitions(${TARGET_NAME} PRIVATE RELEASE_BUILD)
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(${TARGET_NAME} PRIVATE DEBUG_BUILD)
endif()
# Include MySort Header Files
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Install Yutils Library ---------------------------------------------------------------------------
add_subdirectory("vendor/Yutils")
# Link Yutils Library
target_link_libraries(${TARGET_NAME} PRIVATE Yutils::Yutils)
# Set Binary Output Path
if(NOT DEFINED OUTPUT_DIR)
set(OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif()
set_target_properties(
${TARGET_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
${OUTPUT_DIR}/bin/${CMAKE_BUILD_TYPE}/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR}
)
# ==================================================================================================