summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2017-02-12 10:52:26 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2017-02-12 10:52:26 +0200
commit112fd594442aaf8003764b32390d60162a38131b (patch)
treebd531424e441794d9795d392d78d69e5090f769f /CMakeLists.txt
parent2467922d47a579d447406eddcecdb1127d33213b (diff)
parenta5d90990263b3171cc699315e69d0e09f6a420ad (diff)
Merge branch 'master' of github.com:nanopb/nanopb
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt83
1 files changed, 57 insertions, 26 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7889bf4a..f69386bf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,12 +6,16 @@ set(nanopb_VERSION_STRING nanopb-0.3.8-dev)
string(REPLACE "nanopb-" "" nanopb_VERSION ${nanopb_VERSION_STRING})
+option(nanopb_BUILD_RUNTIME "Build the headers and libraries needed at runtime" ON)
+option(nanopb_BUILD_GENERATOR "Build the protoc plugin for code generation" ON)
option(nanopb_MSVC_STATIC_RUNTIME "Link static runtime libraries" ON)
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "d")
endif()
+include(GNUInstallDirs)
+
if(MSVC AND nanopb_MSVC_STATIC_RUNTIME)
foreach(flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
@@ -22,38 +26,65 @@ if(MSVC AND nanopb_MSVC_STATIC_RUNTIME)
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)
+if(NOT DEFINED CMAKE_INSTALL_CMAKEDIR)
+ set(CMAKE_INSTALL_CMAKEDIR "lib/cmake/nanopb")
+endif()
-target_include_directories(libprotobuf-nanopb INTERFACE
- $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
-)
+if(nanopb_BUILD_GENERATOR)
+ set(generator_protos nanopb plugin)
-include(GNUInstallDirs)
+ find_package(PythonInterp 2.7 REQUIRED)
+ execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} -c
+ "from distutils import sysconfig; print(sysconfig.get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}'))"
+ OUTPUT_VARIABLE PYTHON_INSTDIR
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
-if(NOT DEFINED CMAKE_INSTALL_CMAKEDIR)
- set(CMAKE_INSTALL_CMAKEDIR "lib/cmake/nanopb")
+ foreach(generator_proto IN LISTS generator_protos)
+ string(REGEX REPLACE "([^;]+)" "generator/proto/\\1.proto" generator_proto_file "${generator_proto}")
+ string(REGEX REPLACE "([^;]+)" "\\1_pb2.py" generator_proto_py_file "${generator_proto}")
+ add_custom_command(
+ OUTPUT ${generator_proto_py_file}
+ COMMAND protoc --python_out=${CMAKE_CURRENT_BINARY_DIR} -Igenerator/proto ${generator_proto_file}
+ DEPENDS ${generator_proto_file}
+ )
+ add_custom_target("generate_${generator_proto_py_file}" ALL DEPENDS ${generator_proto_py_file})
+ install(
+ FILES ${generator_proto_py_file}
+ DESTINATION ${PYTHON_INSTDIR}
+ )
+ endforeach()
endif()
-install(TARGETS libprotobuf-nanopb EXPORT nanopb-targets
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+if(nanopb_BUILD_RUNTIME)
+ add_library(protobuf-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(protobuf-nanopb INTERFACE
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+ )
-install(EXPORT nanopb-targets
- DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
- NAMESPACE nanopb::)
+ configure_file(extra/nanopb-config-version.cmake.in
+ nanopb-config-version.cmake @ONLY)
-configure_file(extra/nanopb-config-version.cmake.in
- nanopb-config-version.cmake @ONLY)
+ install(TARGETS protobuf-nanopb EXPORT nanopb-targets
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
-install(FILES extra/nanopb-config.cmake
- ${CMAKE_CURRENT_BINARY_DIR}/nanopb-config-version.cmake
- DESTINATION ${CMAKE_INSTALL_CMAKEDIR})
+ install(EXPORT nanopb-targets
+ DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
+ NAMESPACE nanopb::)
-install(FILES pb.h pb_common.h pb_encode.h pb_decode.h
- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+ 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})
+endif()