-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
130 lines (101 loc) · 3.52 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
cmake_minimum_required(VERSION 3.22)
if(UNIX AND NOT APPLE)
set(CMAKE_CXX_COMPILER "g++-11")
endif()
project(cartogram LANGUAGES CXX)
# ========== Project Setup ==========
set(CMAKE_CXX_STANDARD 20)
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(CMAKE_COLOR_DIAGNOSTICS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Assume development build by default
set(RELEASE_TAG "development" CACHE STRING "Release tag for the build")
# Default build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
# ========== Dependencies Setup ==========
# Direct CMake to local CGAL installation
set(CGAL_DIR ${PROJECT_SOURCE_DIR}/external/cgal)
find_package(CGAL REQUIRED)
# Boost
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
# PkgConfig, fftw, and cairo
find_package(PkgConfig REQUIRED)
pkg_search_module(fftw REQUIRED fftw3 IMPORTED_TARGET)
pkg_search_module(cairo REQUIRED cairo IMPORTED_TARGET)
# ========== Source Files ==========
file(GLOB_RECURSE CARTOGRAM_SOURCES "src/*.cpp")
add_executable(cartogram ${CARTOGRAM_SOURCES})
target_compile_definitions(cartogram PRIVATE RELEASE_TAG="${RELEASE_TAG}")
# ========== Include Directories ==========
target_include_directories(cartogram
PUBLIC
${PROJECT_SOURCE_DIR}/include
)
target_include_directories(cartogram
SYSTEM PUBLIC
${CGAL_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/external
)
# ========== Compile Options ==========
target_compile_options(cartogram PRIVATE -ffp-contract=off)
# Compiler warnings
target_compile_options(cartogram PRIVATE
-Wall # Enable all warnings
-Wextra # Enable extra warnings
-Wpedantic # Enable pedantic warnings
)
# ========== Linking Libraries ==========
target_link_libraries(cartogram
PkgConfig::fftw
PkgConfig::cairo
)
# ========== Installation ==========
install(TARGETS cartogram DESTINATION /usr/local/bin)
# Enable CTest testing
enable_testing()
# Add test executable
file(GLOB_RECURSE TEST_FILES "tests/*.cpp")
# Include the source files from the src directory that are needed for testing
set(CARTOGRAM_TEST_SOURCES_FROM_SRC
"src/misc/string_to_decimal_converter.cpp"
# Add additional test sources from src here if necessary
)
# For each test file, create an executable and a test
foreach(TEST_FILE ${TEST_FILES})
# Extract the filename without an extension to use as a test name
get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE)
# Create an executable for each test file
add_executable(${TEST_NAME} ${TEST_FILE} ${CARTOGRAM_TEST_SOURCES_FROM_SRC})
# Include directories for the test executable
target_include_directories(${TEST_NAME}
PUBLIC
${PROJECT_SOURCE_DIR}/include
)
target_include_directories(${TEST_NAME}
SYSTEM PUBLIC
${CGAL_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/external
)
target_compile_options(${TEST_NAME} PRIVATE -ffp-contract=off)
# Compiler warnings for the test executable
target_compile_options(${TEST_NAME} PRIVATE -Wall -Wextra -pedantic -Wno-deprecated-declarations)
# Linking Libraries for Test Executable
target_link_libraries(${TEST_NAME}
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
PkgConfig::fftw
)
# Register the executable as a test
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
endforeach()
# Uninstall target
add_custom_target("uninstall")
add_custom_command(
TARGET "uninstall"
POST_BUILD
COMMENT "Uninstalling cartogram..."
COMMAND xargs rm -vf < install_manifest.txt || echo "Nothing in install_manifest.txt to be uninstalled!"
)