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 #-----------------------------------------------------------------------------
98 #-----------------------------------------------------------------------------
103 set(TEST_BDD db osm2pgsql api)
105 find_program(PYTHON_BEHAVE behave)
106 find_program(PYLINT NAMES pylint3 pylint)
107 find_program(PYTEST NAMES pytest py.test-3 py.test)
110 message(STATUS "Using Python behave binary ${PYTHON_BEHAVE}")
111 foreach (test ${TEST_BDD})
112 add_test(NAME bdd_${test}
113 COMMAND ${PYTHON_BEHAVE} ${test}
114 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test/bdd)
115 set_tests_properties(bdd_${test}
116 PROPERTIES ENVIRONMENT "NOMINATIM_DIR=${PROJECT_BINARY_DIR}")
119 message(WARNING "behave not found. BDD tests disabled." )
123 message(STATUS "Using pylint binary ${PYLINT}")
125 COMMAND ${PYLINT} nominatim
126 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
128 message(WARNING "pylint not found. Python linting tests disabled.")
132 message(STATUS "Using pytest binary ${PYTEST}")
134 COMMAND ${PYTEST} test/python
135 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
137 message(WARNING "pytest not found. Python tests disabled." )
141 #-----------------------------------------------------------------------------
143 #-----------------------------------------------------------------------------
146 include(GNUInstallDirs)
147 set(NOMINATIM_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME})
148 set(NOMINATIM_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR}/${PROJECT_NAME})
149 set(NOMINATIM_CONFIGDIR ${CMAKE_INSTALL_FULL_SYSCONFDIR}/${PROJECT_NAME})
150 set(NOMINATIM_MUNINDIR ${CMAKE_INSTALL_FULL_DATADIR}/munin/plugins)
153 configure_file(${PROJECT_SOURCE_DIR}/cmake/tool-installed.tmpl installed.bin)
154 install(PROGRAMS ${PROJECT_BINARY_DIR}/installed.bin
155 DESTINATION ${CMAKE_INSTALL_BINDIR}
158 configure_file(${PROJECT_SOURCE_DIR}/cmake/paths-py-no-php.tmpl paths-py.installed)
160 foreach (submodule nominatim_db nominatim_api)
161 install(DIRECTORY src/${submodule}
162 DESTINATION ${NOMINATIM_LIBDIR}/lib-python
163 FILES_MATCHING PATTERN "*.py"
164 PATTERN "paths.py" EXCLUDE
165 PATTERN __pycache__ EXCLUDE)
166 install(FILES ${PROJECT_BINARY_DIR}/paths-py.installed
167 DESTINATION ${NOMINATIM_LIBDIR}/lib-python/${submodule}
171 install(DIRECTORY lib-sql DESTINATION ${NOMINATIM_LIBDIR})
173 install(FILES ${COUNTRY_GRID_FILE}
175 DESTINATION ${NOMINATIM_DATADIR})
179 if (${CMAKE_VERSION} VERSION_LESS 3.13)
180 # Installation of subdirectory targets was only introduced in 3.13.
181 # So just copy the osm2pgsql file for older versions.
182 install(PROGRAMS ${PROJECT_BINARY_DIR}/osm2pgsql/osm2pgsql
183 DESTINATION ${NOMINATIM_LIBDIR})
185 install(TARGETS osm2pgsql RUNTIME DESTINATION ${NOMINATIM_LIBDIR})
189 install(FILES settings/env.defaults
190 settings/address-levels.json
191 settings/phrase-settings.json
192 settings/import-admin.lua
193 settings/import-street.lua
194 settings/import-address.lua
195 settings/import-full.lua
196 settings/import-extratags.lua
197 settings/flex-base.lua
198 settings/icu_tokenizer.yaml
199 settings/country_settings.yaml
200 DESTINATION ${NOMINATIM_CONFIGDIR})
202 install(DIRECTORY settings/icu-rules
203 DESTINATION ${NOMINATIM_CONFIGDIR})
204 install(DIRECTORY settings/country-names
205 DESTINATION ${NOMINATIM_CONFIGDIR})
207 if (INSTALL_MUNIN_PLUGINS)
208 install(FILES munin/nominatim_importlag
209 munin/nominatim_query_speed
210 munin/nominatim_requests
211 DESTINATION ${NOMINATIM_MUNINDIR})
214 message(WARNING "Building with CMake is deprecated and will be removed in Nominatim 5.0."
215 "Use Nominatim pip packages instead.\n"
216 "See https://nominatim.org/release-docs/develop/admin/Installation/#downloading-and-building-nominatim")