Skip to content

Commit c827968

Browse files
committed
Handle different installation layouts.
using cmake option INSTALL_LAYOUT=STANDALONE would produce the layout as in tar.gz or zip packages. INSTALL_LAYOUT=UNIX will produce unixish install layout (with mysqld being in sbin subdirectory , libs in lib/mysql etc). This layout is used for RPM packages. Subtle differences in both packages unfortunately lead to the need to recompile MySQL to use with other package type - as otherwise for example default plugins or data directories would be wrong set. There are numerous other variables that allow fine-tuning packaging layout. (INSTALL_BINDIR, INSTALL_LIBDIR , INSTALL_PLUGINDIR etc). This options are different from autotools as they do not expect full paths to directories, but only subdirectory of CMAKE_INSTALL_PREFIX. There are 2 special options that expect full directory paths - MYSQL_DATADIR that defines default MYSQL data directory (autotools equivalent is --localstatedir) - SYSCONFDIR can be added to search my.cnf search path (autotools equivalent is --sysconfdir)
1 parent 80f57fb commit c827968

19 files changed

Lines changed: 256 additions & 92 deletions

CMakeLists.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ INCLUDE(libutils)
8282
INCLUDE(dtrace)
8383
INCLUDE(plugin)
8484
INCLUDE(install_macros)
85+
INCLUDE(install_layout)
8586
INCLUDE(mysql_add_executable)
8687

8788
# Handle options
@@ -165,12 +166,17 @@ IF(WIN32)
165166
SET(SHAREDIR share)
166167
ELSE()
167168
SET(DEFAULT_MYSQL_HOME ${CMAKE_INSTALL_PREFIX})
168-
SET(SHAREDIR ${DEFAULT_MYSQL_HOME}/share)
169+
SET(SHAREDIR ${DEFAULT_MYSQL_HOME}/${INSTALL_MYSQLSHAREDIR})
169170
ENDIF()
170171

171172
SET(DEFAULT_BASEDIR "${DEFAULT_MYSQL_HOME}")
172-
SET(MYSQL_DATADIR "${DEFAULT_MYSQL_HOME}/data")
173+
SET(MYSQL_DATADIR "${DEFAULT_MYSQL_HOME}/${INSTALL_MYSQLDATADIR}" CACHE PATH
174+
"default MySQL data directory")
173175
SET(DEFAULT_CHARSET_HOME "${DEFAULT_MYSQL_HOME}")
176+
SET(PLUGINDIR "${DEFAULT_MYSQL_HOME}/${INSTALL_PLUGINDIR}")
177+
IF(SYSCONFDIR)
178+
SET(DEFAULT_SYSCONFDIR "${SYSCONFDIR}")
179+
ENDIF()
174180

175181

176182
# Optionally read user configuration, generated by configure.js.
@@ -255,11 +261,11 @@ ELSE()
255261
SET(CPACK_GENERATOR "TGZ")
256262
ENDIF()
257263
INCLUDE(CPack)
258-
INSTALL(FILES COPYING EXCEPTIONS-CLIENT README DESTINATION .)
264+
INSTALL(FILES COPYING EXCEPTIONS-CLIENT README DESTINATION ${INSTALL_DOCREADMEDIR})
259265
IF(UNIX)
260-
INSTALL(FILES Docs/INSTALL-BINARY DESTINATION .)
266+
INSTALL(FILES Docs/INSTALL-BINARY DESTINATION ${INSTALL_DOCREADMEDIR})
261267
ENDIF()
262268
# MYSQL_DOCS_LOCATON is used in "make dist", points to the documentation directory
263269
SET(MYSQL_DOCS_LOCATION "" CACHE PATH "Location from where documentation is copied")
264270
MARK_AS_ADVANCED(MYSQL_DOCS_LOCATION)
265-
INSTALL(DIRECTORY Docs DESTINATION .)
271+
INSTALL(DIRECTORY Docs/ DESTINATION ${INSTALL_DOCDIR})

cmake/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ EXTRA_DIST = \
2121
merge_archives_unix.cmake.in \
2222
dtrace_prelink.cmake \
2323
versioninfo.rc.in \
24-
mysql_add_executable.cmake
24+
mysql_add_executable.cmake \
25+
install_layout.cmake

cmake/configure.pl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
foreach my $option (@ARGV)
1313
{
14-
1514
if (substr ($option, 0, 2) == "--")
1615
{
1716
$option = substr($option, 2);
@@ -83,6 +82,12 @@
8382
$cmakeargs = $cmakeargs." -DWITH_CHARSETS=complex";
8483
next;
8584
}
85+
if ($option =~ /localstatedir=/)
86+
{
87+
$cmakeargs = $cmakeargs." -DMYSQL_DATADIR=".substr($option,14);
88+
next;
89+
}
90+
8691
$option = uc($option);
8792
$option =~ s/-/_/g;
8893
$cmakeargs = $cmakeargs." -D".$option."=1";

cmake/install_layout.cmake

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Copyright (C) 2010 Sun Microsystems, Inc
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; version 2 of the License.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
16+
# The purpose of this file is to set the default installation layout.
17+
# Currently, there are 2 different installation layouts ,
18+
# one is used in tar.gz packages (Windows zip is about the same), another one
19+
# in RPMs.
20+
21+
# There are currently 2 layouts defines, named STANDALONE (tar.gz layout)
22+
# and UNIX (rpm layout). To force a directory layout when invoking cmake use
23+
# -DINSTALL_LAYOUT=[STANDALONE|UNIX].
24+
# This wil use a predefined layout. There is a possibility to further fine-tune
25+
# installation directories. Several variables are can be overwritten
26+
#
27+
# - INSTALL_BINDIR (directory with client executables and Unix shell scripts)
28+
# - INSTALL_SBINDIR (directory with mysqld)
29+
# - INSTALL_LIBDIR (directory with client end embedded libraries)
30+
# - INSTALL_PLUGINDIR (directory for plugins)
31+
# - INSTALL_INCLUDEDIR (directory for MySQL headers)
32+
# - INSTALL_DOCDIR (documentation)
33+
# - INSTALL_MANDIR (man pages)
34+
# - INSTALL_SCRIPTDIR (several scripts, rarely used)
35+
# - INSTALL_MYSQLSHAREDIR (MySQL character sets and localized error messages)
36+
# - INSTALL_SHAREDIR (location of aclocal/mysql.m4)
37+
# - INSTALL_SQLBENCHDIR (sql-bench)
38+
# - INSTALL_MYSQLTESTDIR (mysql-test)
39+
# - INSTALL_DOCREADMEDIR (readme and similar)
40+
# - INSTALL_SUPPORTFILESDIR (used only in standalone installer)
41+
42+
# Default installation layout on Unix is UNIX (kent wants it so)
43+
IF(NOT INSTALL_LAYOUT)
44+
IF(WIN32)
45+
SET(DEFAULT_INSTALL_LAYOUT "STANDALONE")
46+
ELSE()
47+
SET(DEFAULT_INSTALL_LAYOUT "UNIX")
48+
ENDIF()
49+
ENDIF()
50+
51+
SET(INSTALL_LAYOUT "${DEFAULT_INSTALL_LAYOUT}"
52+
CACHE STRING "Installation directory layout. Options are: STANDALONE (as in zip or tar.gz installer) or UNIX")
53+
54+
IF(NOT INSTALL_LAYOUT MATCHES "STANDALONE")
55+
IF(NOT INSTALL_LAYOUT MATCHES "UNIX")
56+
SET(INSTALL_LAYOUT "${DEFAULT_INSTALL_LAYOUT}")
57+
ENDIF()
58+
ENDIF()
59+
60+
IF(UNIX)
61+
IF(INSTALL_LAYOUT MATCHES "UNIX")
62+
SET(default_prefix "/usr")
63+
ELSE()
64+
SET(default_prefix "/usr/local/mysql")
65+
ENDIF()
66+
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
67+
SET(CMAKE_INSTALL_PREFIX ${default_prefix}
68+
CACHE PATH "install prefix" FORCE)
69+
ENDIF()
70+
SET(SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/etc"
71+
CACHE PATH "config directory (for my.cnf)")
72+
MARK_AS_ADVANCED(SYSCONFDIR)
73+
ENDIF()
74+
75+
76+
77+
# STANDALONE layout
78+
SET(INSTALL_BINDIR_STANDALONE "bin")
79+
SET(INSTALL_SBINDIR_STANDALONE "bin")
80+
SET(INSTALL_LIBDIR_STANDALONE "lib")
81+
SET(INSTALL_INCLUDEDIR_STANDALONE "include")
82+
SET(INSTALL_PLUGINDIR_STANDALONE "lib/plugin")
83+
SET(INSTALL_DOCDIR_STANDALONE "doc")
84+
SET(INSTALL_MANDIR_STANDALONE "man")
85+
SET(INSTALL_MYSQLSHAREDIR_STANDALONE "share")
86+
SET(INSTALL_SHAREDIR_STANDALONE "share")
87+
SET(INSTALL_SCRIPTDIR_STANDALONE "scripts")
88+
SET(INSTALL_MYSQLTESTDIR_STANDALONE "mysql-test")
89+
SET(INSTALL_SQLBENCHROOTDIR_STANDALONE ".")
90+
SET(INSTALL_DOCREADMEDIR_STANDALONE ".")
91+
SET(INSTALL_SUPPORTFILESDIR_STANDALONE "support-files")
92+
SET(INSTALL_MYSQLDATADIR_STANDALONE "data")
93+
94+
# UNIX layout
95+
SET(INSTALL_BINDIR_UNIX "bin")
96+
SET(INSTALL_SBINDIR_UNIX "sbin")
97+
SET(INSTALL_LIBDIR_UNIX "lib/mysql")
98+
SET(INSTALL_PLUGINDIR_UNIX "lib/mysql/plugin")
99+
SET(INSTALL_DOCDIR_UNIX "share/mysql/doc/MySQL-server-${MYSQL_NO_DASH_VERSION}")
100+
SET(INSTALL_MANDIR_UNIX "share/mysql/man")
101+
SET(INSTALL_INCLUDEDIR_UNIX "include/mysql")
102+
SET(INSTALL_MYSQLSHAREDIR_UNIX "share/mysql")
103+
SET(INSTALL_SHAREDIR_UNIX "share")
104+
SET(INSTALL_SCRIPTDIR_UNIX "bin")
105+
SET(INSTALL_MYSQLTESTDIR_UNIX "mysql-test")
106+
SET(INSTALL_SQLBENCHROOTDIR_UNIX "")
107+
SET(INSTALL_DOCREADMEDIR_UNIX "share/mysql/doc/MySQL-server-${MYSQL_NO_DASH_VERSION}")
108+
SET(INSTALL_SUPPORTFILESDIR_UNIX "")
109+
SET(INSTALL_MYSQLDATADIR_STANDALONE "var")
110+
111+
112+
# Clear cached variables if install layout was changed
113+
IF(OLD_INSTALL_LAYOUT)
114+
IF(NOT OLD_INSTALL_LAYOUT STREQUAL INSTALL_LAYOUR)
115+
SET(FORCE FORCE)
116+
ENDIF()
117+
ENDIF()
118+
SET(OLD_INSTALL_LAYOUT ${INSTALL_LAYOUT} CACHE INTERNAL "")
119+
120+
# Set INSTALL_FOODIR variables for chosen layout
121+
# (for example, INSTALL_BINDIR will be defined as
122+
# ${INSTALL_BINDIR_STANDALONE} by default if STANDALONE layout is chosen)
123+
FOREACH(var BIN SBIN LIB MYSQLSHARE SHARE PLUGIN INCLUDE SCRIPT DOC MAN
124+
MYSQLTEST SQLBENCHROOT DOCREADME SUPPORTFILES MYSQLDATA)
125+
SET(INSTALL_${var}DIR ${INSTALL_${var}DIR_${INSTALL_LAYOUT}}
126+
CACHE STRING "${var} installation directory" ${FORCE})
127+
MARK_AS_ADVANCED(INSTALL_${var}DIR)
128+
ENDFOREACH()

cmake/libutils.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ MACRO(MERGE_LIBRARIES)
257257
MESSAGE(FATAL_ERROR "Unknown library type")
258258
ENDIF()
259259
IF(NOT ARG_NOINSTALL)
260-
MYSQL_INSTALL_TARGETS(${TARGET} DESTINATION lib)
260+
MYSQL_INSTALL_TARGETS(${TARGET} DESTINATION "${INSTALL_LIBDIR}")
261261
ENDIF()
262262
ENDMACRO()
263263

cmake/mysql_add_executable.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ INCLUDE(cmake_parse_arguments)
2929
FUNCTION (MYSQL_ADD_EXECUTABLE)
3030
# Pass-through arguments for ADD_EXECUTABLE
3131
CMAKE_PARSE_ARGUMENTS(ARG
32-
"WIN32;MACOSX_BUNDLE;EXCLUDE_FROM_ALL"
32+
"WIN32;MACOSX_BUNDLE;EXCLUDE_FROM_ALL;DESTINATION"
3333
""
3434
${ARGN}
3535
)
@@ -41,6 +41,9 @@ FUNCTION (MYSQL_ADD_EXECUTABLE)
4141
ADD_EXECUTABLE(${target} ${ARG_WIN32} ${ARG_MACOSX_BUNDLE} ${ARG_EXCLUDE_FROM_ALL} ${sources})
4242
# tell CPack where to install
4343
IF(NOT ARG_EXCLUDE_FROM_ALL)
44-
MYSQL_INSTALL_TARGETS(${target} DESTINATION bin)
44+
IF(NOT ARG_DESTINATION)
45+
SET(ARG_DESTINATION ${INSTALL_BINDIR})
46+
ENDIF()
47+
MYSQL_INSTALL_TARGETS(${target} DESTINATION ${ARG_DESTINATION})
4548
ENDIF()
4649
ENDFUNCTION()

cmake/plugin.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ MACRO(MYSQL_ADD_PLUGIN)
162162
SET_TARGET_PROPERTIES(${target} PROPERTIES
163163
OUTPUT_NAME "${ARG_MODULE_OUTPUT_NAME}")
164164
# Install dynamic library
165-
SET(INSTALL_LOCATION lib/plugin)
166-
MYSQL_INSTALL_TARGETS(${target} DESTINATION ${INSTALL_LOCATION})
165+
MYSQL_INSTALL_TARGETS(${target} DESTINATION ${INSTALL_PLUGINDIR})
167166
ENDIF()
168167
ENDMACRO()
169168

config.h.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,8 @@
636636
#cmakedefine DEFAULT_BASEDIR "@DEFAULT_BASEDIR@"
637637
#cmakedefine MYSQL_DATADIR "@MYSQL_DATADIR@"
638638
#cmakedefine DEFAULT_CHARSET_HOME "@DEFAULT_CHARSET_HOME@"
639+
#cmakedefine PLUGINDIR "@PLUGINDIR@"
640+
#cmakedefine DEFAULT_SYSCONFDIR "@DEFAULT_SYSCONFDIR@"
639641

640642
#define PACKAGE "mysql"
641643
#define PACKAGE_BUGREPORT ""

include/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ SET(HEADERS
5454
${HEADERS_GEN_CONFIGURE}
5555
)
5656

57-
INSTALL(FILES ${HEADERS} DESTINATION include)
58-
INSTALL(DIRECTORY mysql/ DESTINATION include
59-
FILES_MATCHING PATTERN "*.h")
57+
INSTALL(FILES ${HEADERS} DESTINATION ${INSTALL_INCLUDEDIR})
58+
INSTALL(DIRECTORY mysql/ DESTINATION ${INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h")
6059

6160

libmysql/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ SET(LIBS clientlib dbug strings vio mysys ${ZLIB_LIBRARY} ${SSL_LIBRARIES})
154154
# and link them together into shared library.
155155
MERGE_LIBRARIES(mysqlclient STATIC ${LIBS})
156156
IF(UNIX)
157-
INSTALL_SYMLINK(${CMAKE_STATIC_LIBRARY_PREFIX}mysqlclient_r mysqlclient lib)
157+
INSTALL_SYMLINK(${CMAKE_STATIC_LIBRARY_PREFIX}mysqlclient_r mysqlclient ${INSTALL_LIBDIR})
158158
ENDIF()
159159

160160
IF(NOT DISABLE_SHARED)
@@ -177,6 +177,6 @@ IF(NOT DISABLE_SHARED)
177177
#(mysqlclient in this case)
178178
SET_TARGET_PROPERTIES(mysqlclient PROPERTIES CLEAN_DIRECT_OUTPUT 1)
179179
SET_TARGET_PROPERTIES(libmysql PROPERTIES CLEAN_DIRECT_OUTPUT 1)
180-
INSTALL_SYMLINK(${CMAKE_SHARED_LIBRARY_PREFIX}mysqlclient_r libmysql lib)
180+
INSTALL_SYMLINK(${CMAKE_SHARED_LIBRARY_PREFIX}mysqlclient_r libmysql ${INSTALL_LIBDIR})
181181
ENDIF()
182182
ENDIF()

0 commit comments

Comments
 (0)