-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
231 lines (207 loc) · 8.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# ----------------------------------------------------------------------------
# Root CMake file for RasterClass.
# A simple GDAL wrapper for raster data IO with asc, tif, and MongoDB.
#
# Please build from the off-tree build directory, e.g.:
# $ mkdir -p build
# $ cd build
# $ cmake ..
# Optional cmake options:
# -DUNITTEST=1 means run unittest based gtest/gmock
# -DRUNCOV=1 means run code coverage based gcov and lcov
#
# Routine testing platforms and compilers include:
# 1. Windows 10 with Visual Studio 2013, mongo-c-driver-1.5.5, GDAL-1.11.4
# 2. Windows 10 with mingw64 (GCC-4.9.3), mongo-c-driver-1.8.1, GDAL-1.11.5
# 3. CentOS 6.2 (cluster) with GCC-4.8.4, mongo-c-driver-1.5.5, GDAL-1.9.0
# 4. Red Hat Server 6.2 (cluster) with ICC-12.1.0, mongo-c-driver-1.5.5, GDAL-1.11.5
# 5. macOS 10.12.6 with Clang-8.0 (or GCC-4.9.3), mongo-c-driver-1.5.5, GDAL-1.11.4
#
# Created and maintained by Liang-Jun Zhu (zlj@lreis.ac.cn)
# Latest updated: Dec. 1, 2017
# Copyright (C) 2017 Lreis, IGSNRR, CAS
# ----------------------------------------------------------------------------
IF(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
MESSAGE(FATAL_ERROR "
FATAL: In-source builds are not allowed.
You should create a separate directory for build files.")
ENDIF()
CMAKE_MINIMUM_REQUIRED(VERSION 3.1 FATAL_ERROR)
if(POLICY CMP0015)
cmake_policy(SET CMP0015 NEW)
endif()
if(POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
### Project name.
project(RasterClass)
### Set cmake find path
set(CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/cmake
${CMAKE_MODULE_PATH}
)
### Set default or specified installation directory.
IF (INSTALL_PREFIX)
SET(CMAKE_INSTALL_PREFIX ${INSTALL_PREFIX} CACHE PATH "Set specified install path" FORCE)
ELSEIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/bin CACHE PATH "Set default install path" FORCE)
ENDIF ()
SET(INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
### In case of Makefiles if the user does not setup CMAKE_BUILD_TYPE, assume it's Release.
IF(CMAKE_GENERATOR MATCHES "Makefiles|Ninja" AND "${CMAKE_BUILD_TYPE}" STREQUAL "")
SET(CMAKE_BUILD_TYPE Release)
ENDIF()
### Allow project folders in MSVC.
IF(MSVC)
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
ENDIF()
### OS platform.
if (WIN32)
add_definitions(-Dwindows)
if (MSVC)
add_definitions(-DMSVC)
endif ()
elseif (APPLE)
add_definitions(-Dmacos)
else ()
add_definitions(-Dlinux)
endif ()
### Break in case of popular CMake configuration mistakes.
IF(NOT CMAKE_SIZEOF_VOID_P GREATER 0)
MESSAGE(FATAL_ERROR "CMake fails to determine the bitness of the target platform.
Please check your CMake and compiler installation.")
ENDIF()
# Global flag to cause add_library to create shared libraries if on, otherwise static library.
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
# libraries built with hunter link against the dynamic CRT on windows
option(BUILD_WITH_STATIC_CRT "Build against dynamic CRT on windows." ON)
### Detect compiler and target platform architecture.
INCLUDE(Utils)
SET(ENABLE_CXX11 1)
INCLUDE(DetectCXXCompiler)
### Use statically or dynamically linked CRT? Default: dynamic
IF(MSVC)
INCLUDE(CRTLinkage)
ENDIF(MSVC)
### Add standard paths or specified paths for Find libraries and headers.
INCLUDE(AddFindPaths)
### RasterClass library
set(SOURCE_FILES clsRasterData.h)
set(UTILS_INC ${CMAKE_CURRENT_SOURCE_DIR}/../UtilsClass)
file(GLOB UTILS_HEADERS ${UTILS_INC}/*.h)
file(GLOB UTILS_FILES ${UTILS_INC}/*.cpp)
set(MONGO_INC ${CMAKE_CURRENT_SOURCE_DIR}/../MongoUtilClass)
file(GLOB MONGO_HEADERS MONGO_INC/*.h)
file(GLOB MONGO_FILES ${MONGO_INC}/*.cpp)
### Find packages.
SET(WITH_GDAL 1)
SET(WITH_OPENMP 1)
IF (EXISTS ${MONGO_FILES})
SET(WITH_MONGOC 1)
ENDIF ()
INCLUDE(FindPackages)
if (BSON_FOUND AND MONGOC_FOUND AND WITH_MONGOC)
add_definitions(-DUSE_MONGODB)
geo_include_directories(${BSON_INCLUDE_DIR} ${MONGOC_INCLUDE_DIR} ${UTILS_INC} ${MONGO_INC})
add_library(RasterClass ${SOURCE_FILES} ${UTILS_FILES} ${UTILS_HEADERS} ${MONGO_FILES} ${MONGO_HEADERS})
target_link_libraries(RasterClass ${BSON_LIBRARIES} ${MONGOC_LIBRARIES})
else ()
geo_include_directories(${UTILS_INC})
add_library(RasterClass ${SOURCE_FILES} ${UTILS_FILES} ${UTILS_HEADERS})
endif ()
if (GDAL_FOUND)
geo_include_directories(${GDAL_INCLUDE_DIR})
target_link_libraries(RasterClass ${GDAL_LIBRARIES})
endif ()
### Set code coverage linkage.
if (RUNCOV STREQUAL 1)
set_target_properties(RasterClass PROPERTIES COMPILE_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
set_target_properties(RasterClass PROPERTIES LINK_FLAGS "-coverage -lgcov")
endif()
### unittest based on gtest/gmock, which is optional.
IF (UNITTEST STREQUAL 1)
add_definitions(-DUNITTEST)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
### Download and compile googletest
include(DownloadProject)
download_project(PROJ googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
include_directories("${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test)
ENDIF ()
### Copy test data to build directory.
if (MSVC)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test)
else()
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif ()
install(TARGETS RasterClass DESTINATION ${INSTALL_DIR})
### For CLion to implement the "make install" command
add_custom_target(install_${PROJECT_NAME}
$(MAKE) install
DEPENDS RasterClass
COMMENT "Installing ${PROJECT_NAME}")
### Build platform.
STATUS("")
STATUS(" Platform:")
IF(NOT CMAKE_VERSION VERSION_LESS 2.8.11 AND NOT BUILD_INFO_SKIP_TIMESTAMP)
STRING(TIMESTAMP TIMESTAMP "" UTC)
IF(TIMESTAMP)
STATUS(" Timestamp:" ${TIMESTAMP})
ENDIF()
ENDIF()
STATUS(" Host:" ${CMAKE_HOST_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_VERSION} ${CMAKE_HOST_SYSTEM_PROCESSOR})
IF(CMAKE_CROSSCOMPILING)
STATUS(" Target:" ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION} ${CMAKE_SYSTEM_PROCESSOR})
ENDIF()
STATUS(" CMake:" ${CMAKE_VERSION})
STATUS(" CMake generator:" ${CMAKE_GENERATOR})
STATUS(" CMake build tool:" ${CMAKE_BUILD_TOOL})
IF(MSVC)
STATUS(" MSVC:" ${MSVC_VERSION})
ENDIF()
IF(CMAKE_GENERATOR MATCHES Xcode)
STATUS(" Xcode:" ${XCODE_VERSION})
ENDIF()
IF(NOT CMAKE_GENERATOR MATCHES "Xcode|Visual Studio")
STATUS(" Configuration:" ${CMAKE_BUILD_TYPE})
ENDIF()
### C/C++ options.
IF(CMAKE_CXX_COMPILER_VERSION)
SET(GEO_COMPILER_STR "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} (ver ${CMAKE_CXX_COMPILER_VERSION})")
ELSE()
SET(GEO_COMPILER_STR "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
ENDIF()
STRING(STRIP "${GEO_COMPILER_STR}" GEO_COMPILER_STR)
STATUS("")
STATUS(" C/C++:")
IF(ENABLE_CXX11 OR HAVE_CXX11)
STATUS(" C++11:" HAVE_CXX11 THEN YES ELSE NO)
ENDIF()
STATUS(" C++ Compiler:" ${GEO_COMPILER_STR})
STATUS(" C++ flags (Release):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE})
STATUS(" C++ flags (Debug):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG})
STATUS(" C Compiler:" ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1})
STATUS(" C flags (Release):" ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE})
STATUS(" C flags (Debug):" ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG})
IF(WIN32)
STATUS(" Linker flags (Release):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_RELEASE})
STATUS(" Linker flags (Debug):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
ELSE()
STATUS(" Linker flags (Release):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_RELEASE})
STATUS(" Linker flags (Debug):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_DEBUG})
ENDIF()
### Dependencies.
STATUS(" GDAL: ${GDAL_LIBRARIES} ${GDAL_INCLUDE_DIR}")
IF(BSON_FOUND AND MONGOC_FOUND AND WITH_MONGOC)
STATUS(" BSON: ${BSON_LIBRARIES} ${BSON_INCLUDE_DIR}")
STATUS(" MongoC: ${MONGOC_LIBRARIES} ${MONGOC_INCLUDE_DIR}")
ENDIF()
### Auxiliary.
STATUS("")
STATUS(" Install path:" ${CMAKE_INSTALL_PREFIX})
STATUS("")