]> git.openstreetmap.org Git - nominatim.git/blob - CMakeLists.txt
Merge remote-tracking branch 'upstream/master'
[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 # Targets for running a development webserver from the build directory.
98 #-----------------------------------------------------------------------------
99
100 if (BUILD_API)
101    set(WEBSITEFILES
102        403.html
103        509.html
104        crossdomain.xml
105        favicon.ico
106        nominatim.xml
107        robots.txt
108        taginfo.json
109    )
110
111    foreach (webfile ${WEBSITEFILES})
112        configure_file(${PROJECT_SOURCE_DIR}/website/${webfile}
113                       ${PROJECT_BINARY_DIR}/website/${webfile})
114    endforeach()
115 endif()
116
117 #-----------------------------------------------------------------------------
118 # Tests
119 #-----------------------------------------------------------------------------
120
121 if (BUILD_TESTS)
122     include(CTest)
123
124     set(TEST_BDD db osm2pgsql api)
125
126     find_program(PYTHON_BEHAVE behave)
127     find_program(PYLINT NAMES pylint3 pylint)
128     find_program(PYTEST NAMES pytest py.test-3 py.test)
129
130     if (PYTHON_BEHAVE)
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}")
138         endforeach()
139     else()
140         message(WARNING "behave not found. BDD tests disabled." )
141     endif()
142
143     if (PYLINT)
144         message(STATUS "Using pylint binary ${PYLINT}")
145         add_test(NAME pylint
146                  COMMAND ${PYLINT} nominatim
147                  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
148     else()
149         message(WARNING "pylint not found. Python linting tests disabled.")
150     endif()
151
152     if (PYTEST)
153         message(STATUS "Using pytest binary ${PYTEST}")
154         add_test(NAME pytest
155                  COMMAND ${PYTEST} test/python
156                  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
157     else()
158         message(WARNING "pytest not found. Python tests disabled." )
159     endif()
160 endif()
161
162 #-----------------------------------------------------------------------------
163 # Installation
164 #-----------------------------------------------------------------------------
165
166
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)
172
173 if (BUILD_IMPORTER)
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}
177             RENAME nominatim)
178
179     configure_file(${PROJECT_SOURCE_DIR}/cmake/paths-py-no-php.tmpl paths-py.installed)
180
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}
189                 RENAME paths.py)
190     endforeach()
191
192     install(DIRECTORY lib-sql DESTINATION ${NOMINATIM_LIBDIR})
193
194     install(FILES ${COUNTRY_GRID_FILE}
195                   data/words.sql
196             DESTINATION ${NOMINATIM_DATADIR})
197 endif()
198
199 if (BUILD_OSM2PGSQL)
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})
205     else()
206         install(TARGETS osm2pgsql RUNTIME DESTINATION ${NOMINATIM_LIBDIR})
207     endif()
208 endif()
209
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})
222
223 install(DIRECTORY settings/icu-rules
224         DESTINATION ${NOMINATIM_CONFIGDIR})
225 install(DIRECTORY settings/country-names
226         DESTINATION ${NOMINATIM_CONFIGDIR})
227
228 if (INSTALL_MUNIN_PLUGINS)
229     install(FILES munin/nominatim_importlag
230                   munin/nominatim_query_speed
231                   munin/nominatim_requests
232             DESTINATION ${NOMINATIM_MUNINDIR})
233 endif()
234
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")