-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
118 lines (99 loc) · 3.91 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
cmake_minimum_required(VERSION 3.15)
# set the project name
project(DiscreteENN_TSP VERSION 1.0
DESCRIPTION
"A fast algorithm to find reasonable solutions to TSP"
LANGUAGES CXX)
### Require out-of-source builds
file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
if(EXISTS "${LOC_PATH}")
message(FATAL_ERROR "You cannot build in a source directory (or any directory with "
"CMakeLists.txt file). Please make a build subdirectory. Feel free to "
"remove CMakeCache.txt and CMakeFiles.")
endif()
# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
# # we default to Release build type
# if(NOT CMAKE_BUILD_TYPE)
# set(CMAKE_BUILD_TYPE "Debug")
# endif()
if (MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Wall -Wextra -pedantic)
endif()
file(GLOB HEADER_LIST CONFIGURE_DEPENDS
"${PROJECT_SOURCE_DIR}/include/*.hpp")
add_library(tsp_enn_lib)
target_sources(tsp_enn_lib
PRIVATE
"${PROJECT_SOURCE_DIR}/src/tsp_discrete_enn.cxx"
PUBLIC
"${HEADER_LIST}"
)
target_include_directories(tsp_enn_lib PUBLIC "${PROJECT_SOURCE_DIR}/include")
target_link_libraries(tsp_enn_lib PRIVATE
sfml-graphics
sfml-window
sfml-system
)
add_executable(tsp_enn "${PROJECT_SOURCE_DIR}/src/main.cpp" "${HEADER_LIST}")
target_include_directories(tsp_enn PUBLIC "${PROJECT_SOURCE_DIR}/include")
# target_compile_features(enn_tsp PRIVATE cxx_std_17)
target_compile_options(tsp_enn PRIVATE
$<$<CONFIG:Release>:-O3;-march=native;-mtune=native>
$<$<CONFIG:Debug>:-fsanitize=address,undefined,float-divide-by-zero,nullability;-fno-omit-frame-pointer;-Og;-g>
)
target_link_options(tsp_enn PRIVATE
$<$<CONFIG:Debug>:-fsanitize=address,undefined,float-divide-by-zero,nullability;-fno-omit-frame-pointer>
)
target_link_libraries(tsp_enn PRIVATE tsp_enn_lib)
install(TARGETS tsp_enn DESTINATION "${PROJECT_SOURCE_DIR}/bin")
# Copy to source directory
add_custom_target(
copy-compile-commands ALL
DEPENDS
${CMAKE_SOURCE_DIR}/compile_commands.json
)
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/compile_commands.json
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_SOURCE_DIR}/compile_commands.json
DEPENDS
# Unlike "proper" targets like executables and libraries,
# custom command / target pairs will not set up source
# file dependencies, so we need to list file explicitly here
generate-compile-commands
${CMAKE_BINARY_DIR}/compile_commands.json
)
# Generate the compilation commands. Necessary so cmake knows where it came
# from and if for some reason you delete it.
add_custom_target(generate-compile-commands
DEPENDS
${CMAKE_BINARY_DIR}/compile_commands.json
)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/compile_commands.json
COMMAND ${CMAKE_COMMAND} -B${CMAKE_BINARY_DIR} -S${CMAKE_SOURCE_DIR}
)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
add_custom_target(generate_git_commit ALL
DEPENDS "${CMAKE_BINARY_DIR}/last_git_commit.txt")
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/last_git_commit.txt"
COMMAND ${GIT_EXECUTABLE} log -n 2 > "${CMAKE_BINARY_DIR}/last_git_commit.txt" 2>&1)
endif()
# find_program(BASH bash HINTS /bin)
# find_package(Git QUIET)
# if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# add_custom_target(generate_git_commit ALL
# DEPENDS "${CMAKE_BINARY_DIR}/last_git_commit.txt")
# add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/last_git_commit.txt"
# COMMAND ${CMAKE_COMMAND} -E env ${BASH} -c "${GIT_EXECUTABLE} log -n 2 > ${CMAKE_BINARY_DIR}/last_git_commit.txt 2>&1")
# VERBATIM)
# endif()