Skip to content

Commit

Permalink
CMake config: Set minimum C++ version needed in a different way
Browse files Browse the repository at this point in the history
This setting should be overwritten if CMake find that some library needs
an even more modern version.
  • Loading branch information
joto committed Jan 7, 2024
1 parent 4e009b0 commit 30097cd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/c.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
env:
CC: clang
CXX: clang++
CXXFLAGS: -Werror -Wall -pedantic -std=c++17
CXXFLAGS: -Werror -Wall -pedantic
BUILD_TYPE: Debug
steps:
- uses: actions/checkout@v4
Expand Down
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ project(osmpbf VERSION 1.5.0)

include(GNUInstallDirs)

# This is needed for the protobuf_generate_cpp() function to work on newer
# versions of the Protobuf CMake config.
set(protobuf_MODULE_COMPATIBLE ON CACHE BOOL "")

# This is needed so that we pick up the (more modern) CONFIG mode cmake file
# before the (older) MODULE mode cmake config file. Seems to be needed on macOS.
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)

find_package(Protobuf REQUIRED)

add_subdirectory(osmpbf)
Expand Down
5 changes: 3 additions & 2 deletions osmpbf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
protobuf_generate_cpp(CPPS HS fileformat.proto osmformat.proto)

add_library(osmpbf STATIC ${CPPS})
target_compile_features(osmpbf PUBLIC cxx_std_11)
target_link_libraries(osmpbf PRIVATE protobuf::libprotobuf)
target_include_directories(osmpbf SYSTEM PUBLIC ${Protobuf_INCLUDE_DIRS})
set_property(TARGET osmpbf PROPERTY CXX_STANDARD 11)
install(TARGETS osmpbf ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

add_library(osmpbf_shared SHARED ${CPPS})
set_property(TARGET osmpbf_shared PROPERTY CXX_STANDARD 11)
target_compile_features(osmpbf_shared PUBLIC cxx_std_11)
target_link_libraries(osmpbf_shared PRIVATE protobuf::libprotobuf)
target_include_directories(osmpbf_shared SYSTEM PUBLIC ${Protobuf_INCLUDE_DIRS})
set_target_properties(osmpbf_shared PROPERTIES OUTPUT_NAME osmpbf
Expand Down

0 comments on commit 30097cd

Please sign in to comment.