-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
89 lines (70 loc) · 2.56 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
# Cmake params
cmake_minimum_required(VERSION 3.9)
# Export data for LSP
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# CPP params
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -pedantic -Werror")
# string(APPEND CMAKE_CXX_FLAGS " -Rpass-missed=loop-vectorize")
# string(APPEND CMAKE_CXX_FLAGS " -Rpass-analysis=loop-vectorize")
# Set cmake standard
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
# Speed up
set(UNITY_BUILD true)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -fno-omit-frame-pointer -fsanitize=address")
string(APPEND CMAKE_LINKER_FLAGS_DEBUG " -fno-omit-frame-pointer -fsanitize=address")
add_link_options(-fsanitize=address)
# string(APPEND CMAKE_CXX_FLAGS_DEBUG " -fsanitize=undefined")
# string(APPEND CMAKE_LINKER_FLAGS_DEBUG " -fsanitize=undefined")
# add_link_options(-fsanitize=undefined)
# string(APPEND CMAKE_CXX_FLAGS_DEBUG " -ftime-trace")
endif()
# Define project
project(app CXX)
file(GLOB SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*.cpp)
include_directories(includes)
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} algs)
# Add libs
add_subdirectory(cpp_algs libs/algs)
# SFML
# find_package(SFML 2 REQUIRED network audio graphics window system)
find_package(SFML 2.5.1 COMPONENTS graphics REQUIRED)
target_link_libraries(${PROJECT_NAME} sfml-graphics sfml-audio)
# # Use threads
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT})
find_package(TBB REQUIRED)
target_link_libraries(${PROJECT_NAME} ${TBB_IMPORTED_TARGETS})
find_package(X11 REQUIRED)
link_libraries(${X11_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${X11_LIBRARIES})
# # Use openmp if found
# option(USE_OPENMP "flag to use OpenMP for multithreading" ON)
# if(USE_OPENMP)
# find_package(OpenMP 3.0 COMPONENTS CXX)
# if (OpenMP_CXX_FOUND)
# message(STATUS "Building with OpenMP Multithreading.")
# else()
# message(STATUS "No OpenMP found, no multithreading.")
# endif()
# endif()
# Colored output
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options (-fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options (-fcolor-diagnostics)
endif ()
###########################
# compile_commands.json #
###########################
add_custom_target(
copy-compile-commands
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_CURRENT_LIST_DIR}
)