Skip to content
Snippets Groups Projects
Commit fe0aca04 authored by Petteri Aimonen's avatar Petteri Aimonen Committed by GitHub
Browse files

Merge pull request #208 from podsvirov/topic-cmake-project

Added CMake project
parents 060e6a6c 6e47677a
No related branches found
No related tags found
No related merge requests found
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})
set(PACKAGE_VERSION "@nanopb_VERSION@")
# Check whether the requested PACKAGE_FIND_VERSION is compatible
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
include(${CMAKE_CURRENT_LIST_DIR}/nanopb-targets.cmake)
......@@ -6,5 +6,6 @@
sed -i -e 's/nanopb_version\s*=\s*"[^"]*"/nanopb_version = "'$1'"/' generator/nanopb_generator.py
sed -i -e 's/#define\s*NANOPB_VERSION\s*.*/#define NANOPB_VERSION '$1'/' pb.h
sed -i -e 's/set(\s*nanopb_VERSION_STRING\s*[^)]*)/set(nanopb_VERSION_STRING '$1')/' CMakeLists.txt
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment