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 5)
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_TESTS on CACHE BOOL "Build test suite")
48 set(BUILD_OSM2PGSQL on CACHE BOOL "Build osm2pgsql (expert only)")
49 set(INSTALL_MUNIN_PLUGINS on CACHE BOOL "Install Munin plugins for supervising Nominatim")
51 #-----------------------------------------------------------------------------
52 # osm2pgsql (imports/updates only)
53 #-----------------------------------------------------------------------------
55 if (BUILD_IMPORTER AND BUILD_OSM2PGSQL)
56 if (NOT EXISTS "${CMAKE_SOURCE_DIR}/osm2pgsql/CMakeLists.txt")
57 message(FATAL_ERROR "The osm2pgsql directory is empty.\
58 Did you forget to check out Nominatim recursively?\
59 \nTry updating submodules with: git submodule update --init")
61 set(BUILD_TESTS_SAVED "${BUILD_TESTS}")
63 add_subdirectory(osm2pgsql)
64 set(BUILD_TESTS ${BUILD_TESTS_SAVED})
68 #-----------------------------------------------------------------------------
69 # python (imports/updates only)
70 #-----------------------------------------------------------------------------
72 if (BUILD_IMPORTER OR BUILD_API)
73 find_package(PythonInterp 3.7 REQUIRED)
76 #-----------------------------------------------------------------------------
77 # import scripts and utilities (importer only)
78 #-----------------------------------------------------------------------------
81 find_file(COUNTRY_GRID_FILE country_osm_grid.sql.gz
82 PATHS ${PROJECT_SOURCE_DIR}/data
84 DOC "Location of the country grid file."
87 if (NOT COUNTRY_GRID_FILE)
88 message(FATAL_ERROR "\nYou need to download the country_osm_grid first:\n"
89 " wget -O ${PROJECT_SOURCE_DIR}/data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz")
92 configure_file(${PROJECT_SOURCE_DIR}/cmake/tool.tmpl
93 ${PROJECT_BINARY_DIR}/nominatim)
96 #-----------------------------------------------------------------------------
97 # Targets for running a development webserver from the build directory.
98 #-----------------------------------------------------------------------------
111 foreach (webfile ${WEBSITEFILES})
112 configure_file(${PROJECT_SOURCE_DIR}/website/${webfile}
113 ${PROJECT_BINARY_DIR}/website/${webfile})
117 #-----------------------------------------------------------------------------
119 #-----------------------------------------------------------------------------
124 set(TEST_BDD db osm2pgsql api)
126 find_program(PYTHON_BEHAVE behave)
127 find_program(PYLINT NAMES pylint3 pylint)
128 find_program(PYTEST NAMES pytest py.test-3 py.test)
131 message(STATUS "Using Python behave binary ${PYTHON_BEHAVE}")
132 foreach (test ${TEST_BDD})
133 add_test(NAME bdd_${test}
134 COMMAND ${PYTHON_BEHAVE} ${test}
135 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test/bdd)
136 set_tests_properties(bdd_${test}
137 PROPERTIES ENVIRONMENT "NOMINATIM_DIR=${PROJECT_BINARY_DIR}")
140 message(WARNING "behave not found. BDD tests disabled." )
144 message(STATUS "Using pylint binary ${PYLINT}")
146 COMMAND ${PYLINT} nominatim
147 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
149 message(WARNING "pylint not found. Python linting tests disabled.")
153 message(STATUS "Using pytest binary ${PYTEST}")
155 COMMAND ${PYTEST} test/python
156 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
158 message(WARNING "pytest not found. Python tests disabled." )
162 #-----------------------------------------------------------------------------
164 #-----------------------------------------------------------------------------
167 include(GNUInstallDirs)
168 set(NOMINATIM_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME})
169 set(NOMINATIM_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR}/${PROJECT_NAME})
170 set(NOMINATIM_CONFIGDIR ${CMAKE_INSTALL_FULL_SYSCONFDIR}/${PROJECT_NAME})
171 set(NOMINATIM_MUNINDIR ${CMAKE_INSTALL_FULL_DATADIR}/munin/plugins)
174 configure_file(${PROJECT_SOURCE_DIR}/cmake/tool-installed.tmpl installed.bin)
175 install(PROGRAMS ${PROJECT_BINARY_DIR}/installed.bin
176 DESTINATION ${CMAKE_INSTALL_BINDIR}
179 configure_file(${PROJECT_SOURCE_DIR}/cmake/paths-py-no-php.tmpl paths-py.installed)
181 foreach (submodule nominatim_db nominatim_api)
182 install(DIRECTORY src/${submodule}
183 DESTINATION ${NOMINATIM_LIBDIR}/lib-python
184 FILES_MATCHING PATTERN "*.py"
185 PATTERN "paths.py" EXCLUDE
186 PATTERN __pycache__ EXCLUDE)
187 install(FILES ${PROJECT_BINARY_DIR}/paths-py.installed
188 DESTINATION ${NOMINATIM_LIBDIR}/lib-python/${submodule}
192 install(DIRECTORY lib-sql DESTINATION ${NOMINATIM_LIBDIR})
194 install(FILES ${COUNTRY_GRID_FILE}
196 DESTINATION ${NOMINATIM_DATADIR})
200 if (${CMAKE_VERSION} VERSION_LESS 3.13)
201 # Installation of subdirectory targets was only introduced in 3.13.
202 # So just copy the osm2pgsql file for older versions.
203 install(PROGRAMS ${PROJECT_BINARY_DIR}/osm2pgsql/osm2pgsql
204 DESTINATION ${NOMINATIM_LIBDIR})
206 install(TARGETS osm2pgsql RUNTIME DESTINATION ${NOMINATIM_LIBDIR})
210 install(FILES settings/env.defaults
211 settings/address-levels.json
212 settings/phrase-settings.json
213 settings/import-admin.lua
214 settings/import-street.lua
215 settings/import-address.lua
216 settings/import-full.lua
217 settings/import-extratags.lua
218 settings/flex-base.lua
219 settings/icu_tokenizer.yaml
220 settings/country_settings.yaml
221 DESTINATION ${NOMINATIM_CONFIGDIR})
223 install(DIRECTORY settings/icu-rules
224 DESTINATION ${NOMINATIM_CONFIGDIR})
225 install(DIRECTORY settings/country-names
226 DESTINATION ${NOMINATIM_CONFIGDIR})
228 if (INSTALL_MUNIN_PLUGINS)
229 install(FILES munin/nominatim_importlag
230 munin/nominatim_query_speed
231 munin/nominatim_requests
232 DESTINATION ${NOMINATIM_MUNINDIR})
235 message(WARNING "Building with CMake is deprecated and will be removed in Nominatim 5.0."
236 "Use Nominatim pip packages instead.\n"
237 "See https://nominatim.org/release-docs/develop/admin/Installation/#downloading-and-building-nominatim")