Modernize and clean up CMake configuration

This commit is contained in:
Jochen Topf 2021-01-02 20:27:50 +01:00
parent a627e4b9dd
commit e464c06294
6 changed files with 34 additions and 60 deletions

4
.gitignore vendored
View File

@ -1,6 +1,4 @@
build-stamp
build
configure-stamp
/build
osmpbf.jar
generated.java
include/osmpbf/*.pb.h

View File

@ -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()

View File

@ -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
```

1
osmpbf Symbolic link
View File

@ -0,0 +1 @@
src

View File

@ -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)

View File

@ -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)