forked from Doc-Cirrus/orthanc-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
executable file
·211 lines (185 loc) · 7.51 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
cmake_minimum_required(VERSION 3.2)
project(OrthancMongoDB)
set(ORTHANC_ROOT "${PROJECT_SOURCE_DIR}/../Orthanc-1.5.7" CACHE STRING "Orthanc server sources root.")
set(BUILD_TESTS OFF CACHE BOOL "Option to build tests.")
set(BUILD_WITH_GCOV OFF CACHE BOOL "Option to build with gcov for the code coverage.")
set(LINK_STATIC_LIBS OFF CACHE BOOL "Option to link against static mongo-c-driver and mongo-cxx-driver.")
set(AUTO_INSTALL_DEPENDENCIES OFF CACHE BOOL "Option to install some required libraries automatically. Libraries wiill be installed in project build folder.")
set(ORTHANC_OPTIMAL_VERSION_MAJOR 1)
set(ORTHANC_OPTIMAL_VERSION_MINOR 5)
set(ORTHANC_OPTIMAL_VERSION_REVISION 7)
message("-- Orthanc Root: ${ORTHANC_ROOT}")
IF ( MSVC )
IF (NOT AUTO_INSTALL_DEPENDENCIES)
set(LIBJSON_ROOT "/jsoncpp" CACHE STRING "JSONCPP root.")
set(MONGOC_ROOT "/mongo-c-driver" CACHE STRING "Mongo C driver root.")
set(MONGOCXX_ROOT "/mongo-cxx-driver" CACHE STRING "Mongo CXX driver root.")
# Set reqired include pathes for MSVC
set(BSON_INCLUDE_DIRS "${MONGOC_ROOT}/include/libbson-1.0")
set(MONGOCLIB_INCLUDE_DIRS "${MONGOC_ROOT}/include/libmongoc-1.0")
set(BSONCXX_INCLUDE_DIRS "${MONGOCXX_ROOT}/include/bsoncxx/v_noabi")
set(MONGOCXX_INCLUDE_DIRS "${MONGOCXX_ROOT}/include/mongocxx/v_noabi")
set(JSONCPP_INCLUDE_DIRS "${LIBJSON_ROOT}/include")
ELSE ()
# Install, build and configure next components: jsoncpp, libbson, libmongoc, libbsoncxx, libmongocxx
include(CMake/autoconfig.cmake)
ENDIF ()
set(LIBS ${LIBS} RpcRT4.Lib)
ELSE ()
#rely on pkg-config
include(FindPkgConfig)
IF (NOT AUTO_INSTALL_DEPENDENCIES)
pkg_search_module(MONGOCLIB REQUIRED libmongoc-1.0)
pkg_search_module(JSONCPP REQUIRED jsoncpp)
IF (LINK_STATIC_LIBS)
pkg_search_module(BSONCXX REQUIRED libbsoncxx-static)
pkg_search_module(MONGOCXX REQUIRED libmongocxx-static)
ELSE()
pkg_search_module(BSONCXX REQUIRED libbsoncxx)
pkg_search_module(MONGOCXX REQUIRED libmongocxx)
ENDIF()
ELSE ()
# Install, build and configure next components: jsoncpp, libbson, libmongoc, libbsoncxx, libmongocxx
include(CMake/autoconfig.cmake)
ENDIF ()
pkg_search_module(OPENSSL openssl)
IF (OPENSSL_FOUND)
find_library(CYRUS sasl2)
set(LIBS ${LIBS} ${OPENSSL_LIBRARIES} "sasl2")
ENDIF()
IF (CYRUS_FOUND)
set(LIBS ${LIBS} ${CYRUS_LIBRARIES})
ENDIF()
set(CMAKE_CXX_FLAGS "-std=c++14")
#Linux specific switches
IF (NOT APPLE)
set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,defs")
set(LIBS ${LIBS} "uuid" "pthread" "rt")
ENDIF()
set(LIBS ${LIBS} "z" "resolv")
ENDIF ()
# Include directories
include_directories(${BSON_INCLUDE_DIRS})
include_directories(${MONGOCLIB_INCLUDE_DIRS})
include_directories(${BSONCXX_INCLUDE_DIRS})
include_directories(${MONGOCXX_INCLUDE_DIRS})
include_directories(${JSONCPP_INCLUDE_DIRS})
IF (NOT AUTO_INSTALL_DEPENDENCIES)
set(LIBJSON_LIB_NAMES jsoncpp )
set(BSON_LIB_NAMES bson-1.0 )
set(MONGOC_LIB_NAMES mongoc-1.0)
set(BSONCXX_LIB_NAMES bsoncxx )
set(MONGOCXX_LIB_NAMES mongocxx )
IF (LINK_STATIC_LIBS)
##################################################################
#link against static libraries
set(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(LIBJSON_LIB_NAMES jsoncpp_static ${LIBJSON_LIB_NAMES} )
set(BSON_LIB_NAMES bson-static-1.0 bson-1.0 ${BSON_LIB_NAMES} )
set(MONGOC_LIB_NAMES mongoc-static-1.0 mongoc-1.0 ${MONGOC_LIB_NAMES} )
set(BSONCXX_LIB_NAMES bsoncxx-static ${BSONCXX_LIB_NAMES} )
set(MONGOCXX_LIB_NAMES mongocxx-static ${MONGOCXX_LIB_NAMES})
ENDIF()
find_library(LIBJSON_LIBS
NAMES ${LIBJSON_LIB_NAMES}
PATHS "${LIBJSON_ROOT}/lib"
)
find_library(BSON_LIBS
NAMES ${BSON_LIB_NAMES}
PATHS "${MONGOC_ROOT}/lib"
)
find_library(MONGOC_LIBS
NAMES ${MONGOC_LIB_NAMES}
PATHS "${MONGOC_ROOT}/lib"
)
find_library(BSONXX_LIBS
NAMES ${BSONCXX_LIB_NAMES}
PATHS "${MONGOCXX_ROOT}/lib"
)
find_library(AMONGOCXX_LIBS
NAMES ${MONGOCXX_LIB_NAMES}
PATHS "${MONGOCXX_ROOT}/lib"
)
ENDIF ()
message("Found libraries:")
message(" LIBJSON_LIBS " ${LIBJSON_LIBS} )
message(" MONGOCXX_LIBS " ${AMONGOCXX_LIBS} )
message(" BSONCXX_LIBS " ${BSONXX_LIBS} )
message(" MONGOC_LIBS " ${MONGOC_LIBS} )
message(" BSON_LIBS " ${BSON_LIBS})
set(LIBS ${LIBS} ${LIBJSON_LIBS} ${AMONGOCXX_LIBS} ${BSONXX_LIBS} ${MONGOC_LIBS} ${BSON_LIBS})
link_libraries(${LIBS})
##################################################################
include_directories ("${PROJECT_SOURCE_DIR}/Core")
include_directories ("${PROJECT_SOURCE_DIR}/IndexPlugin")
include_directories ("${PROJECT_SOURCE_DIR}/StoragePlugin")
include_directories ("${ORTHANC_ROOT}/Plugins/Include")
##################################################################
add_definitions(
-DHAS_ORTHANC_EXCEPTION=1
-DORTHANC_ENABLE_LOGGING=1
-DORTHANC_ENABLE_LOGGING_PLUGIN=1
-DORTHANC_ENABLE_LOGGING_STDIO=1
-DORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT=1
-DORTHANC_OPTIMAL_VERSION_MAJOR=${ORTHANC_OPTIMAL_VERSION_MAJOR}
-DORTHANC_OPTIMAL_VERSION_MINOR=${ORTHANC_OPTIMAL_VERSION_MINOR}
-DORTHANC_OPTIMAL_VERSION_REVISION=${ORTHANC_OPTIMAL_VERSION_REVISION}
)
set(CORE_SOURCES
"Core/MongoDBConnection.cpp"
"Core/Configuration.cpp"
)
set(INDEX_PLUGIN_SOURCES
"IndexPlugin/MongoDBBackend.cpp"
"IndexPlugin/Plugin.cpp"
)
set(STORAGE_PLUGIN_SOURCES
"StoragePlugin/MongoDBStorageArea.cpp"
"StoragePlugin/Plugin.cpp"
"StoragePlugin/MongoDBGridFS.cpp"
)
##################################################################
add_library(OrthancMongoDBIndex SHARED ${CORE_SOURCES} ${INDEX_PLUGIN_SOURCES})
add_library(OrthancMongoDBStorage SHARED ${CORE_SOURCES} ${STORAGE_PLUGIN_SOURCES})
IF (APPLE)
set(APPLE_LIBS "sasl2" "-framework Security" "-framework CoreFoundation")
target_link_libraries(OrthancMongoDBIndex ${APPLE_LIBS})
target_link_libraries(OrthancMongoDBStorage ${APPLE_LIBS})
ENDIF ()
install(
TARGETS OrthancMongoDBIndex OrthancMongoDBStorage
RUNTIME DESTINATION lib # Destination for Windows
LIBRARY DESTINATION share/orthanc/plugins # Destination for Linux
)
IF (BUILD_TESTS)
IF (BUILD_WITH_GCOV)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
IF(UNIX AND NOT APPLE)
set(LIBS ${LIBS} gcov)
ENDIF()
ENDIF()
IF (UNIX)
pkg_search_module(GTEST REQUIRED gtest)
include_directories(${GTEST_INCLUDE_DIRS})
ENDIF()
include_directories ("${PROJECT_SOURCE_DIR}/Tests")
find_library(GOOGLE_TEST_LIB gtest)
set(TEST_SOURCES_INDEX
"Tests/IndexTest.cpp"
)
set(TEST_SOURCES_STORAGE
"Tests/StorageTest.cpp"
)
set(TEST_SOURCES_CONFIGURATION
"Tests/ConfigurationTest.cpp"
)
IF (UNIX AND NOT APPLE)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread -lm")
ENDIF()
add_executable(IndexTest ${CORE_SOURCES} ${INDEX_PLUGIN_SOURCES} ${TEST_SOURCES_INDEX})
add_executable(StorageTest ${CORE_SOURCES} ${STORAGE_PLUGIN_SOURCES} ${TEST_SOURCES_STORAGE})
add_executable(ConfigurationTest ${CORE_SOURCES} ${TEST_SOURCES_CONFIGURATION})
target_link_libraries(IndexTest ${APPLE_LIBS} ${LIBS} ${GOOGLE_TEST_LIB})
target_link_libraries(StorageTest ${APPLE_LIBS} ${LIBS} ${GOOGLE_TEST_LIB})
target_link_libraries(ConfigurationTest ${APPLE_LIBS} ${LIBS} ${GOOGLE_TEST_LIB})
ENDIF()