-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
128 lines (104 loc) · 3 KB
/
CMakeLists.txt
File metadata and controls
128 lines (104 loc) · 3 KB
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
cmake_minimum_required(VERSION 3.10)
# When stable set project version to 1.0.0
project(project_name VERSION 0.0.0 LANGUAGES C CXX)
if (CMAKE_C_COMPILER)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
endif()
if (CMAKE_CXX_COMPILER)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
if (CMAKE_C_COMPILER)
message(STATUS "C Compiler: ${CMAKE_C_COMPILER_ID}")
endif()
if (CMAKE_CXX_COMPILER)
message(STATUS "C++ Compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()
if(WIN32)
#find_package(unofficial-sodium CONFIG REQUIRED)
#find_package(FLTK CONFIG REQUIRED)
else()
#find_package(FLTK REQUIRED)
#find_package(PkgConfig REQUIRED)
#pkg_check_modules(SODIUM REQUIRED libsodium)
endif()
set(SOURCES)
if (CMAKE_C_COMPILER)
list(APPEND SOURCES
src/main.c
# add other C files here
)
endif()
if (CMAKE_CXX_COMPILER)
list(APPEND SOURCES
# src/main.cpp
# add other C++ files here
)
endif()
# Default exec name
if(EXECUTABLE_OUTPUT_NAME)
set(EXECUTABLE_OUTPUT_NAME "projectname")
endif()
add_executable(project_name ${SOURCES})
set_target_properties(project_name PROPERTIES OUTPUT_NAME ${EXECUTABLE_OUTPUT_NAME})
if(WIN32)
#set_target_properties(project_name PROPERTIES WIN32_EXECUTABLE TRUE)
endif()
if(WIN32)
#target_link_libraries(project_name PRIVATE unofficial-sodium::sodium)
else()
#target_include_directories(project_name PRIVATE ${SODIUM_INCLUDE_DIRS})
#target_link_libraries(project_name PRIVATE ${SODIUM_LIBRARIES})
endif()
target_include_directories(project_name PRIVATE
${PROJECT_SOURCE_DIR}/include
)
target_compile_definitions(project_name PRIVATE
PROJECT_VERSION=\"${PROJECT_VERSION}\"
)
# ==============================
# Compiler-specific configuration
# ==============================
if (MSVC)
# Debug
target_compile_options(project_name PRIVATE
$<$<CONFIG:Debug>:/Zi /Od>
)
target_link_options(project_name PRIVATE
$<$<CONFIG:Debug>:/DEBUG>
)
target_compile_definitions(project_name PRIVATE
$<$<CONFIG:Debug>:DEBUG_MODE=1>
)
# Release
target_compile_options(project_name PRIVATE
$<$<CONFIG:Release>:/O2>
)
target_compile_definitions(project_name PRIVATE
$<$<CONFIG:Release>:NDEBUG>
)
else() # GCC / Clang
# Debug
target_compile_options(project_name PRIVATE
$<$<CONFIG:Debug>:-g -O0 -fno-omit-frame-pointer>
)
target_compile_definitions(project_name PRIVATE
$<$<CONFIG:Debug>:DEBUG_MODE=1>
)
# Optional ASAN (ONLY here)
target_compile_options(project_name PRIVATE
$<$<CONFIG:Debug>:-fsanitize=address>
)
target_link_options(project_name PRIVATE
$<$<CONFIG:Debug>:-fsanitize=address>
)
# Release
target_compile_options(project_name PRIVATE
$<$<CONFIG:Release>:-O3>
)
target_compile_definitions(project_name PRIVATE
$<$<CONFIG:Release>:NDEBUG>
)
endif()