forked from Rogier-5/minetest-mapper-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
164 lines (136 loc) · 5.25 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
# CMakeList.txt: CMake-Projektdatei der obersten Ebene. Führen Sie eine globale Konfiguration durch,
# und schließen Sie hier Unterprojekte ein.
#
cmake_minimum_required (VERSION 3.8)
set (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
endif()
# This is important to vcpkg to select the right libraries
IF(NOT CMAKE_BUILD_TYPE )
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
ENDIF()
project (
"Minetestmapper"
DESCRIPTION "Map generator for Minetest"
LANGUAGES C CXX)
find_package(Git REQUIRED)
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --long --dirty --tags --match v[0-9]*
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_tag
ERROR_VARIABLE git_error
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if( NOT git_result EQUAL 0 )
message( FATAL_ERROR "Failed to execute Git: ${git_error}" )
endif()
if( git_tag MATCHES "v([0-9]+).([0-9]+).([0-9]+)-([0-9]+)-g([0-9,a-f]+)(-dirty)?" )
set( git_version_major "${CMAKE_MATCH_1}" )
set( git_version_minor "${CMAKE_MATCH_2}" )
set( git_version_patch "${CMAKE_MATCH_3}" )
set( git_commits_since_last_tag "${CMAKE_MATCH_4}" )
set( git_hash "${CMAKE_MATCH_5}" )
set( git_wip "${CMAKE_MATCH_6}" )
else()
message( FATAL_ERROR "Git tag isn't valid semantic version: [${git_tag}]" )
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_current_branch
ERROR_VARIABLE git_error
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if( NOT git_result EQUAL 0 )
message( FATAL_ERROR "Failed to execute Git: ${git_error}" )
endif()
if(${git_commits_since_last_tag} EQUAL 0)
set (PRERELEASE 0)
else()
set (PRERELEASE 1)
endif()
set(BUILD_BRANCH ${git_current_branch})
if(BUILD_BRANCH STREQUAL "master")
set (SPECIALBUILD 0)
else()
set (SPECIALBUILD 1)
endif()
set (PROJECT_VERSION_MAJOR ${git_version_major})
set (PROJECT_VERSION_MINOR ${git_version_minor})
set (PROJECT_VERSION_PATCH ${git_version_patch})
set (PROJECT_VERSION_TWEAK ${git_commits_since_last_tag})
if(NOT PROJECT_VERSION_TWEAK)
set(PROJECT_VERSION_TWEAK 0)
endif()
if(git_wip)
set (DIRTY_BUILD 1)
else()
set (DIRTY_BUILD 0)
endif()
set (PROJECT_VERSION "${git_version_major}.${git_version_minor}.${git_version_patch}.${git_commits_since_last_tag}-g${git_hash}${git_wip}")
message(STATUS "Version: ${PROJECT_VERSION}")
# Set output directories
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
OPTION(ENABLE_SQLITE3 "Enable sqlite3 backend" True)
OPTION(ENABLE_POSTGRESQL "Enable postgresql backend")
OPTION(ENABLE_LEVELDB "Enable LevelDB backend")
OPTION(ENABLE_REDIS "Enable redis backend")
macro(EnableDBBackend NAME_TECHNICAL DATABASE_NAME)
message (STATUS "${DATABASE_NAME} library: ${${NAME_TECHNICAL}_LIBRARY}")
message (STATUS "${DATABASE_NAME} headers: ${${NAME_TECHNICAL}_INCLUDE_DIR}")
if(${NAME_TECHNICAL}_LIBRARY AND ${NAME_TECHNICAL}_INCLUDE_DIR)
set(USE_${NAME_TECHNICAL} 1)
message(STATUS "${DATABASE_NAME} backend enabled")
include_directories(${${NAME_TECHNICAL}_INCLUDE_DIR})
else(${NAME_TECHNICAL}_LIBRARY AND ${NAME_TECHNICAL}_INCLUDE_DIR)
set(USE_${NAME_TECHNICAL} 0)
if(ENABLE_${NAME_TECHNICAL})
message(SEND_ERROR "${DATABASE_NAME} backend requested but ${DATABASE_NAME} libraries not found!")
else(ENABLE_${NAME_TECHNICAL})
message(STATUS "${DATABASE_NAME} not enabled (${DATABASE_NAME} libraries and/or headers not found)")
endif(ENABLE_${NAME_TECHNICAL})
endif(${NAME_TECHNICAL}_LIBRARY AND ${NAME_TECHNICAL}_INCLUDE_DIR)
endmacro()
# Find sqlite3
if(ENABLE_SQLITE3)
find_library(SQLITE3_LIBRARY sqlite3)
find_path(SQLITE3_INCLUDE_DIR sqlite3.h)
EnableDBBackend(SQLITE3 sqlite3)
endif(ENABLE_SQLITE3)
# Find postgresql
if(ENABLE_POSTGRESQL)
find_library(POSTGRESQL_LIBRARY NAMES pq libpq)
find_path(POSTGRESQL_INCLUDE_DIR libpq-fe.h PATH_SUFFIXES postgresql)
EnableDBBackend(POSTGRESQL postgresql)
endif(ENABLE_POSTGRESQL)
# Find leveldb
if(ENABLE_LEVELDB)
find_library(LEVELDB_LIBRARY NAMES leveldb libleveldb)
find_path(LEVELDB_INCLUDE_DIR db.h PATH_SUFFIXES leveldb)
EnableDBBackend(LEVELDB LevelDB)
endif(ENABLE_LEVELDB)
# Find redis
if(ENABLE_REDIS OR ENABLE_ANY_DATABASE OR ENABLE_ALL_DATABASES)
find_library(REDIS_LIBRARY hiredis)
find_path(REDIS_INCLUDE_DIR hiredis.h PATH_SUFFIXES hiredis)
EnableDBBackend(REDIS redis)
endif(ENABLE_REDIS OR ENABLE_ANY_DATABASE OR ENABLE_ALL_DATABASES)
# Schließen Sie Unterprojekte ein.
add_subdirectory ("Minetestmapper")
configure_file(
"${PROJECT_SOURCE_DIR}/version.h.in"
"${PROJECT_SOURCE_DIR}/Minetestmapper/version.h"
)
configure_file(
"${PROJECT_SOURCE_DIR}/build_config.h.in"
"${PROJECT_SOURCE_DIR}/Minetestmapper/build_config.h"
)