From e464c06294a3f1f27374bb04d68d588cde68f229 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Sat, 2 Jan 2021 20:27:50 +0100 Subject: [PATCH] Modernize and clean up CMake configuration --- .gitignore | 4 +--- CMakeLists.txt | 17 ++++++++--------- README.md | 12 +++++++----- osmpbf | 1 + src/CMakeLists.txt | 21 +++++++-------------- tools/CMakeLists.txt | 39 ++++++++++----------------------------- 6 files changed, 34 insertions(+), 60 deletions(-) create mode 120000 osmpbf diff --git a/.gitignore b/.gitignore index 0a56cd0..4c97329 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ -build-stamp -build -configure-stamp +/build osmpbf.jar generated.java include/osmpbf/*.pb.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0263928..e558d6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,14 @@ -PROJECT(OSMBinary) -cmake_minimum_required(VERSION 2.8.5) +cmake_minimum_required(VERSION 3.7) -SET(SEARCH_PREFIX CACHE PATH "Additional prefix to search libraries (Protobuf etc.)" ) +project(OSMBinary) -SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${SEARCH_PREFIX}) +set(CMAKE_CXX_STANDARD 11) -include(FindProtobuf) find_package(Protobuf REQUIRED) -include_directories(${PROTOBUF_INCLUDE_DIR}) -add_subdirectory(src) +add_subdirectory(osmpbf) + +# The osmpbf-outline tool does not compile on Windows because getopt.h is missing if(NOT MSVC) -add_subdirectory(tools) -endif() \ No newline at end of file + add_subdirectory(tools) +endif() diff --git a/README.md b/README.md index 4fa5587..9a2bd74 100644 --- a/README.md +++ b/README.md @@ -34,20 +34,22 @@ For a Java usage example, see src.java/crosby/binary/test/ReadFileExample.java To compile: ```sh -make -C src +mkdir build && cd build +cmake .. +make ``` To install: ```sh -make -C src install +make install ``` There is a tool named osmpbf-outline that shows a debug output of the contents -of a PBF file. To compile it: +of a PBF file. To run it: ```sh -make -C tools +tools/osmpbf-outline osm-file.osm.pbf ``` @@ -62,7 +64,7 @@ To include in your program use: and link with: ``` --pthread -lz -lprotobuf-lite -losmpbf +-pthread -lz -lprotobuf -losmpbf ``` diff --git a/osmpbf b/osmpbf new file mode 120000 index 0000000..e831038 --- /dev/null +++ b/osmpbf @@ -0,0 +1 @@ +src \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4a2b9ac..a28410f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,19 +1,12 @@ -PROTOBUF_GENERATE_CPP(CPPS HS fileformat.proto osmformat.proto) - -if(MSVC) - set(CMAKE_CXX_FLAGS "/O3") -else() - set(CMAKE_CXX_FLAGS "-O3") -endif() +protobuf_generate_cpp(CPPS HS fileformat.proto osmformat.proto) add_library(osmpbf STATIC ${CPPS}) +target_include_directories(osmpbf SYSTEM PUBLIC ${Protobuf_INCLUDE_DIRS}) -set_target_properties(osmpbf PROPERTIES LINKER_LANGUAGE CXX LANGUAGE CXX) +install(FILES ${CMAKE_SOURCE_DIR}/include/osmpbf/osmpbf.h + ${CMAKE_BINARY_DIR}/osmpbf/osmformat.pb.h + ${CMAKE_BINARY_DIR}/osmpbf/fileformat.pb.h + DESTINATION "include/osmpbf") -ADD_CUSTOM_COMMAND(TARGET osmpbf POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/src/fileformat.pb.h ${CMAKE_SOURCE_DIR}/include/osmpbf) -ADD_CUSTOM_COMMAND(TARGET osmpbf POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/src/osmformat.pb.h ${CMAKE_SOURCE_DIR}/include/osmpbf) +install(TARGETS osmpbf ARCHIVE DESTINATION lib) -SET(INCLUDE_INSTALL "include/osmpbf") -SET(files ${CMAKE_SOURCE_DIR}/include/osmpbf/osmpbf.h ${CMAKE_BINARY_DIR}/src/osmformat.pb.h ${CMAKE_BINARY_DIR}/src/fileformat.pb.h) -INSTALL(FILES ${files} DESTINATION ${INCLUDE_INSTALL}) -install(TARGETS osmpbf LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 91f01eb..dd705a2 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,32 +1,13 @@ -SET(PROJECT osmpbf-outline) -PROJECT(${PROJECT}) - -if(MSVC) - set(CMAKE_CXX_FLAGS "/O3") -else() - set(CMAKE_CXX_FLAGS "-O3 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64") -endif() - -SET(CPP_SRC osmpbf-outline.cpp) -SET(HPP_SRC "") -SET(C_SRC "") -include_directories("${CMAKE_SOURCE_DIR}/include") - -add_executable(${PROJECT} ${HPP_SRC} ${CPP_SRC} ${C_SRC}) -set_target_properties(${PROJECT} PROPERTIES LINKER_LANGUAGE CXX LANGUAGE CXX) - find_package(ZLIB REQUIRED) -include_directories(${ZLIB_INCLUDE_DIR}) - -INCLUDE (CheckIncludeFiles) -CHECK_INCLUDE_FILES(winsock2.h HAVE_WINSOCK) -if(HAVE_WINSOCK) - add_definitions( -DD_HAVE_WINSOCK ) - SET(WINSOCK_LIB ws2_32) -endif() - - find_package(Threads) -target_link_libraries(${PROJECT} ${WINSOCK_LIB} ${ZLIB_LIBRARY} osmpbf ${PROTOBUF_LITE_LIBRARIES}) -INSTALL(TARGETS ${PROJECT} RUNTIME DESTINATION bin) +include_directories("${CMAKE_SOURCE_DIR}/include") +include_directories(${CMAKE_BINARY_DIR}) + +add_executable(osmpbf-outline osmpbf-outline.cpp) + +target_include_directories(osmpbf-outline SYSTEM PRIVATE ${ZLIB_INCLUDE_DIR}) +target_link_libraries(osmpbf-outline PRIVATE osmpbf ZLIB::ZLIB protobuf::libprotobuf) + +install(TARGETS osmpbf-outline RUNTIME DESTINATION bin) +install(FILES osmpbf-outline.1 DESTINATION share/man/man1)