Warning, /libraries/kpublictransport/cmake/FindOsmTools.cmake is written in an unsupported language. File is not indexed.
0001 # SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0002 # 0003 # SPDX-License-Identifier: BSD-3-Clause 0004 0005 0006 find_program(OSMCONVERT_EXECUTABLE osmconvert) 0007 find_program(OSMFILTER_EXECUTABLE osmfilter) 0008 find_program(OSMUPDATE_EXECUTABLE osmupdate) 0009 0010 find_program(WGET_EXECUTABLE wget) # needed by osmupdate 0011 find_program(RSYNC_EXECUTABLE rsync) # needed for the initial download 0012 0013 0014 include(FindPackageHandleStandardArgs) 0015 find_package_handle_standard_args(OsmTools 0016 FOUND_VAR OsmTools_FOUND 0017 REQUIRED_VARS OSMCONVERT_EXECUTABLE OSMFILTER_EXECUTABLE OSMUPDATE_EXECUTABLE WGET_EXECUTABLE RSYNC_EXECUTABLE 0018 ) 0019 0020 if (OSMCONVERT_EXECUTABLE AND NOT TARGET OSM::convert) 0021 add_executable(OSM::convert IMPORTED) 0022 set_target_properties(OSM::convert PROPERTIES IMPORTED_LOCATION ${OSMCONVERT_EXECUTABLE}) 0023 endif() 0024 if (OSMFILTER_EXECUTABLE AND NOT TARGET OSM::filter) 0025 add_executable(OSM::filter IMPORTED) 0026 set_target_properties(OSM::filter PROPERTIES IMPORTED_LOCATION ${OSMFILTER_EXECUTABLE}) 0027 endif() 0028 if (OSMUPDATE_EXECUTABLE AND NOT TARGET OSM::update) 0029 add_executable(OSM::update IMPORTED) 0030 set_target_properties(OSM::update PROPERTIES IMPORTED_LOCATION ${OSMUPDATE_EXECUTABLE}) 0031 endif() 0032 0033 set_package_properties(OsmTools PROPERTIES 0034 URL "https://gitlab.com/osm-c-tools/osmctools" 0035 DESCRIPTION "Tols to convert, filter and update OpenStreetMap data files" 0036 ) 0037 0038 mark_as_advanced(OSMCONVERT_EXECUTABLE OSMFILTER_EXECUTABLE OSMCONVERT_EXECUTABLE WGET_EXECUTABLE) 0039 0040 set(OSM_PLANET_DIR "" CACHE PATH "Directory containing the planet-latest.o5m file, and enough space to store processing results in.") 0041 set(OSM_MIRROR "ftp5.gwdg.de/pub/misc/openstreetmap/planet.openstreetmap.org" CACHE STRING "Base URL of the preferred OSM download mirror.") 0042 0043 # create initial download and incremental update targets for the OSM planet file 0044 if (OSM_PLANET_DIR) 0045 set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM ON) # avoid cleaning the expensive full planet files 0046 add_custom_command( 0047 OUTPUT ${OSM_PLANET_DIR}/planet-latest.osm.pbf 0048 COMMAND ${RSYNC_EXECUTABLE} -Lvz --partial --progress rsync://${OSM_MIRROR}/pbf/planet-latest.osm.pbf ${OSM_PLANET_DIR}/planet-latest.osm.pbf 0049 WORKING_DIRECTORY ${OSM_PLANET_DIR} 0050 COMMENT "Downloading full OSM plant file (~60GB)" 0051 ) 0052 add_custom_command( 0053 OUTPUT ${OSM_PLANET_DIR}/planet-latest.o5m 0054 COMMAND OSM::convert ${OSM_PLANET_DIR}/planet-latest.osm.pbf --drop-author --drop-version --out-o5m -o=${OSM_PLANET_DIR}/planet-latest.o5m 0055 WORKING_DIRECTORY ${OSM_PLANET_DIR} 0056 COMMENT "Converting full OSM planet file to o5m format (takes ~30min and needs ~80GB of extra disk space)" 0057 ) 0058 0059 add_custom_target(osm-update-planet 0060 COMMAND OSM::update --base-url=https://${OSM_MIRROR}/replication --day --verbose ${OSM_PLANET_DIR}/planet-latest.o5m ${OSM_PLANET_DIR}/new-planet-latest.o5m 0061 COMMAND ${CMAKE_COMMAND} -E rename ${OSM_PLANET_DIR}/new-planet-latest.o5m ${OSM_PLANET_DIR}/planet-latest.o5m 0062 WORKING_DIRECTORY ${OSM_PLANET_DIR} 0063 DEPENDS ${OSM_PLANET_DIR}/planet-latest.o5m 0064 COMMENT "Updating OSM planet file" 0065 ) 0066 endif() 0067 0068 if (TARGET OSM::convert) 0069 0070 # Convert the given input file to the output file with determining the output format 0071 # from the file extension 0072 # Arguments: 0073 # INPUT input file, assumed to be in OSM_PLANET_DIR 0074 # OUTPUT output file, assumed to be in OSM_PLANET_DIR 0075 # ADD_BBOX bool, enable injection of bounding box tags 0076 function(osm_convert) 0077 set(optionArgs ADD_BBOX) 0078 set(oneValueArgs INPUT OUTPUT) 0079 cmake_parse_arguments(osm_convert "${optionArgs}" "${oneValueArgs}" "" ${ARGN}) 0080 get_filename_component(format ${osm_convert_OUTPUT} LAST_EXT) 0081 string(SUBSTRING ${format} 1 -1 format) 0082 0083 set(extra_args "") 0084 if (osm_convert_ADD_BBOX) 0085 set(extra_args "--add-bbox-tags") 0086 endif() 0087 0088 add_custom_command( 0089 OUTPUT ${OSM_PLANET_DIR}/${osm_convert_OUTPUT} 0090 COMMAND OSM::convert ${OSM_PLANET_DIR}/${osm_convert_INPUT} --drop-author --drop-version ${extra_args} --out-${format} -o=${OSM_PLANET_DIR}/${osm_convert_OUTPUT} 0091 WORKING_DIRECTORY ${OSM_PLANET_DIR} 0092 COMMENT "Converting ${osm_convert_INPUT} to ${format} format" 0093 DEPENDS ${OSM_PLANET_DIR}/${osm_convert_INPUT} 0094 ) 0095 endfunction() 0096 0097 endif() 0098 0099 0100 if (TARGET OSM::filter) 0101 0102 # Filter the given input file by the given filter arguments 0103 # Arguments: 0104 # INPUT input file, assumed to be in OSM_PLANET_DIR (default is planet-latest.o5m) 0105 # OUTPUT output file, assumed to be in OSM_PLANET_DIR 0106 # FILTER filter arguments for osmfilter 0107 function(osm_filter) 0108 set(oneValueArgs INPUT OUTPUT) 0109 set(multiValueArgs FILTER) 0110 cmake_parse_arguments(osm_filter "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 0111 get_filename_component(format ${osm_filter_OUTPUT} LAST_EXT) 0112 string(SUBSTRING ${format} 1 -1 format) 0113 0114 if (NOT osm_filter_INPUT) 0115 set(osm_filter_INPUT planet-latest.o5m) 0116 endif() 0117 0118 add_custom_command( 0119 OUTPUT ${OSM_PLANET_DIR}/${osm_filter_OUTPUT} 0120 COMMAND OSM::filter ${OSM_PLANET_DIR}/${osm_filter_INPUT} --drop-author --drop-version ${osm_filter_FILTER} --out-${format} -o=${OSM_PLANET_DIR}/${osm_filter_OUTPUT} 0121 WORKING_DIRECTORY ${OSM_PLANET_DIR} 0122 COMMENT "Filtering ${osm_filter_INPUT}" 0123 DEPENDS ${OSM_PLANET_DIR}/${osm_filter_INPUT} 0124 ) 0125 endfunction() 0126 0127 endif()