1# Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
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, version 2.0,
5# as published by the Free Software Foundation.
6#
7# This program is also distributed with certain software (including
8# but not limited to OpenSSL) that is licensed under separate terms,
9# as designated in a particular file or component or in included license
10# documentation.  The authors of MySQL hereby grant you an additional
11# permission to link the program and your derivative works with the
12# separately licensed software that they have included with MySQL.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
23
24# installed executable location (used in config.h)
25IF(IS_ABSOLUTE "${ROUTER_INSTALL_BINDIR}")
26  SET(ROUTER_BINDIR ${ROUTER_INSTALL_BINDIR})
27ELSE()
28  SET(ROUTER_BINDIR ${CMAKE_INSTALL_PREFIX}/${ROUTER_INSTALL_BINDIR})
29ENDIF()
30
31# Configuration folder (config_folder configuration option)
32IF(WIN32)
33  SET(_configdir "ENV{APPDATA}")
34ELSE()
35  IF(IS_ABSOLUTE ${ROUTER_INSTALL_CONFIGDIR})
36    SET(_configdir "${ROUTER_INSTALL_CONFIGDIR}")
37  ELSEIF(INSTALL_CONFIGDIR STREQUAL ".")
38    # Current working directory
39    SET(_configdir "${ROUTER_INSTALL_CONFIGDIR}")
40  ELSE()
41    SET(_configdir "${CMAKE_INSTALL_PREFIX}/${ROUTER_INSTALL_CONFIGDIR}")
42  ENDIF()
43ENDIF()
44SET(ROUTER_CONFIGDIR ${_configdir})
45UNSET(_configdir)
46
47# Logging folder (logging_folder configuration option)
48IF(WIN32)
49  SET(_logdir "ENV{APPDATA}\\\\log")
50ELSE()
51  # logging folder can be set to empty to log to console
52  IF(IS_ABSOLUTE "${ROUTER_INSTALL_LOGDIR}")
53    SET(_logdir ${ROUTER_INSTALL_LOGDIR})
54  ELSEIF(NOT ROUTER_INSTALL_LOGDIR)
55    SET(_logdir "/var/log/mysqlrouter/")
56  ELSE()
57    SET(_logdir ${CMAKE_INSTALL_PREFIX}/${ROUTER_INSTALL_LOGDIR})
58  ENDIF()
59ENDIF()
60SET(ROUTER_LOGDIR ${_logdir}
61  CACHE STRING "Location of log files; empty is console (logging_folder)")
62UNSET(_logdir)
63
64# Runtime folder (runtime_folder configuration option)
65IF(WIN32)
66  SET(_runtimedir "ENV{APPDATA}")
67ELSE()
68  IF(IS_ABSOLUTE "${ROUTER_INSTALL_RUNTIMEDIR}")
69    SET(_runtimedir ${ROUTER_INSTALL_RUNTIMEDIR})
70  ELSEIF(NOT ROUTER_INSTALL_RUNTIMEDIR)
71    SET(_runtimedir "/var/run/mysqlrouter/")
72  ELSE()
73    SET(_runtimedir ${CMAKE_INSTALL_PREFIX}/${ROUTER_INSTALL_RUNTIMEDIR})
74  ENDIF()
75ENDIF()
76SET(ROUTER_RUNTIMEDIR ${_runtimedir}
77  CACHE STRING "Location runtime files such as PID file (runtime_folder)")
78UNSET(_runtimedir)
79
80# Plugin folder (plugin_folder configuration option)
81IF(IS_ABSOLUTE "${ROUTER_INSTALL_PLUGINDIR}")
82  SET(_plugindir ${ROUTER_INSTALL_PLUGINDIR})
83ELSE()
84  SET(_plugindir ${CMAKE_INSTALL_PREFIX}/${ROUTER_INSTALL_PLUGINDIR})
85ENDIF()
86SET(ROUTER_PLUGINDIR ${_plugindir}
87  CACHE STRING "Location MySQL Router plugins (plugin_folder)")
88UNSET(_plugindir)
89
90# Data folder (data_folder configuration option)
91IF(WIN32)
92  SET(_datadir "ENV{APPDATA}\\\\data")
93ELSE()
94  IF(IS_ABSOLUTE "${ROUTER_INSTALL_DATADIR}")
95    SET(_datadir ${ROUTER_INSTALL_DATADIR})
96  ELSEIF(NOT ROUTER_INSTALL_DATADIR)
97    SET(_datadir "/var/lib/mysqlrouter/")
98  ELSE()
99    SET(_datadir "${CMAKE_INSTALL_PREFIX}/${ROUTER_INSTALL_DATADIR}")
100  ENDIF()
101ENDIF()
102SET(ROUTER_DATADIR ${_datadir}
103  CACHE STRING "Location of data files such as keyring file")
104UNSET(_datadir)
105
106IF(INSTALL_LAYOUT STREQUAL "STANDALONE")
107  SET(ROUTER_PLUGINDIR "{origin}/../${ROUTER_INSTALL_PLUGINDIR}")
108  SET(ROUTER_CONFIGDIR "{origin}/../${ROUTER_INSTALL_CONFIGDIR}")
109  SET(ROUTER_RUNTIMEDIR "{origin}/../${ROUTER_INSTALL_RUNTIMEDIR}")
110  SET(ROUTER_LOGDIR "{origin}/../${ROUTER_INSTALL_LOGDIR}")
111  SET(ROUTER_DATADIR "{origin}/../${ROUTER_INSTALL_DATADIR}")
112ENDIF()
113
114# Default configuration file locations (similar to MySQL Server)
115IF(WIN32)
116  SET(CONFIG_FILE_LOCATIONS
117      "${ROUTER_CONFIGDIR}/${MYSQL_ROUTER_INI}"
118      "ENV{APPDATA}/${MYSQL_ROUTER_INI}"
119      )
120ELSE()
121  SET(CONFIG_FILE_LOCATIONS
122      "${ROUTER_CONFIGDIR}/${MYSQL_ROUTER_INI}"
123      "ENV{HOME}/.${MYSQL_ROUTER_INI}"
124      )
125ENDIF()
126SET(CONFIG_FILES ${CONFIG_FILE_LOCATIONS})
127
128# check if platform supports prlimit()
129INCLUDE(CMakePushCheckState)
130cmake_push_check_state()
131cmake_reset_check_state()
132INCLUDE(CheckSymbolExists)
133SET(CMAKE_REQUIRED_FLAGS -D_GNU_SOURCE)
134check_symbol_exists(prlimit sys/resource.h HAVE_PRLIMIT)
135cmake_pop_check_state()
136
137CONFIGURE_FILE(config.h.in router_config.h @ONLY)
138INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
139