diff options
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/CMakeLists.txt | 6 | ||||
-rw-r--r-- | cmake/examples.cmake | 114 | ||||
-rw-r--r-- | cmake/extract_includes.bat.in | 1 | ||||
-rw-r--r-- | cmake/install.cmake | 2 | ||||
-rw-r--r-- | cmake/libprotobuf.cmake | 5 | ||||
-rw-r--r-- | cmake/protobuf-config-version.cmake.in | 2 | ||||
-rw-r--r-- | cmake/protobuf-config.cmake.in | 3 | ||||
-rw-r--r-- | cmake/protobuf-module.cmake.in | 1 | ||||
-rw-r--r-- | cmake/protobuf-options.cmake | 14 |
9 files changed, 79 insertions, 69 deletions
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 07b176d9..df3b2012 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -86,6 +86,7 @@ if (CMAKE_USE_PTHREADS_INIT) add_definitions(-DHAVE_PTHREAD) endif (CMAKE_USE_PTHREADS_INIT) +set(_protobuf_FIND_ZLIB) if (protobuf_WITH_ZLIB) find_package(ZLIB) if (ZLIB_FOUND) @@ -96,6 +97,7 @@ if (protobuf_WITH_ZLIB) # Using imported target if exists if (TARGET ZLIB::ZLIB) set(ZLIB_LIBRARIES ZLIB::ZLIB) + set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND)\n find_package(ZLIB)\nendif()") endif (TARGET ZLIB::ZLIB) else (ZLIB_FOUND) set(HAVE_ZLIB 0) @@ -157,6 +159,10 @@ else (MSVC) set(LIB_PREFIX) endif (MSVC) +if (protobuf_UNICODE) + add_definitions(-DUNICODE -D_UNICODE) +endif (protobuf_UNICODE) + include(libprotobuf-lite.cmake) include(libprotobuf.cmake) include(libprotoc.cmake) diff --git a/cmake/examples.cmake b/cmake/examples.cmake index 0a651051..e5cad63f 100644 --- a/cmake/examples.cmake +++ b/cmake/examples.cmake @@ -1,57 +1,57 @@ -if(protobuf_VERBOSE)
- message(STATUS "Protocol Buffers Examples Configuring...")
-endif()
-
-get_filename_component(examples_dir "../examples" ABSOLUTE)
-
-if(protobuf_VERBOSE)
- message(STATUS "Protocol Buffers Examples Configuring done")
-endif()
-include(ExternalProject)
-
-# Internal utility function: Create a custom target representing a build of examples with custom options.
-function(add_examples_build NAME)
-
- ExternalProject_Add(${NAME}
- PREFIX ${NAME}
- SOURCE_DIR "${examples_dir}"
- BINARY_DIR ${NAME}
- STAMP_DIR ${NAME}/logs
- INSTALL_COMMAND "" #Skip
- LOG_CONFIGURE 1
- CMAKE_CACHE_ARGS "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
- "-Dprotobuf_VERBOSE:BOOL=${protobuf_VERBOSE}"
- ${ARGN}
- )
- set_property(TARGET ${NAME} PROPERTY FOLDER "Examples")
- set_property(TARGET ${NAME} PROPERTY EXCLUDE_FROM_ALL TRUE)
-endfunction()
-
-# Add examples as an external project.
-# sub_directory cannot be used because the find_package(protobuf) call would cause failures with redefined targets.
-add_examples_build(examples "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}")
-add_dependencies(examples libprotobuf protoc)
-
-option(protobuf_BUILD_EXAMPLES_MULTITEST "Build Examples in multiple configurations. Useful for testing." OFF)
-mark_as_advanced(protobuf_BUILD_EXAMPLES_MULTITEST)
-if(protobuf_BUILD_EXAMPLES_MULTITEST)
- set_property(GLOBAL PROPERTY USE_FOLDERS ON)
-
- #Build using the legacy compatibility module.
- add_examples_build(examples-legacy
- "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}"
- "-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE"
- )
- add_dependencies(examples-legacy libprotobuf protoc)
-
- #Build using the installed library.
- add_examples_build(examples-installed
- "-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}"
- )
-
- #Build using the installed library in legacy compatibility mode.
- add_examples_build(examples-installed-legacy
- "-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}"
- "-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE"
- )
-endif()
+if(protobuf_VERBOSE) + message(STATUS "Protocol Buffers Examples Configuring...") +endif() + +get_filename_component(examples_dir "../examples" ABSOLUTE) + +if(protobuf_VERBOSE) + message(STATUS "Protocol Buffers Examples Configuring done") +endif() +include(ExternalProject) + +# Internal utility function: Create a custom target representing a build of examples with custom options. +function(add_examples_build NAME) + + ExternalProject_Add(${NAME} + PREFIX ${NAME} + SOURCE_DIR "${examples_dir}" + BINARY_DIR ${NAME} + STAMP_DIR ${NAME}/logs + INSTALL_COMMAND "" #Skip + LOG_CONFIGURE 1 + CMAKE_CACHE_ARGS "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}" + "-Dprotobuf_VERBOSE:BOOL=${protobuf_VERBOSE}" + ${ARGN} + ) + set_property(TARGET ${NAME} PROPERTY FOLDER "Examples") + set_property(TARGET ${NAME} PROPERTY EXCLUDE_FROM_ALL TRUE) +endfunction() + +# Add examples as an external project. +# sub_directory cannot be used because the find_package(protobuf) call would cause failures with redefined targets. +add_examples_build(examples "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}") +add_dependencies(examples libprotobuf protoc) + +option(protobuf_BUILD_EXAMPLES_MULTITEST "Build Examples in multiple configurations. Useful for testing." OFF) +mark_as_advanced(protobuf_BUILD_EXAMPLES_MULTITEST) +if(protobuf_BUILD_EXAMPLES_MULTITEST) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + + #Build using the legacy compatibility module. + add_examples_build(examples-legacy + "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}" + "-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE" + ) + add_dependencies(examples-legacy libprotobuf protoc) + + #Build using the installed library. + add_examples_build(examples-installed + "-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}" + ) + + #Build using the installed library in legacy compatibility mode. + add_examples_build(examples-installed-legacy + "-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}" + "-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE" + ) +endif() diff --git a/cmake/extract_includes.bat.in b/cmake/extract_includes.bat.in index c76973c9..9edafca8 100644 --- a/cmake/extract_includes.bat.in +++ b/cmake/extract_includes.bat.in @@ -69,7 +69,6 @@ copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\metadata.h include\goo copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\reflection.h include\google\protobuf\reflection.h copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\reflection_ops.h include\google\protobuf\reflection_ops.h copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\repeated_field.h include\google\protobuf\repeated_field.h -copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\repeated_field_reflection.h include\google\protobuf\repeated_field_reflection.h copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\service.h include\google\protobuf\service.h copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\source_context.pb.h include\google\protobuf\source_context.pb.h copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\struct.pb.h include\google\protobuf\struct.pb.h diff --git a/cmake/install.cmake b/cmake/install.cmake index 94ef2198..73e31984 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -110,7 +110,7 @@ install(EXPORT protobuf-targets NAMESPACE protobuf:: COMPONENT protobuf-export) -install(DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/ +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/ DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" COMPONENT protobuf-export PATTERN protobuf-targets.cmake EXCLUDE diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index 8930c1ca..26e1f356 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -56,7 +56,10 @@ set(libprotobuf_files add_library(libprotobuf ${protobuf_SHARED_OR_STATIC} ${libprotobuf_lite_files} ${libprotobuf_files}) -target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES}) +target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT}) +if(protobuf_WITH_ZLIB) + target_link_libraries(libprotobuf ${ZLIB_LIBRARIES}) +endif() target_include_directories(libprotobuf PUBLIC ${protobuf_source_dir}/src) if(MSVC AND protobuf_BUILD_SHARED_LIBS) target_compile_definitions(libprotobuf diff --git a/cmake/protobuf-config-version.cmake.in b/cmake/protobuf-config-version.cmake.in index 3b8ced2d..0036c9ef 100644 --- a/cmake/protobuf-config-version.cmake.in +++ b/cmake/protobuf-config-version.cmake.in @@ -3,7 +3,7 @@ set(${PACKAGE_FIND_NAME}_VERSION_PRERELEASE "@protobuf_VERSION_PRERELEASE@" PARE # Prerelease versions cannot be passed in directly via the find_package command, # so we allow users to specify it in a variable -if(NOT DEFINED "${${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE}") +if(NOT DEFINED "${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE") set("${${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE}" "") else() set(PACKAGE_FIND_VERSION ${PACKAGE_FIND_VERSION}-${${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE}) diff --git a/cmake/protobuf-config.cmake.in b/cmake/protobuf-config.cmake.in index 37315510..a044fe5c 100644 --- a/cmake/protobuf-config.cmake.in +++ b/cmake/protobuf-config.cmake.in @@ -1,6 +1,9 @@ # User options include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake") +# Depend packages +@_protobuf_FIND_ZLIB@ + # Imported targets include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake") diff --git a/cmake/protobuf-module.cmake.in b/cmake/protobuf-module.cmake.in index 6e0bcf90..614e4c04 100644 --- a/cmake/protobuf-module.cmake.in +++ b/cmake/protobuf-module.cmake.in @@ -147,7 +147,6 @@ function(_protobuf_find_libraries name filename) LOCATION_RELEASE) get_target_property(${name}_LIBRARY_DEBUG protobuf::lib${filename} LOCATION_DEBUG) - endif() select_library_configurations(${name}) set(${name}_LIBRARY ${${name}_LIBRARY} PARENT_SCOPE) diff --git a/cmake/protobuf-options.cmake b/cmake/protobuf-options.cmake index 99c85ebe..47fb1582 100644 --- a/cmake/protobuf-options.cmake +++ b/cmake/protobuf-options.cmake @@ -1,7 +1,7 @@ -# Verbose output
-option(protobuf_VERBOSE "Enable for verbose output" OFF)
-mark_as_advanced(protobuf_VERBOSE)
-
-# FindProtobuf module compatibel
-option(protobuf_MODULE_COMPATIBLE "CMake build-in FindProtobuf.cmake module compatible" OFF)
-mark_as_advanced(protobuf_MODULE_COMPATIBLE)
+# Verbose output +option(protobuf_VERBOSE "Enable for verbose output" OFF) +mark_as_advanced(protobuf_VERBOSE) + +# FindProtobuf module compatibel +option(protobuf_MODULE_COMPATIBLE "CMake build-in FindProtobuf.cmake module compatible" OFF) +mark_as_advanced(protobuf_MODULE_COMPATIBLE) |