-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
147 lines (122 loc) · 5.85 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
################################################################################
# CMake file for new projects. #
# #
# (C) 2024 Marc Schöndorf #
# Licensed under the zlib License. See LICENSE.md #
################################################################################
cmake_minimum_required(VERSION 3.25)
# TODO: Check if needed for macOS
#set(CMAKE_OSX_DEPLOYMENT_TARGET "12.0" CACHE STRING "Minimum OS X deployment version")
###########################################################
# Set options for sub projects
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) # Needed to set options of subprojects inside parent project
###########################################################
# Use C++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED true)
set(CMAKE_CXX_EXTENSIONS false) # Don't use GNU++
###########################################################
# Set options for libs
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) # Needed to set options from subprojects in parent project
###########################################################
# Set build output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/debug")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin/debug")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/bin/release")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/debug")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin/debug")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/bin/release")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/debug")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin/debug")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/bin/release")
###########################################################
# Our project
project("Project"
VERSION 0.1.0
DESCRIPTION "Project description."
LANGUAGES CXX
)
# Main library
#add_library("${PROJECT_NAME}"
# include/Main.hpp
# src/Main.cpp
#)
# Main executable
add_executable("${PROJECT_NAME}"
include/Main.hpp
src/Main.cpp
)
# The projects include directories
target_include_directories("${PROJECT_NAME}" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
###########################################################
# Project versioning
configure_file("cmake additional/ProjectVersion.hpp.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/include/ProjectVersion.hpp")
###########################################################
# Sub-projects
#add_subdirectory("examples/simple example")
###########################################################
# Use a lib
#add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/lib/CLI11")
#target_include_directories("${PROJECT_NAME}" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/lib/CLI11/include")
#target_link_directories("${PROJECT_NAME}" PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/lib/CLI11/src")
#target_link_libraries("${PROJECT_NAME}" PRIVATE CLI11)
#############################################################
# Optimization settings
if (WIN32)
if (MSVC)
target_compile_options("${PROJECT_NAME}" PRIVATE "/O2")
endif()
else()
target_compile_options("${PROJECT_NAME}" PRIVATE "-O3")
endif()
#############################################################
# Compiler settings (example)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # GCC
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") # Do we compile for arm64?
#target_compile_options("${PROJECT_NAME}" PRIVATE "-march=armv8-a+crypto+crc")
#target_compile_options("${PROJECT_NAME}" PRIVATE "-ftree-vectorize")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "Win32")
#target_compile_options("${PROJECT_NAME}" PRIVATE "-march=native")
#target_compile_options("${PROJECT_NAME}" PRIVATE "-ftree-vectorize")
endif()
endif()
###########################################################
# Macro for removing /RTC flag in VisualStudio (incompatible with /O2 optimization)
macro(RemoveRTCFlagDebug_VS)
string(REGEX REPLACE "/RTC[^ ]*" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
endmacro()
macro(RemoveRTCFlagRelease_VS)
string(REGEX REPLACE "/RTC[^ ]*" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
endmacro()
###########################################################
# Enable a lot of warnings
if (WIN32)
if (MSVC)
RemoveRTCFlagDebug_VS()
RemoveRTCFlagRelease_VS()
target_compile_options("${PROJECT_NAME}" PRIVATE "/W3")
#target_compile_options("${PROJECT_NAME}" PRIVATE "/WX")
#target_compile_options("${PROJECT_NAME}" PRIVATE "/wd4244")
#target_compile_options("${PROJECT_NAME}" PRIVATE "/wd4267")
target_compile_options("${PROJECT_NAME}" PRIVATE "/D_CRT_SECURE_NO_WARNINGS")
endif()
# Force Win32 to UNICODE
target_compile_definitions("${PROJECT_NAME}" PRIVATE UNICODE _UNICODE)
#target_compile_options("${PROJECT_NAME}" PRIVATE "/utf-8")
else()
target_compile_options("${PROJECT_NAME}" PRIVATE "-Wall")
target_compile_options("${PROJECT_NAME}" PRIVATE "-Wextra")
target_compile_options("${PROJECT_NAME}" PRIVATE "-pedantic")
target_compile_options("${PROJECT_NAME}" PRIVATE "-Wmissing-declarations")
target_compile_options("${PROJECT_NAME}" PRIVATE "-Wdeprecated")
target_compile_options("${PROJECT_NAME}" PRIVATE "-Wshadow")
target_compile_options("${PROJECT_NAME}" PRIVATE "-Wsign-conversion")
endif()
###########################################################
# Helper for formatting and printing text with color
include("cmake additional/colorFormatting.cmake")
###########################################################
# Include summary file for printing various information
include("cmake additional/printSummary.cmake")
# Print the information
PRINT_SUMMARY()