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_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")
52 #-----------------------------------------------------------------------------
53 # osm2pgsql (imports/updates only)
54 #-----------------------------------------------------------------------------
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")
62 set(BUILD_TESTS_SAVED "${BUILD_TESTS}")
64 add_subdirectory(osm2pgsql)
65 set(BUILD_TESTS ${BUILD_TESTS_SAVED})
69 #-----------------------------------------------------------------------------
70 # python (imports/updates only)
71 #-----------------------------------------------------------------------------
73 if (BUILD_IMPORTER OR BUILD_API)
74 find_package(PythonInterp 3.7 REQUIRED)
77 #-----------------------------------------------------------------------------
78 # import scripts and utilities (importer only)
79 #-----------------------------------------------------------------------------
82 find_file(COUNTRY_GRID_FILE country_osm_grid.sql.gz
83 PATHS ${PROJECT_SOURCE_DIR}/data
85 DOC "Location of the country grid file."
88 if (NOT COUNTRY_GRID_FILE)
89 message(FATAL_ERROR "\nYou need to download the country_osm_grid first:\n"
90 " wget -O ${PROJECT_SOURCE_DIR}/data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz")
93 configure_file(${PROJECT_SOURCE_DIR}/cmake/tool.tmpl
94 ${PROJECT_BINARY_DIR}/nominatim)
97 #-----------------------------------------------------------------------------
99 #-----------------------------------------------------------------------------
104 set(TEST_BDD db osm2pgsql api)
106 find_program(PYTHON_BEHAVE behave)
107 find_program(PYLINT NAMES pylint3 pylint)
108 find_program(PYTEST NAMES pytest py.test-3 py.test)
111 message(STATUS "Using Python behave binary ${PYTHON_BEHAVE}")
112 foreach (test ${TEST_BDD})
113 add_test(NAME bdd_${test}
114 COMMAND ${PYTHON_BEHAVE} ${test}
115 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test/bdd)
116 set_tests_properties(bdd_${test}
117 PROPERTIES ENVIRONMENT "NOMINATIM_DIR=${PROJECT_BINARY_DIR}")
120 message(WARNING "behave not found. BDD tests disabled." )
124 message(STATUS "Using pylint binary ${PYLINT}")
126 COMMAND ${PYLINT} nominatim
127 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
129 message(WARNING "pylint not found. Python linting tests disabled.")
133 message(STATUS "Using pytest binary ${PYTEST}")
135 COMMAND ${PYTEST} test/python
136 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
138 message(WARNING "pytest not found. Python tests disabled." )
142 #-----------------------------------------------------------------------------
144 #-----------------------------------------------------------------------------
147 add_subdirectory(module)
150 #-----------------------------------------------------------------------------
152 #-----------------------------------------------------------------------------
155 include(GNUInstallDirs)
156 set(NOMINATIM_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME})
157 set(NOMINATIM_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR}/${PROJECT_NAME})
158 set(NOMINATIM_CONFIGDIR ${CMAKE_INSTALL_FULL_SYSCONFDIR}/${PROJECT_NAME})
159 set(NOMINATIM_MUNINDIR ${CMAKE_INSTALL_FULL_DATADIR}/munin/plugins)
162 configure_file(${PROJECT_SOURCE_DIR}/cmake/tool-installed.tmpl installed.bin)
163 install(PROGRAMS ${PROJECT_BINARY_DIR}/installed.bin
164 DESTINATION ${CMAKE_INSTALL_BINDIR}
167 configure_file(${PROJECT_SOURCE_DIR}/cmake/paths-py-no-php.tmpl paths-py.installed)
169 foreach (submodule nominatim_db nominatim_api)
170 install(DIRECTORY src/${submodule}
171 DESTINATION ${NOMINATIM_LIBDIR}/lib-python
172 FILES_MATCHING PATTERN "*.py"
173 PATTERN "paths.py" EXCLUDE
174 PATTERN __pycache__ EXCLUDE)
175 install(FILES ${PROJECT_BINARY_DIR}/paths-py.installed
176 DESTINATION ${NOMINATIM_LIBDIR}/lib-python/${submodule}
180 install(DIRECTORY lib-sql DESTINATION ${NOMINATIM_LIBDIR})
182 install(FILES ${COUNTRY_GRID_FILE}
184 DESTINATION ${NOMINATIM_DATADIR})
188 if (${CMAKE_VERSION} VERSION_LESS 3.13)
189 # Installation of subdirectory targets was only introduced in 3.13.
190 # So just copy the osm2pgsql file for older versions.
191 install(PROGRAMS ${PROJECT_BINARY_DIR}/osm2pgsql/osm2pgsql
192 DESTINATION ${NOMINATIM_LIBDIR})
194 install(TARGETS osm2pgsql RUNTIME DESTINATION ${NOMINATIM_LIBDIR})
199 install(PROGRAMS ${PROJECT_BINARY_DIR}/module/nominatim.so
200 DESTINATION ${NOMINATIM_LIBDIR}/module)
203 install(FILES settings/env.defaults
204 settings/address-levels.json
205 settings/phrase-settings.json
206 settings/import-admin.lua
207 settings/import-street.lua
208 settings/import-address.lua
209 settings/import-full.lua
210 settings/import-extratags.lua
211 settings/flex-base.lua
212 settings/icu_tokenizer.yaml
213 settings/country_settings.yaml
214 DESTINATION ${NOMINATIM_CONFIGDIR})
216 install(DIRECTORY settings/icu-rules
217 DESTINATION ${NOMINATIM_CONFIGDIR})
218 install(DIRECTORY settings/country-names
219 DESTINATION ${NOMINATIM_CONFIGDIR})
221 if (INSTALL_MUNIN_PLUGINS)
222 install(FILES munin/nominatim_importlag
223 munin/nominatim_query_speed
224 munin/nominatim_requests
225 DESTINATION ${NOMINATIM_MUNINDIR})
228 message(WARNING "Building with CMake is deprecated and will be removed in Nominatim 5.0."
229 "Use Nominatim pip packages instead.\n"
230 "See https://nominatim.org/release-docs/develop/admin/Installation/#downloading-and-building-nominatim")