-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·189 lines (165 loc) · 7.42 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
cmake_minimum_required(VERSION 3.30)
project(
Gecot
VERSION 1.0
DESCRIPTION
"Graph-based Ecological Connectivity Optimization Tool"
LANGUAGES CXX)
# set(CMAKE_VERBOSE_MAKEFILE ON)
# ################### Options ####################
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(ENABLE_TESTING "Enable unit tests" OFF)
option(WARNINGS "Enable warnings" OFF)
option(OPTIMIZE_FOR_NATIVE "Build with -march=native" OFF)
# ################### Modules ####################
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
include(GNUInstallDirs)
include(CompilerWarnings)
include(CompilerOptimizations)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}" ${CMAKE_MODULE_PATH})
if(WIN32)
file(TO_CMAKE_PATH "${CONAN_TBB_INCLUDE_DIR}" CONAN_TBB_INCLUDE_DIR)
file(TO_CMAKE_PATH "${CONAN_TBB_LIB_DIR}" CONAN_TBB_LIB_DIR)
file(TO_CMAKE_PATH "${CONAN_MINGW_LIB_DIR}" CONAN_MINGW_LIB_DIR)
endif()
if(NOT WIN32)
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib")
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
endif()
if(WIN32)
set(WINDRES_ICON_O "misc/gecot_icon.o")
execute_process(COMMAND "${CONAN_MINGW_LIB_DIR}/../bin/windres" "misc/gecot_icon.rc" -o ${WINDRES_ICON_O}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE WINDRES_RESULT
OUTPUT_VARIABLE WINDRES_OUTPUT)
message(STATUS "WINDRES [${WINDRES_RESULT}]: ${WINDRES_OUTPUT}")
endif()
# ################### Packages ####################
find_package(fast-cpp-csv-parser REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(nlohmann_json_schema_validator REQUIRED)
find_package(phmap REQUIRED)
if(NOT WIN32)
find_package(TBB REQUIRED)
endif()
find_package(Boost REQUIRED COMPONENTS program_options)
find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(Eigen3 REQUIRED)
# find_package(GDAL REQUIRED)
find_package(melon REQUIRED)
find_package(mippp REQUIRED)
# ################### LIB target ####################
add_library(gecot INTERFACE)
target_compile_definitions(gecot INTERFACE PROJECT_VERSION="${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}")
target_include_directories(gecot
INTERFACE ${PROJECT_SOURCE_DIR}/include)
if(WIN32)
target_include_directories(gecot INTERFACE ${CONAN_TBB_INCLUDE_DIR})
target_link_directories(gecot INTERFACE ${CONAN_TBB_LIB_DIR} "${CONAN_TBB_LIB_DIR}\\..\\bin")
target_link_libraries(gecot INTERFACE "${CONAN_TBB_LIB_DIR}/../bin/libtbb12.dll")
else()
target_link_libraries(gecot INTERFACE onetbb::onetbb)
endif()
target_link_libraries(gecot INTERFACE Boost::program_options)
target_link_libraries(gecot INTERFACE Eigen3::Eigen)
target_link_libraries(gecot INTERFACE fmt::fmt)
target_link_libraries(gecot INTERFACE spdlog::spdlog)
target_link_libraries(gecot INTERFACE melon::melon)
target_link_libraries(gecot INTERFACE mippp::mippp)
# ################### EXEC target ####################
add_executable(gecot_optimize src/instance.cpp src/parse_instance.cpp src/gecot_optimize.cpp ${WINDRES_ICON_O})
target_link_libraries(gecot_optimize PUBLIC gecot)
target_link_libraries(gecot_optimize PUBLIC fast-cpp-csv-parser::fast-cpp-csv-parser)
target_link_libraries(gecot_optimize PUBLIC nlohmann_json::nlohmann_json)
target_link_libraries(gecot_optimize PUBLIC nlohmann_json_schema_validator)
target_link_libraries(gecot_optimize PUBLIC phmap)
target_compile_options(gecot_optimize PUBLIC -fconcepts-diagnostics-depth=4 -Wall)
# target_compile_options(gecot_optimize PRIVATE -fsanitize=address)
# target_link_options(gecot_optimize PRIVATE -fsanitize=address -lpthread -static-libasan)
# add_executable(gecot_rank_options src/rank_options.cpp ${WINDRES_ICON_O})
# target_link_libraries(gecot_rank_options PUBLIC gecot)
# target_link_libraries(gecot_rank_options PUBLIC fast-cpp-csv-parser::fast-cpp-csv-parser)
# target_link_libraries(gecot_rank_options PUBLIC nlohmann_json::nlohmann_json)
# target_link_libraries(gecot_rank_options PUBLIC nlohmann_json_schema_validator)
# target_link_libraries(gecot_rank_options PUBLIC phmap)
# target_compile_options(gecot_rank_options PUBLIC -fconcepts-diagnostics-depth=4 -Wall)
# add_executable(gecot_hexagonify src/hexagonify.cpp ${WINDRES_ICON_O})
# target_link_libraries(gecot_hexagonify PUBLIC gecot)
# target_link_libraries(gecot_hexagonify PUBLIC Boost::headers) # geometry
# target_link_libraries(gecot_hexagonify PUBLIC GDAL::GDAL)
# target_compile_options(gecot_hexagonify PUBLIC -fconcepts-diagnostics-depth=4 -Wall)
# ################### TESTS ######################
if(ENABLE_TESTING)
enable_testing()
message("Building Tests.")
set_project_warnings(gecot)
add_subdirectory(test)
endif()
# ################## INSTALL #####################
install(TARGETS gecot_optimize RUNTIME DESTINATION bin LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
if(NOT WIN32)
install(CODE [[
file(GET_RUNTIME_DEPENDENCIES
EXECUTABLES $<TARGET_FILE:gecot_optimize>
RESOLVED_DEPENDENCIES_VAR _r_deps
UNRESOLVED_DEPENDENCIES_VAR _u_deps
DIRECTORIES bin
)
foreach(_file ${_r_deps})
file(INSTALL
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
TYPE SHARED_LIBRARY
FILES "${_file}" FOLLOW_SYMLINK_CHAIN
)
endforeach()
list(LENGTH _u_deps _u_length)
if("${_u_length}" GREATER 0)
message(WARNING "Unresolved dependencies detected! (" ${_u_deps} ")")
endif()
]])
else()
# install(FILES
# "c:/libs/cbc/bin/cbc.exe"
# "${CONAN_TBB_LIB_DIR}/../bin/libtbb12.dll"
# "${CONAN_MINGW_LIB_DIR}/../x86_64-w64-mingw32/lib/libgcc_s_seh-1.dll"
# "${CONAN_MINGW_LIB_DIR}/../x86_64-w64-mingw32/lib/libwinpthread-1.dll"
# "${CONAN_MINGW_LIB_DIR}/../x86_64-w64-mingw32/lib/libstdc++-6.dll"
# DESTINATION bin)
# set(CPACK_NSIS_MODIFY_PATH 2)
# set(CPACK_NSIS_DISPLAY_NAME Gecot)
# set(CPACK_NSIS_URL_INFO_ABOUT "https://github.com/fhamonic/gecot")
# set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
# set(CPACK_NSIS_INSTALLED_ICON_NAME "bin/gecot_optimize.exe")
# set(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/misc/gecot.ico")
# set(CPACK_NSIS_MUI_HEADERIMAGE "${PROJECT_SOURCE_DIR}/misc\\nsis_gecot_header.bmp")
install(FILES
"c:/libs/cbc/bin/cbc.exe"
"${CONAN_TBB_LIB_DIR}/../bin/libtbb12.dll"
"${CONAN_MINGW_LIB_DIR}/../x86_64-w64-mingw32/lib/libgcc_s_seh-1.dll"
"${CONAN_MINGW_LIB_DIR}/../x86_64-w64-mingw32/lib/libwinpthread-1.dll"
"${CONAN_MINGW_LIB_DIR}/../x86_64-w64-mingw32/lib/libstdc++-6.dll"
DESTINATION bin)
set(CPACK_GENERATOR WIX)
set(CPACK_WIX_VERSION 3)
# set(CPACK_WIX_PRODUCT_GUID 7315e975-bdb5-4797-b9e0-628fe7c89ee6)
set(CPACK_WIX_UPGRADE_GUID 504AB3DC-9C1E-4E24-B4D5-E3D3732DBD46)
set(CPACK_WIX_PROPERTY_ARPURLINFOABOUT "https://github.com/fhamonic/gecot")
set(CPACK_WIX_PRODUCT_ICON "${PROJECT_SOURCE_DIR}/misc/gecot.ico")
set(CPACK_WIX_UI_BANNER "${PROJECT_SOURCE_DIR}/misc/wix_gecot_banner.png")
set(CPACK_WIX_UI_DIALOG "${PROJECT_SOURCE_DIR}/misc/wix_gecot_dialog.png")
set(CPACK_WIX_PATCH_FILE "${PROJECT_SOURCE_DIR}/misc/PathPatch.xml")
set(CPACK_WIX_EXTENSIONS "WixUtilExtension")
endif()
set(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/misc/gecot.ico")
set(CPACK_PACKAGE_VENDOR "F. HAMONIC")
if(WIN32)
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/misc/windows_licenses.txt")
install(FILES "${PROJECT_SOURCE_DIR}/misc/windows_licenses.txt" RENAME "LICENCE.txt" DESTINATION .)
else()
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/misc/linux_licenses.txt")
install(FILES "${PROJECT_SOURCE_DIR}/misc/linux_licenses.txt" RENAME "LICENCE" DESTINATION .)
endif()
include(CPack)