Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
101 lines (82 loc) · 3.83 KB
/
Copy pathCMakeLists.txt
File metadata and controls
101 lines (82 loc) · 3.83 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
cmake_minimum_required(VERSION 3.28)
# Update the release version here for when the code is built out
# of tree. It is not optimal, but that how it is. There is a check
# in the release build to make sure this version and the tag have
# the same version.
project(gerbv
VERSION 2.13.0
DESCRIPTION "Gerber Viewer"
LANGUAGES C CXX)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_EXPORT_COMPILE_COMMANDS "ON")
## Glib-2.0 and GTK-2.0
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-2.0)
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0>=2.6)
## Gettext and intl
find_package(Gettext REQUIRED) # https://cmake.org/cmake/help/latest/module/FindGettext.html
find_package(Intl) # Removed REQUIRED since it will fail on Mingw where it seems to be part of Gettext
include(GNUInstallDirs)
set(DATADIR "${CMAKE_INSTALL_FULL_DATADIR}/${CMAKE_PROJECT_NAME}")
set(LOCALEDIR "${CMAKE_INSTALL_FULL_LOCALEDIR}")
set(SCMSUBDIR "scheme")
set(BACKEND_DIR "${DATADIR}/${SCMSUBDIR}")
add_library(compilation-flags INTERFACE)
target_compile_options(compilation-flags INTERFACE -Wall -Wimplicit-fallthrough -O3 -Wno-deprecated-declarations)
target_compile_options(compilation-flags INTERFACE $<$<CONFIG:Debug>:-g3>)
target_link_libraries(compilation-flags INTERFACE PkgConfig::GLIB PkgConfig::GTK m)
if(Intl_FOUND)
target_link_libraries(compilation-flags INTERFACE Intl::Intl)
endif()
## This is installation directory settings. These must be solved later by install target
target_compile_definitions(compilation-flags INTERFACE "GERBV_DATADIR=\"${DATADIR}\"")
target_compile_definitions(compilation-flags INTERFACE "GERBV_LOCALEDIR=\"${LOCALEDIR}\"")
target_compile_definitions(compilation-flags INTERFACE "GERBV_BINDIR=\"${CMAKE_INSTALL_FULL_BINDIR}\"")
target_compile_definitions(compilation-flags INTERFACE "GERBV_SCMSUBDIR=\"${SCMSUBDIR}\"")
target_compile_definitions(compilation-flags INTERFACE "GERBV_BACKEND_DIR=\"${BACKEND_DIR}\"")
if(NOT WIN32 AND CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# set CMAKE_INSTALL_PREFIX with -D parameter to cmake
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
endif()
include(GetGitVersion)
get_git_version(GIT_VERSION)
# Parse git version for packaging
# Format: v4.0.1 or v4.0.1-23-gabcd1234 or v4.0.1-dirty
string(REGEX REPLACE "^v" "" GIT_VERSION_CLEAN "${GIT_VERSION}")
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.?([0-9]*)" VERSION_MATCH "${GIT_VERSION_CLEAN}")
set(VERSION_MAJOR "${CMAKE_MATCH_1}")
set(VERSION_MINOR "${CMAKE_MATCH_2}")
set(VERSION_PATCH "${CMAKE_MATCH_3}")
# If no patch version, default to 0
if("${VERSION_PATCH}" STREQUAL "")
set(VERSION_PATCH "0")
endif()
# Extract additional info (commit count + hash or -dirty)
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.?[0-9]*-?" "" VERSION_SUFFIX "${GIT_VERSION_CLEAN}")
# Override project version with git version
set(PROJECT_VERSION_MAJOR ${VERSION_MAJOR})
set(PROJECT_VERSION_MINOR ${VERSION_MINOR})
set(PROJECT_VERSION_PATCH ${VERSION_PATCH})
set(PROJECT_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
message(STATUS "Version from git: ${GIT_VERSION}")
message(STATUS "Parsed version: ${PROJECT_VERSION} (suffix: ${VERSION_SUFFIX})")
# Note: config must happen before locale, since locale uses config for authors.c/bugs.c
add_subdirectory(config)
add_subdirectory(locale)
add_subdirectory(src)
add_subdirectory(man)
add_subdirectory(desktop)
add_subdirectory(thirdparty)
install(DIRECTORY example TYPE DOC) # Rename to examples
install(DIRECTORY share/ TYPE DATA)
enable_testing()
add_subdirectory(test)
# where to find our CMake modules
include(InstallWindowsDLLs)
include(Packing)