]> git.openstreetmap.org Git - nominatim.git/blob - CMakeLists.txt
Merge pull request #3588 from lonvia/optional-reverse-api
[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 5)
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_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")
50
51 #-----------------------------------------------------------------------------
52 #  osm2pgsql (imports/updates only)
53 #-----------------------------------------------------------------------------
54
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")
60     endif()
61     set(BUILD_TESTS_SAVED "${BUILD_TESTS}")
62     set(BUILD_TESTS off)
63     add_subdirectory(osm2pgsql)
64     set(BUILD_TESTS ${BUILD_TESTS_SAVED})
65 endif()
66
67
68 #-----------------------------------------------------------------------------
69 #  python (imports/updates only)
70 #-----------------------------------------------------------------------------
71
72 if (BUILD_IMPORTER OR BUILD_API)
73     find_package(PythonInterp 3.7 REQUIRED)
74 endif()
75
76 #-----------------------------------------------------------------------------
77 # import scripts and utilities (importer only)
78 #-----------------------------------------------------------------------------
79
80 if (BUILD_IMPORTER)
81    find_file(COUNTRY_GRID_FILE country_osm_grid.sql.gz
82              PATHS ${PROJECT_SOURCE_DIR}/data
83              NO_DEFAULT_PATH
84              DOC "Location of the country grid file."
85             )
86
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")
90    endif()
91
92    configure_file(${PROJECT_SOURCE_DIR}/cmake/tool.tmpl
93                   ${PROJECT_BINARY_DIR}/nominatim)
94 endif()
95
96 #-----------------------------------------------------------------------------
97 # Tests
98 #-----------------------------------------------------------------------------
99
100 if (BUILD_TESTS)
101     include(CTest)
102
103     set(TEST_BDD db osm2pgsql api)
104
105     find_program(PYTHON_BEHAVE behave)
106     find_program(PYLINT NAMES pylint3 pylint)
107     find_program(PYTEST NAMES pytest py.test-3 py.test)
108
109     if (PYTHON_BEHAVE)
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}")
117         endforeach()
118     else()
119         message(WARNING "behave not found. BDD tests disabled." )
120     endif()
121
122     if (PYLINT)
123         message(STATUS "Using pylint binary ${PYLINT}")
124         add_test(NAME pylint
125                  COMMAND ${PYLINT} nominatim
126                  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
127     else()
128         message(WARNING "pylint not found. Python linting tests disabled.")
129     endif()
130
131     if (PYTEST)
132         message(STATUS "Using pytest binary ${PYTEST}")
133         add_test(NAME pytest
134                  COMMAND ${PYTEST} test/python
135                  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
136     else()
137         message(WARNING "pytest not found. Python tests disabled." )
138     endif()
139 endif()
140
141 #-----------------------------------------------------------------------------
142 # Installation
143 #-----------------------------------------------------------------------------
144
145
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)
151
152 if (BUILD_IMPORTER)
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}
156             RENAME nominatim)
157
158     configure_file(${PROJECT_SOURCE_DIR}/cmake/paths-py-no-php.tmpl paths-py.installed)
159
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}
168                 RENAME paths.py)
169     endforeach()
170
171     install(DIRECTORY lib-sql DESTINATION ${NOMINATIM_LIBDIR})
172
173     install(FILES ${COUNTRY_GRID_FILE}
174                   data/words.sql
175             DESTINATION ${NOMINATIM_DATADIR})
176 endif()
177
178 if (BUILD_OSM2PGSQL)
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})
184     else()
185         install(TARGETS osm2pgsql RUNTIME DESTINATION ${NOMINATIM_LIBDIR})
186     endif()
187 endif()
188
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})
201
202 install(DIRECTORY settings/icu-rules
203         DESTINATION ${NOMINATIM_CONFIGDIR})
204 install(DIRECTORY settings/country-names
205         DESTINATION ${NOMINATIM_CONFIGDIR})
206
207 if (INSTALL_MUNIN_PLUGINS)
208     install(FILES munin/nominatim_importlag
209                   munin/nominatim_query_speed
210                   munin/nominatim_requests
211             DESTINATION ${NOMINATIM_MUNINDIR})
212 endif()
213
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")