]> git.openstreetmap.org Git - nominatim.git/blob - CMakeLists.txt
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / CMakeLists.txt
1 #-----------------------------------------------------------------------------
2 #
3 #  CMake Config
4 #
5 #  Nominatim
6 #
7 #-----------------------------------------------------------------------------
8
9 cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
10 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
11
12
13 #-----------------------------------------------------------------------------
14 #
15 #  Project version
16 #
17 #-----------------------------------------------------------------------------
18
19 project(nominatim)
20
21 set(NOMINATIM_VERSION_MAJOR 4)
22 set(NOMINATIM_VERSION_MINOR 4)
23 set(NOMINATIM_VERSION_PATCH 0)
24
25 set(NOMINATIM_VERSION "${NOMINATIM_VERSION_MAJOR}.${NOMINATIM_VERSION_MINOR}.${NOMINATIM_VERSION_PATCH}")
26
27 add_definitions(-DNOMINATIM_VERSION="${NOMINATIM_VERSION}")
28
29 # Setting GIT_HASH
30 find_package(Git)
31 if (GIT_FOUND)
32     execute_process(
33         COMMAND "${GIT_EXECUTABLE}" log -1 --format=%h
34         WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
35         OUTPUT_VARIABLE GIT_HASH
36         OUTPUT_STRIP_TRAILING_WHITESPACE
37         ERROR_QUIET
38         )
39 endif()
40
41 #-----------------------------------------------------------------------------
42 #  Configuration
43 #-----------------------------------------------------------------------------
44
45 set(BUILD_IMPORTER on CACHE BOOL "Build everything for importing/updating the database")
46 set(BUILD_API on CACHE BOOL "Build everything for the API server")
47 set(BUILD_MODULE off CACHE BOOL "Build PostgreSQL module for legacy tokenizer")
48 set(BUILD_TESTS on CACHE BOOL "Build test suite")
49 set(BUILD_OSM2PGSQL on CACHE BOOL "Build osm2pgsql (expert only)")
50 set(INSTALL_MUNIN_PLUGINS on CACHE BOOL "Install Munin plugins for supervising Nominatim")
51
52 #-----------------------------------------------------------------------------
53 #  osm2pgsql (imports/updates only)
54 #-----------------------------------------------------------------------------
55
56 if (BUILD_IMPORTER AND BUILD_OSM2PGSQL)
57     if (NOT EXISTS "${CMAKE_SOURCE_DIR}/osm2pgsql/CMakeLists.txt")
58         message(FATAL_ERROR "The osm2pgsql directory is empty.\
59         Did you forget to check out Nominatim recursively?\
60         \nTry updating submodules with: git submodule update --init")
61     endif()
62     set(BUILD_TESTS_SAVED "${BUILD_TESTS}")
63     set(BUILD_TESTS off)
64     add_subdirectory(osm2pgsql)
65     set(BUILD_TESTS ${BUILD_TESTS_SAVED})
66 endif()
67
68
69 #-----------------------------------------------------------------------------
70 #  python (imports/updates only)
71 #-----------------------------------------------------------------------------
72
73 if (BUILD_IMPORTER OR BUILD_API)
74     find_package(PythonInterp 3.7 REQUIRED)
75 endif()
76
77 #-----------------------------------------------------------------------------
78 # PHP
79 #-----------------------------------------------------------------------------
80
81 # Setting PHP binary variable as to command line (prevailing) or auto detect
82
83 if (BUILD_API)
84     if (NOT PHP_BIN)
85          find_program (PHP_BIN php)
86     endif()
87     # sanity check if PHP binary exists
88     if (NOT EXISTS ${PHP_BIN})
89         message(WARNING "PHP binary not found. Only Python frontend can be used.")
90         set(PHP_BIN "")
91     else()
92         message (STATUS "Using PHP binary " ${PHP_BIN})
93     endif()
94 endif()
95
96 #-----------------------------------------------------------------------------
97 # import scripts and utilities (importer only)
98 #-----------------------------------------------------------------------------
99
100 if (BUILD_IMPORTER)
101    find_file(COUNTRY_GRID_FILE country_osm_grid.sql.gz
102              PATHS ${PROJECT_SOURCE_DIR}/data
103              NO_DEFAULT_PATH
104              DOC "Location of the country grid file."
105             )
106
107    if (NOT COUNTRY_GRID_FILE)
108        message(FATAL_ERROR "\nYou need to download the country_osm_grid first:\n"
109                            "    wget -O ${PROJECT_SOURCE_DIR}/data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz")
110    endif()
111
112    configure_file(${PROJECT_SOURCE_DIR}/cmake/tool.tmpl
113                   ${PROJECT_BINARY_DIR}/nominatim)
114 endif()
115
116 #-----------------------------------------------------------------------------
117 # Targets for running a development webserver from the build directory.
118 #-----------------------------------------------------------------------------
119
120 if (BUILD_API)
121    set(WEBSITEFILES
122        403.html
123        509.html
124        crossdomain.xml
125        favicon.ico
126        nominatim.xml
127        robots.txt
128        taginfo.json
129    )
130
131    foreach (webfile ${WEBSITEFILES})
132        configure_file(${PROJECT_SOURCE_DIR}/website/${webfile}
133                       ${PROJECT_BINARY_DIR}/website/${webfile})
134    endforeach()
135 endif()
136
137 #-----------------------------------------------------------------------------
138 # Tests
139 #-----------------------------------------------------------------------------
140
141 if (BUILD_TESTS)
142     include(CTest)
143
144     set(TEST_BDD db osm2pgsql api)
145
146     find_program(PYTHON_BEHAVE behave)
147     find_program(PYLINT NAMES pylint3 pylint)
148     find_program(PYTEST NAMES pytest py.test-3 py.test)
149     find_program(PHPCS phpcs)
150     find_program(PHPUNIT phpunit)
151
152     if (PYTHON_BEHAVE)
153         message(STATUS "Using Python behave binary ${PYTHON_BEHAVE}")
154         foreach (test ${TEST_BDD})
155             add_test(NAME bdd_${test}
156                      COMMAND ${PYTHON_BEHAVE} ${test}
157                      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test/bdd)
158             set_tests_properties(bdd_${test}
159                 PROPERTIES ENVIRONMENT "NOMINATIM_DIR=${PROJECT_BINARY_DIR}")
160         endforeach()
161     else()
162         message(WARNING "behave not found. BDD tests disabled." )
163     endif()
164
165     if (PHPUNIT)
166         message(STATUS "Using phpunit binary ${PHPUNIT}")
167         add_test(NAME php
168                  COMMAND ${PHPUNIT} ./
169                  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test/php)
170     else()
171         message(WARNING "phpunit not found. PHP unit tests disabled." )
172     endif()
173
174     if (PHPCS)
175         message(STATUS "Using phpcs binary ${PHPCS}")
176         add_test(NAME phpcs
177                  COMMAND ${PHPCS} --report-width=120 --colors lib-php
178                  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
179     else()
180         message(WARNING "phpcs not found. PHP linting tests disabled." )
181     endif()
182
183     if (PYLINT)
184         message(STATUS "Using pylint binary ${PYLINT}")
185         add_test(NAME pylint
186                  COMMAND ${PYLINT} nominatim
187                  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
188     else()
189         message(WARNING "pylint not found. Python linting tests disabled.")
190     endif()
191
192     if (PYTEST)
193         message(STATUS "Using pytest binary ${PYTEST}")
194         add_test(NAME pytest
195                  COMMAND ${PYTEST} test/python
196                  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
197     else()
198         message(WARNING "pytest not found. Python tests disabled." )
199     endif()
200 endif()
201
202 #-----------------------------------------------------------------------------
203 # Postgres module
204 #-----------------------------------------------------------------------------
205
206 if (BUILD_MODULE)
207     add_subdirectory(module)
208 endif()
209
210 #-----------------------------------------------------------------------------
211 # Installation
212 #-----------------------------------------------------------------------------
213
214
215 include(GNUInstallDirs)
216 set(NOMINATIM_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME})
217 set(NOMINATIM_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR}/${PROJECT_NAME})
218 set(NOMINATIM_CONFIGDIR ${CMAKE_INSTALL_FULL_SYSCONFDIR}/${PROJECT_NAME})
219 set(NOMINATIM_MUNINDIR ${CMAKE_INSTALL_FULL_DATADIR}/munin/plugins)
220
221 if (BUILD_IMPORTER)
222     configure_file(${PROJECT_SOURCE_DIR}/cmake/tool-installed.tmpl installed.bin)
223     install(PROGRAMS ${PROJECT_BINARY_DIR}/installed.bin
224             DESTINATION ${CMAKE_INSTALL_BINDIR}
225             RENAME nominatim)
226
227     if (EXISTS ${PHP_BIN})
228         configure_file(${PROJECT_SOURCE_DIR}/cmake/paths-py.tmpl paths-py.installed)
229     else()
230         configure_file(${PROJECT_SOURCE_DIR}/cmake/paths-py-no-php.tmpl paths-py.installed)
231     endif()
232
233     foreach (submodule nominatim_db nominatim_api)
234         install(DIRECTORY src/${submodule}
235                 DESTINATION ${NOMINATIM_LIBDIR}/lib-python
236                 FILES_MATCHING PATTERN "*.py"
237                 PATTERN "paths.py" EXCLUDE
238                 PATTERN __pycache__ EXCLUDE)
239         install(FILES ${PROJECT_BINARY_DIR}/paths-py.installed
240                 DESTINATION ${NOMINATIM_LIBDIR}/lib-python/${submodule}
241                 RENAME paths.py)
242     endforeach()
243
244     install(DIRECTORY lib-sql DESTINATION ${NOMINATIM_LIBDIR})
245
246     install(FILES ${COUNTRY_GRID_FILE}
247                   data/words.sql
248             DESTINATION ${NOMINATIM_DATADIR})
249 endif()
250
251 if (BUILD_OSM2PGSQL)
252     if (${CMAKE_VERSION} VERSION_LESS 3.13)
253         # Installation of subdirectory targets was only introduced in 3.13.
254         # So just copy the osm2pgsql file for older versions.
255         install(PROGRAMS ${PROJECT_BINARY_DIR}/osm2pgsql/osm2pgsql
256                 DESTINATION ${NOMINATIM_LIBDIR})
257     else()
258         install(TARGETS osm2pgsql RUNTIME DESTINATION ${NOMINATIM_LIBDIR})
259     endif()
260 endif()
261
262 if (BUILD_MODULE)
263     install(PROGRAMS ${PROJECT_BINARY_DIR}/module/nominatim.so
264             DESTINATION ${NOMINATIM_LIBDIR}/module)
265 endif()
266
267 if (BUILD_API AND EXISTS ${PHP_BIN})
268     install(DIRECTORY lib-php DESTINATION ${NOMINATIM_LIBDIR})
269 endif()
270
271 install(FILES settings/env.defaults
272               settings/address-levels.json
273               settings/phrase-settings.json
274               settings/import-admin.lua
275               settings/import-street.lua
276               settings/import-address.lua
277               settings/import-full.lua
278               settings/import-extratags.lua
279               settings/flex-base.lua
280               settings/icu_tokenizer.yaml
281               settings/country_settings.yaml
282         DESTINATION ${NOMINATIM_CONFIGDIR})
283
284 install(DIRECTORY settings/icu-rules
285         DESTINATION ${NOMINATIM_CONFIGDIR})
286 install(DIRECTORY settings/country-names
287         DESTINATION ${NOMINATIM_CONFIGDIR})
288
289 if (INSTALL_MUNIN_PLUGINS)
290     install(FILES munin/nominatim_importlag
291                   munin/nominatim_query_speed
292                   munin/nominatim_requests
293             DESTINATION ${NOMINATIM_MUNINDIR})
294 endif()