This repository has been archived by the owner on May 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
136 lines (115 loc) · 4.18 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
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU Lesser General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#
cmake_minimum_required(VERSION 3.0)
project("ModuleDevelopmentKit")
option(WITH_SQLITE "Enable SQLite support" ON)
option(WITH_MARIADB "Enable MariaDB support" ON)
option(WITH_MYSQL "Enable MySQL rather than MariaDB" OFF)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ModuleDevelopmentKit_SOURCE_DIR}/cmake)
# Add definitions for w32 build that dosen't support _WIN32 macro
if (WIN32)
add_definitions("-DWIN32 -D__WIN32__ -D_CRT_SECURE_NO_WARNINGS")
endif()
# Set -fPIC to allow compiling mdk shared library with libuv
if (NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
# Set CMake output directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Find thread libraries and compiler flags if required.
find_package(Threads)
# LibUV inclusions
find_package(LibUV)
if(NOT LIBUV_FOUND)
message("Failed to find libuv, will build bundled copy.")
add_subdirectory(libuv)
include_directories("libuv/include")
set(LIBUV_LIBRARIES uv_a)
else()
include_directories(${LIBUV_INCLUDE_DIRS})
endif()
# Main MDK inclusions
include_directories("include/MDK")
# SQLite inclusion
if (WITH_SQLITE)
add_subdirectory(sqlite3)
include_directories(sqlite3)
endif()
# Mariadb inclusion
if (WITH_MARIADB AND NOT WITH_MYSQL)
find_package(MariaDB)
if(NOT MARIADB_FOUND)
message("Failed to find libmariadb, will build bundled copy.")
set(WITH_UNIT_TESTS OFF) # Remove useless tests from mariadb build
add_subdirectory(mariadb-connector-c)
include_directories("mariadb-connector-c/include")
include_directories("${CMAKE_CURRENT_BINARY_DIR}/mariadb-connector-c/include") # mariadb config
set(MYMR_DATABASE_LIBRARY libmariadb)
else()
include_directories(${MARIADB_INCLUDE_DIRS})
set(MYMR_DATABASE_LIBRARY ${MARIADB_LIBRARIES})
endif()
endif()
if (WITH_MYSQL)
find_package(MySQL)
if (NOT MYSQL_FOUND)
message("Failed to find libmysql")
else()
include_directories(${MYSQL_INCLUDE_DIR})
set(MYMR_DATABASE_LIBRARY ${MYSQL_LIBRARIES})
endif()
endif()
set(SOURCES
${CMAKE_CURRENT_LIST_DIR}/include/MDK/Database.h
${CMAKE_CURRENT_LIST_DIR}/include/MDK/MDK_Definitions.h
${CMAKE_CURRENT_LIST_DIR}/include/MDK/mdkstdint.h
${CMAKE_CURRENT_LIST_DIR}/include/MDK/ModuleEntryPoint.h
${CMAKE_CURRENT_LIST_DIR}/include/MDK/Utility.h
${CMAKE_CURRENT_LIST_DIR}/include/MDK/Query.h
${CMAKE_CURRENT_LIST_DIR}/include/MDK/TemplateClient.h
${CMAKE_CURRENT_LIST_DIR}/include/MDK/TemplateServer.h
${CMAKE_CURRENT_LIST_DIR}/include/MDK/TemplateSocket.h
${CMAKE_CURRENT_LIST_DIR}/include/MDK/ThreadServer.h
${CMAKE_CURRENT_LIST_DIR}/Database.cpp
${CMAKE_CURRENT_LIST_DIR}/Utility.cpp
${CMAKE_CURRENT_LIST_DIR}/Query.cpp
${CMAKE_CURRENT_LIST_DIR}/TemplateClient.cpp
${CMAKE_CURRENT_LIST_DIR}/TemplateServer.cpp
${CMAKE_CURRENT_LIST_DIR}/TemplateSocket.cpp
${CMAKE_CURRENT_LIST_DIR}/ThreadServer.cpp
)
if (WIN32)
set(SOURCES
${SOURCES}
${CMAKE_CURRENT_LIST_DIR}/resource.h
)
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/Common.rc PROPERTIES LANGUAGE RC)
endif()
set(MDK_LIBRARIES ${MDK_LIBRARIES} ${LIBUV_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
if (WITH_MARIADB OR WITH_MYSQL)
set(MDK_LIBRARIES ${MDK_LIBRARIES} ${MYMR_DATABASE_LIBRARY})
endif()
if (WITH_SQLITE)
set(MDK_LIBRARIES ${MDK_LIBRARIES} sqlite3)
endif()
add_library(MDK SHARED ${SOURCES})
target_link_libraries(MDK ${MDK_LIBRARIES})
if (WITH_MARIADB OR WITH_MYSQL)
target_compile_definitions(MDK PUBLIC __MARIADB__=1)
endif()
if (WITH_SQLITE)
target_compile_definitions(MDK PUBLIC __SQLITE__=1)
endif()