1 #-----------------------------------------------------------------------------
7 #-----------------------------------------------------------------------------
9 cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
10 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
13 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
21 set(NOMINATIM_VERSION_MAJOR 4)
22 set(NOMINATIM_VERSION_MINOR 2)
23 set(NOMINATIM_VERSION_PATCH 0)
25 set(NOMINATIM_VERSION "${NOMINATIM_VERSION_MAJOR}.${NOMINATIM_VERSION_MINOR}.${NOMINATIM_VERSION_PATCH}")
27 add_definitions(-DNOMINATIM_VERSION="${NOMINATIM_VERSION}")
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
41 #-----------------------------------------------------------------------------
43 #-----------------------------------------------------------------------------
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_DOCS on CACHE BOOL "Build documentation")
50 set(BUILD_MANPAGE on CACHE BOOL "Build Manual Page")
51 set(BUILD_OSM2PGSQL on CACHE BOOL "Build osm2pgsql (expert only)")
52 set(INSTALL_MUNIN_PLUGINS on CACHE BOOL "Install Munin plugins for supervising Nominatim")
54 #-----------------------------------------------------------------------------
55 # osm2pgsql (imports/updates only)
56 #-----------------------------------------------------------------------------
58 if (BUILD_IMPORTER AND BUILD_OSM2PGSQL)
59 if (NOT EXISTS "${CMAKE_SOURCE_DIR}/osm2pgsql/CMakeLists.txt")
60 message(FATAL_ERROR "The osm2pgsql directory is empty.\
61 Did you forget to check out Nominatim recursively?\
62 \nTry updating submodules with: git submodule update --init")
64 set(BUILD_TESTS_SAVED "${BUILD_TESTS}")
66 add_subdirectory(osm2pgsql)
67 set(BUILD_TESTS ${BUILD_TESTS_SAVED})
71 #-----------------------------------------------------------------------------
72 # python (imports/updates only)
73 #-----------------------------------------------------------------------------
76 find_package(PythonInterp 3.6 REQUIRED)
79 #-----------------------------------------------------------------------------
81 #-----------------------------------------------------------------------------
83 # Setting PHP binary variable as to command line (prevailing) or auto detect
85 if (BUILD_API OR BUILD_IMPORTER)
87 find_program (PHP_BIN php)
89 # sanity check if PHP binary exists
90 if (NOT EXISTS ${PHP_BIN})
91 message(FATAL_ERROR "PHP binary not found. Install php or provide location with -DPHP_BIN=/path/php ")
93 message (STATUS "Using PHP binary " ${PHP_BIN})
96 find_program (PHPCGI_BIN php-cgi)
98 # sanity check if PHP binary exists
99 if (NOT EXISTS ${PHPCGI_BIN})
100 message(WARNING "php-cgi binary not found. nominatim tool will not provide query functions.")
103 message (STATUS "Using php-cgi binary " ${PHPCGI_BIN})
107 #-----------------------------------------------------------------------------
108 # import scripts and utilities (importer only)
109 #-----------------------------------------------------------------------------
112 find_file(COUNTRY_GRID_FILE country_osm_grid.sql.gz
113 PATHS ${PROJECT_SOURCE_DIR}/data
115 DOC "Location of the country grid file."
118 if (NOT COUNTRY_GRID_FILE)
119 message(FATAL_ERROR "\nYou need to download the country_osm_grid first:\n"
120 " wget -O ${PROJECT_SOURCE_DIR}/data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz")
123 configure_file(${PROJECT_SOURCE_DIR}/cmake/tool.tmpl
124 ${PROJECT_BINARY_DIR}/nominatim)
127 #-----------------------------------------------------------------------------
129 #-----------------------------------------------------------------------------
134 set(TEST_BDD db osm2pgsql api)
136 find_program(PYTHON_BEHAVE behave)
137 find_program(PYLINT NAMES pylint3 pylint)
138 find_program(PYTEST NAMES pytest py.test-3 py.test)
139 find_program(PHPCS phpcs)
140 find_program(PHPUNIT phpunit)
143 message(STATUS "Using Python behave binary ${PYTHON_BEHAVE}")
144 foreach (test ${TEST_BDD})
145 add_test(NAME bdd_${test}
146 COMMAND ${PYTHON_BEHAVE} ${test}
147 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test/bdd)
148 set_tests_properties(bdd_${test}
149 PROPERTIES ENVIRONMENT "NOMINATIM_DIR=${PROJECT_BINARY_DIR}")
152 message(WARNING "behave not found. BDD tests disabled." )
156 message(STATUS "Using phpunit binary ${PHPUNIT}")
158 COMMAND ${PHPUNIT} ./
159 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test/php)
161 message(WARNING "phpunit not found. PHP unit tests disabled." )
165 message(STATUS "Using phpcs binary ${PHPCS}")
167 COMMAND ${PHPCS} --report-width=120 --colors lib-php
168 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
170 message(WARNING "phpcs not found. PHP linting tests disabled." )
174 message(STATUS "Using pylint binary ${PYLINT}")
176 COMMAND ${PYLINT} nominatim
177 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
179 message(WARNING "pylint not found. Python linting tests disabled.")
183 message(STATUS "Using pytest binary ${PYTEST}")
185 COMMAND ${PYTEST} test/python
186 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
188 message(WARNING "pytest not found. Python tests disabled." )
192 #-----------------------------------------------------------------------------
194 #-----------------------------------------------------------------------------
197 add_subdirectory(module)
200 #-----------------------------------------------------------------------------
202 #-----------------------------------------------------------------------------
205 add_subdirectory(docs)
208 #-----------------------------------------------------------------------------
210 #-----------------------------------------------------------------------------
213 add_subdirectory(man)
216 #-----------------------------------------------------------------------------
218 #-----------------------------------------------------------------------------
221 include(GNUInstallDirs)
222 set(NOMINATIM_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME})
223 set(NOMINATIM_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR}/${PROJECT_NAME})
224 set(NOMINATIM_CONFIGDIR ${CMAKE_INSTALL_FULL_SYSCONFDIR}/${PROJECT_NAME})
225 set(NOMINATIM_MUNINDIR ${CMAKE_INSTALL_FULL_DATADIR}/munin/plugins)
228 configure_file(${PROJECT_SOURCE_DIR}/cmake/tool-installed.tmpl installed.bin)
229 install(PROGRAMS ${PROJECT_BINARY_DIR}/installed.bin
230 DESTINATION ${CMAKE_INSTALL_BINDIR}
233 install(DIRECTORY nominatim
234 DESTINATION ${NOMINATIM_LIBDIR}/lib-python
235 FILES_MATCHING PATTERN "*.py"
236 PATTERN __pycache__ EXCLUDE)
237 install(DIRECTORY lib-sql DESTINATION ${NOMINATIM_LIBDIR})
239 install(FILES ${COUNTRY_GRID_FILE}
241 DESTINATION ${NOMINATIM_DATADIR})
245 if (${CMAKE_VERSION} VERSION_LESS 3.13)
246 # Installation of subdirectory targets was only introduced in 3.13.
247 # So just copy the osm2pgsql file for older versions.
248 install(PROGRAMS ${PROJECT_BINARY_DIR}/osm2pgsql/osm2pgsql
249 DESTINATION ${NOMINATIM_LIBDIR})
251 install(TARGETS osm2pgsql RUNTIME DESTINATION ${NOMINATIM_LIBDIR})
256 install(PROGRAMS ${PROJECT_BINARY_DIR}/module/nominatim.so
257 DESTINATION ${NOMINATIM_LIBDIR}/module)
261 install(DIRECTORY lib-php DESTINATION ${NOMINATIM_LIBDIR})
264 install(FILES settings/env.defaults
265 settings/address-levels.json
266 settings/phrase-settings.json
267 settings/import-admin.style
268 settings/import-street.style
269 settings/import-address.style
270 settings/import-full.style
271 settings/import-extratags.style
272 settings/icu_tokenizer.yaml
273 settings/country_settings.yaml
274 DESTINATION ${NOMINATIM_CONFIGDIR})
276 install(DIRECTORY settings/icu-rules
277 DESTINATION ${NOMINATIM_CONFIGDIR})
278 install(DIRECTORY settings/country-names
279 DESTINATION ${NOMINATIM_CONFIGDIR})
281 if (INSTALL_MUNIN_PLUGINS)
282 install(FILES munin/nominatim_importlag
283 munin/nominatim_query_speed
284 munin/nominatim_requests
285 DESTINATION ${NOMINATIM_MUNINDIR})