Skip to content

Commit 14c954c

Browse files
committed
More dynamic solution for CONC-107.
Cmake now supports the following options: -DINSTALL_LAYOUT=DEFAULT or RPM -DINSTALL_LIB_DIR -DINSTALL_INCLUDE_DIR -DINSTALL_DOCS_DIR -DINSTALL_PLUGINS_DIR -DINSTALL_BIN_DIR
1 parent 1006e18 commit 14c954c

File tree

4 files changed

+144
-20
lines changed

4 files changed

+144
-20
lines changed

CMakeLists.txt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ IF(NOT MYSQL_UNIX_ADDR)
9292
SET(MYSQL_UNIX_ADDR "/tmp/mysql.sock")
9393
ENDIF()
9494

95+
INCLUDE("${CMAKE_SOURCE_DIR}/cmake/install.cmake")
96+
9597
# todo: we don't character sets in share - all is compiled in
9698
SET(SHAREDIR "share")
9799
SET(DEFAULT_CHARSET_HOME "${CMAKE_INSTALL_PREFIX}")
@@ -102,18 +104,11 @@ INCLUDE(${CMAKE_SOURCE_DIR}/cmake/SearchLibrary.cmake)
102104
IF(WITH_EXTERNAL_ZLIB)
103105
FIND_PACKAGE(ZLIB QUIET)
104106
IF(${ZLIB_FOUND})
105-
SET(LIBZ "-lz")
107+
SET(LIBZ "-z")
106108
ENDIF()
107109
ENDIF()
108110

109-
IF(NOT LIB_INSTALL_DIR)
110-
SET(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
111-
ENDIF()
112111

113-
IF(NOT INCLUDE_INSTALL_DIR)
114-
SET(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include)
115-
ENDIF()
116-
117112
IF(UNIX)
118113
SEARCH_LIBRARY(LIBNSL inet_ntoa "nsl_r;nsl")
119114
SEARCH_LIBRARY(LIBBIND bind "bind;socket")
@@ -197,7 +192,7 @@ ENDIF()
197192

198193
IF(CLIENT_DOCS)
199194
INSTALL(DIRECTORY ${CLIENT_DOCS}
200-
DESTINATION .)
195+
DESTINATION ${DOCS_INSTALL_DIR_${INSTALL_LAYOUT}})
201196
ENDIF()
202197

203198
IF(MSVC)
@@ -208,9 +203,9 @@ IF(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
208203
ADD_SUBDIRECTORY(win/packaging)
209204
ENDIF()
210205

211-
SET(CPACK_PACKAGE_VENDOR "Monty Program AB")
212-
SET(CPACK_PACKAGE_DESCRIPTION "MariaDB client library. A library for connecting to MariaDB and MySQL servers")
213-
SET(CPACK_PACKAGE_NAME "mariadb_client")
206+
SET(CPACK_PACKAGE_VENDOR "MariaDB Corporation Ab")
207+
SET(CPACK_PACKAGE_DESCRIPTION "MariaDB Connector/C. A library for connecting to MariaDB and MySQL servers")
208+
SET(CPACK_PACKAGE_NAME "mariadb_connector_c")
214209
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.LIB")
215210
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
216211
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-src")
@@ -266,3 +261,7 @@ IF(WITH_EXTERNAL_ZLIB)
266261
ELSE()
267262
MESSAGE(STATUS "Zlib support: yes (using bundled zlib)")
268263
ENDIF()
264+
MESSAGE(STATUS "Installation layout: ${INSTALL_LAYOUT}")
265+
MESSAGE(STATUS "Include files will be installed in ${PREFIX_INSTALL_DIR}/${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}")
266+
MESSAGE(STATUS "Libraries will be installed in ${PREFIX_INSTALL_DIR}/${LIB_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}")
267+
MESSAGE(STATUS "Binaries will be installed in ${PREFIX_INSTALL_DIR}/${BIN_INSTALL_DIR}")

cmake/install.cmake

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# ************************************************************************************
2+
# Copyright (C) 2014 MariaDB Corporation Ab
3+
#
4+
# This library is free software#; you can redistribute it and/or
5+
# modify it under the terms of the GNU Library General Public
6+
# License as published by the Free Software Foundation; either
7+
# version 2 of the License, or (at your option) any later version.
8+
#
9+
# This library is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
# Library General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Library General Public
15+
# License along with this library; if not see <http://www.gnu.org/licenses>
16+
# or write to the Free Software Foundation, Inc.,
17+
# 51 Franklin St., Fifth Floor, Boston, MA 02110, USA
18+
#
19+
# *************************************************************************************
20+
21+
#
22+
# This file contains settings for the following layouts:
23+
#
24+
# - RPM
25+
# Built with default prefix=/usr
26+
#
27+
#
28+
# The following va+riables are used and can be overwritten
29+
#
30+
# INSTALL_LAYOUT installation layout (DEFAULT = standard for tar.gz and zip packages
31+
# RPM packages
32+
#
33+
# BIN_INSTALL_DIR location of binaries (mariadb_config)
34+
# LIB_INSTALL_DIR location of libraries
35+
# PLUGIN_INSTALL_DIR location of plugins
36+
37+
IF(NOT INSTALL_LAYOUT)
38+
SET(INSTALL_LAYOUT "DEFAULT")
39+
ENDIF()
40+
41+
SET(INSTALL_LAYOUT ${INSTALL_LAYOUT} CACHE
42+
STRING "Installation layout. Currently supported options are DEFAULT (tar.gz and zip) and RPM")
43+
44+
# On Windows we only provide zip and .msi. Latter one uses a different packager.
45+
IF(UNIX)
46+
IF(INSTALL_LAYOUT MATCHES "RPM")
47+
SET(libmariadb_prefix "/usr")
48+
ELSE()
49+
SET(libmariadb_prefix "/usr/local")
50+
ENDIF()
51+
ENDIF()
52+
53+
IF(CMAKE_DEFAULT_PREFIX_INITIALIZED_BY_DEFAULT)
54+
SET(CMAKE_DEFAULT_PREFIX ${libmariadb_prefix} CACHE PATH "Installation prefix" FORCE)
55+
ENDIF()
56+
57+
# check if the specified installation layout is valid
58+
SET(VALID_INSTALL_LAYOUTS "DEFAULT" "RPM")
59+
LIST(FIND VALID_INSTALL_LAYOUTS "${INSTALL_LAYOUT}" layout_no)
60+
IF(layout_no EQUAL -1)
61+
MESSAGE(FATAL_ERROR "Invalid installation layout. Please specify one of the following layouts: ${VALID_INSTALL_LAYOUTS}")
62+
ENDIF()
63+
64+
65+
66+
#
67+
# Todo: We don't generate man pages yet, will fix it
68+
# later (webhelp to man transformation)
69+
#
70+
71+
#
72+
# DEFAULT layout
73+
#
74+
SET(SUFFIX_INSTALL_DIR_DEFAULT "mariadb")
75+
SET(BIN_INSTALL_DIR_DEFAULT "bin")
76+
SET(LIB_INSTALL_DIR_DEFAULT "lib")
77+
SET(INCLUDE_INSTALL_DIR_DEFAULT "include")
78+
SET(DOCS_INSTALL_DIR_DEFAULT "docs")
79+
SET(LIB_INSTALL_PLUGIN_DIR_DEFAULT "lib/plugins")
80+
81+
#
82+
# RPM layout
83+
#
84+
SET(SUFFIX_INSTALL_DIR_RPM "mariadb")
85+
SET(BIN_INSTALL_DIR_RPM "bin")
86+
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
87+
SET(LIB_INSTALL_DIR_RPM "lib64")
88+
SET(LIB_INSTALL_PLUGINDIR_RPM "lib64/plugins")
89+
ELSE()
90+
SET(LIB_INSTALL_DIR_RPM "lib")
91+
SET(LIB_INSTALL_PLUGINDIR_RPM "lib/plugins")
92+
ENDIF()
93+
94+
SET(INCLUDE_INSTALL_DIR_RPM "include")
95+
SET(DOCS_INSTALL_DIR_RPM "docs")
96+
SET(LIB_INSTALL_PLUGIN_DIR_RPM "lib/plugins")
97+
98+
#
99+
# Overwrite defaults
100+
#
101+
IF(LIB_INSTALL_DIR)
102+
SET(LIB_INSTALL_DIR_${INSTALL_LAYOUT} ${LIB_INSTALL_DIR})
103+
ENDIF()
104+
105+
IF(INCLUDE_INSTALL_DIR)
106+
SET(INCLUDE_INSTALL_DIR_${INSTALL_LAYOUT} ${INCLUDE_INSTALL_DIR})
107+
ENDIF()
108+
109+
IF(BIN_INSTALL_DIR)
110+
SET(BIN_INSTALL_DIR_${INSTALL_LAYOUT} ${BIN_INSTALL_DIR})
111+
ENDIF()
112+
113+
IF(NOT PREFIX_INSTALL_DIR)
114+
SET(PREFIX_INSTALL_DIR_${INSTALL_LAYOUT} ${libmariadb_prefix})
115+
ENDIF()
116+
117+
IF(NOT SUFFIX_INSTALL_DIR)
118+
SET(SUFFIX_INSTALL_DIR_${INSTALL_LAYOUT} "mariadb")
119+
ENDIF()
120+
121+
FOREACH(dir "BIN" "LIB" "INCLUDE" "DOCS" "PREFIX" "SUFFIX")
122+
SET(${dir}_INSTALL_DIR ${${dir}_INSTALL_DIR_${INSTALL_LAYOUT}})
123+
MARK_AS_ADVANCED(${dir}_INSTALL_DIR)
124+
ENDFOREACH()

libmariadb/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,10 @@ ENDIF()
212212

213213
INSTALL(TARGETS
214214
libmariadb mariadbclient
215-
RUNTIME DESTINATION "${LIB_INSTALL_DIR}/mariadb"
216-
LIBRARY DESTINATION "${LIB_INSTALL_DIR}/mariadb"
217-
ARCHIVE DESTINATION "${LIB_INSTALL_DIR}/mariadb")
215+
RUNTIME DESTINATION "${LIB_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}"
216+
LIBRARY DESTINATION "${LIB_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}"
217+
ARCHIVE DESTINATION "${LIB_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}")
218+
218219
IF(NOT WIN32 AND WITH_MYSQLCOMPAT)
219220
INSTALL(FILES "${CMAKE_BINARY_DIR}/libmariadb/libmysql${CMAKE_SHARED_LIBRARY_SUFFIX}"
220221
"${CMAKE_BINARY_DIR}/libmariadb/libmysqlclient${CMAKE_SHARED_LIBRARY_SUFFIX}"
@@ -224,9 +225,9 @@ IF(NOT WIN32 AND WITH_MYSQLCOMPAT)
224225
ENDIF()
225226

226227
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/
227-
DESTINATION include/mariadb)
228+
DESTINATION ${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR})
228229
INSTALL(FILES
229230
${CMAKE_BINARY_DIR}/include/my_config.h
230231
${CMAKE_BINARY_DIR}/include/mysql_version.h
231-
DESTINATION include/mariadb
232-
)
232+
DESTINATION ${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR})
233+

mariadb_config/mariadb_config.c.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <getopt.h>
44
#include <stdio.h>
55

6-
#define INCLUDE "-I@INCLUDE_INSTALL_DIR@/mariadb"
7-
#define LIBS "-L@LIB_INSTALL_DIR@/mariadb -lmariadb" \
6+
#define INCLUDE "-I@PREFIX_INSTALL_DIR@/@INCLUDE_INSTALL_DIR@/@SUFFIX_INSTALL_DIR@"
7+
#define LIBS "-L@PREFIX_INSTALL_DIR@/@LIB_INSTALL_DIR@/@SUFFIX_INSTALL_DIR@ -lmariadb" \
88
"@extra_dynamic_LDFLAGS@"
99
#define CFLAGS INCLUDE " @CMAKE_C_FLAGS@"
1010
#define VERSION "@MYSQL_CLIENT_VERSION@"

0 commit comments

Comments
 (0)