]> git.openstreetmap.org Git - nominatim.git/blob - CMakeLists.txt
remove remaining references to php code
[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_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")
51
52 #-----------------------------------------------------------------------------
53 #  osm2pgsql (imports/updates only)
54 #-----------------------------------------------------------------------------
55
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")
61     endif()
62     set(BUILD_TESTS_SAVED "${BUILD_TESTS}")
63     set(BUILD_TESTS off)
64     add_subdirectory(osm2pgsql)
65     set(BUILD_TESTS ${BUILD_TESTS_SAVED})
66 endif()
67
68
69 #-----------------------------------------------------------------------------
70 #  python (imports/updates only)
71 #-----------------------------------------------------------------------------
72
73 if (BUILD_IMPORTER OR BUILD_API)
74     find_package(PythonInterp 3.7 REQUIRED)
75 endif()
76
77 #-----------------------------------------------------------------------------
78 # import scripts and utilities (importer only)
79 #-----------------------------------------------------------------------------
80
81 if (BUILD_IMPORTER)
82    find_file(COUNTRY_GRID_FILE country_osm_grid.sql.gz
83              PATHS ${PROJECT_SOURCE_DIR}/data
84              NO_DEFAULT_PATH
85              DOC "Location of the country grid file."
86             )
87
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")
91    endif()
92
93    configure_file(${PROJECT_SOURCE_DIR}/cmake/tool.tmpl
94                   ${PROJECT_BINARY_DIR}/nominatim)
95 endif()
96
97 #-----------------------------------------------------------------------------
98 # Tests
99 #-----------------------------------------------------------------------------
100
101 if (BUILD_TESTS)
102     include(CTest)
103
104     set(TEST_BDD db osm2pgsql api)
105
106     find_program(PYTHON_BEHAVE behave)
107     find_program(PYLINT NAMES pylint3 pylint)
108     find_program(PYTEST NAMES pytest py.test-3 py.test)
109
110     if (PYTHON_BEHAVE)
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}")
118         endforeach()
119     else()
120         message(WARNING "behave not found. BDD tests disabled." )
121     endif()
122
123     if (PYLINT)
124         message(STATUS "Using pylint binary ${PYLINT}")
125         add_test(NAME pylint
126                  COMMAND ${PYLINT} nominatim
127                  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
128     else()
129         message(WARNING "pylint not found. Python linting tests disabled.")
130     endif()
131
132     if (PYTEST)
133         message(STATUS "Using pytest binary ${PYTEST}")
134         add_test(NAME pytest
135                  COMMAND ${PYTEST} test/python
136                  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
137     else()
138         message(WARNING "pytest not found. Python tests disabled." )
139     endif()
140 endif()
141
142 #-----------------------------------------------------------------------------
143 # Postgres module
144 #-----------------------------------------------------------------------------
145
146 if (BUILD_MODULE)
147     add_subdirectory(module)
148 endif()
149
150 #-----------------------------------------------------------------------------
151 # Installation
152 #-----------------------------------------------------------------------------
153
154
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)
160
161 if (BUILD_IMPORTER)
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}
165             RENAME nominatim)
166
167     configure_file(${PROJECT_SOURCE_DIR}/cmake/paths-py-no-php.tmpl paths-py.installed)
168
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}
177                 RENAME paths.py)
178     endforeach()
179
180     install(DIRECTORY lib-sql DESTINATION ${NOMINATIM_LIBDIR})
181
182     install(FILES ${COUNTRY_GRID_FILE}
183                   data/words.sql
184             DESTINATION ${NOMINATIM_DATADIR})
185 endif()
186
187 if (BUILD_OSM2PGSQL)
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})
193     else()
194         install(TARGETS osm2pgsql RUNTIME DESTINATION ${NOMINATIM_LIBDIR})
195     endif()
196 endif()
197
198 if (BUILD_MODULE)
199     install(PROGRAMS ${PROJECT_BINARY_DIR}/module/nominatim.so
200             DESTINATION ${NOMINATIM_LIBDIR}/module)
201 endif()
202
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})
215
216 install(DIRECTORY settings/icu-rules
217         DESTINATION ${NOMINATIM_CONFIGDIR})
218 install(DIRECTORY settings/country-names
219         DESTINATION ${NOMINATIM_CONFIGDIR})
220
221 if (INSTALL_MUNIN_PLUGINS)
222     install(FILES munin/nominatim_importlag
223                   munin/nominatim_query_speed
224                   munin/nominatim_requests
225             DESTINATION ${NOMINATIM_MUNINDIR})
226 endif()
227
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")