diff options
author | Petteri Aimonen <jpa@github.mail.kapsi.fi> | 2016-10-10 07:25:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-10 07:25:35 +0300 |
commit | fe0aca04cbc41327144813ca54ea37aafb866d25 (patch) | |
tree | 1eba7ff46e34f155f8491514beeb99e2709d7aa6 /CMakeLists.txt | |
parent | 060e6a6cc21eaf555cba6d3ee2558527e6790a5f (diff) | |
parent | 6e47677acf98934b76fb5f6337867b276ce7bce8 (diff) |
Merge pull request #208 from podsvirov/topic-cmake-project
Added CMake project
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..7b19f287 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,59 @@ +cmake_minimum_required(VERSION 2.8) + +project(nanopb C) + +set(nanopb_VERSION_STRING nanopb-0.3.7-dev) + +string(REPLACE "nanopb-" "" nanopb_VERSION ${nanopb_VERSION_STRING}) + +option(nanopb_MSVC_STATIC_RUNTIME "Link static runtime libraries" ON) + +if(NOT DEFINED CMAKE_DEBUG_POSTFIX) + set(CMAKE_DEBUG_POSTFIX "d") +endif() + +if(MSVC AND nanopb_MSVC_STATIC_RUNTIME) + foreach(flag_var + CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO) + if(${flag_var} MATCHES "/MD") + string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") + endif(${flag_var} MATCHES "/MD") + endforeach(flag_var) +endif() + +add_library(libprotobuf-nanopb STATIC + pb.h + pb_common.h + pb_common.c + pb_encode.h + pb_encode.c + pb_decode.h + pb_decode.c) + +target_include_directories(libprotobuf-nanopb INTERFACE + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> +) + +include(GNUInstallDirs) + +if(NOT DEFINED CMAKE_INSTALL_CMAKEDIR) + set(CMAKE_INSTALL_CMAKEDIR "lib/cmake/nanopb") +endif() + +install(TARGETS libprotobuf-nanopb EXPORT nanopb-targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +install(EXPORT nanopb-targets + DESTINATION ${CMAKE_INSTALL_CMAKEDIR} + NAMESPACE nanopb::) + +configure_file(extra/nanopb-config-version.cmake.in + nanopb-config-version.cmake @ONLY) + +install(FILES extra/nanopb-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/nanopb-config-version.cmake + DESTINATION ${CMAKE_INSTALL_CMAKEDIR}) + +install(FILES pb.h pb_common.h pb_encode.h pb_decode.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |