Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
119 lines (98 loc) · 3.63 KB
/
Copy pathCMakeLists.txt
File metadata and controls
119 lines (98 loc) · 3.63 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
cmake_minimum_required(VERSION 3.30)
project(cartogram LANGUAGES CXX)
enable_testing()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# ----------------------------- Third–party -----------------------------
find_package(Boost REQUIRED CONFIG)
find_package(cgal REQUIRED CONFIG)
find_package(nlohmann_json REQUIRED CONFIG)
find_package(argparse REQUIRED CONFIG)
find_package(vincentlaucsb-csv-parser REQUIRED CONFIG)
find_package(indicators REQUIRED CONFIG)
find_package(PkgConfig REQUIRED)
find_package(jsoncons REQUIRED)
pkg_search_module(FFTW REQUIRED IMPORTED_TARGET fftw3)
# ----------------------------- Cartogram Library ---------------------------
file(GLOB_RECURSE CARTOGRAM_SOURCES CONFIGURE_DEPENDS src/*.cpp)
# Exclude main.cpp from the list of sources
list(FILTER CARTOGRAM_SOURCES EXCLUDE REGEX ".*/main\\.cpp$")
add_library(cartogram_lib STATIC ${CARTOGRAM_SOURCES})
target_include_directories(cartogram_lib
PUBLIC ${PROJECT_SOURCE_DIR}/include
)
target_link_libraries(cartogram_lib
PUBLIC
CGAL::CGAL
boost::boost
nlohmann_json::nlohmann_json
argparse::argparse
vincentlaucsb-csv-parser::vincentlaucsb-csv-parser
indicators::indicators
PkgConfig::FFTW
jsoncons
)
if(CMAKE_BUILD_TYPE STREQUAL Release)
target_compile_options(cartogram_lib PUBLIC -O3)
else()
target_compile_options(cartogram_lib PUBLIC -O1)
# Ignore CGAL preconditions in Debug builds (false positives)
target_compile_definitions(cartogram_lib
PUBLIC CGAL_NO_PRECONDITIONS
)
endif()
target_compile_options(cartogram_lib PUBLIC
-ffp-contract=off
-Werror
-Wall -Wextra -Wpedantic -Wshadow -Wold-style-cast -Wunreachable-code
-pedantic-errors -Wformat=2 -Wformat-security -Wcast-qual -Wcast-align -Wconversion
-Wsign-conversion -Wfloat-equal -Woverloaded-virtual -Wno-unknown-pragmas
-Wmissing-declarations -Werror=return-type -Wnon-virtual-dtor
)
if(CMAKE_BUILD_TYPE STREQUAL Release)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-march=native" HAS_MARCH_NATIVE)
check_cxx_compiler_flag("-mtune=native" HAS_MTUNE_NATIVE)
if(HAS_MARCH_NATIVE)
target_compile_options(cartogram_lib PUBLIC -march=native)
elseif(HAS_MTUNE_NATIVE)
target_compile_options(cartogram_lib PUBLIC -mtune=native)
endif()
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_ok OUTPUT ipo_msg)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(ipo_ok)
find_program(LLD_PATH NAMES lld ld.lld)
if(NOT LLD_PATH)
message(WARNING "lld not found; disabling IPO. Install with: sudo apt install lld")
set(ipo_ok FALSE)
endif()
endif()
endif()
if(ipo_ok)
set_property(TARGET cartogram_lib PROPERTY INTERPROCEDURAL_OPTIMIZATION ON)
target_link_options(cartogram_lib PUBLIC -flto=full)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
message(STATUS "Using LLD with full LTO + whole-program vtables: ${LLD_PATH}")
target_link_options(cartogram_lib PUBLIC -fuse-ld=lld)
target_compile_options(cartogram_lib
PUBLIC
-flto=full
-fwhole-program-vtables
-fvirtual-function-elimination)
endif()
else()
message(STATUS "IPO/LTO not available: ${ipo_msg}")
endif()
endif()
target_include_directories(cartogram_lib
PUBLIC ${PROJECT_SOURCE_DIR}/include
)
# ----------------------------- Main executable -----------------------------
add_executable(cartogram src/main.cpp)
target_link_libraries(cartogram
PRIVATE cartogram_lib
)
install(TARGETS cartogram RUNTIME DESTINATION bin)
# ----------------------------- Tests -----------------------------
add_subdirectory(tests)