This is an automated email from the ASF dual-hosted git repository.

jking pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new 0c4e96f  THRIFT-4811: Add CMake config file and targets. (see #4752) 
(#1748)
0c4e96f is described below

commit 0c4e96f956cd7e3dc527ef215b14c0407148f46c
Author: soroshsabz <soorosh_...@hotmail.com>
AuthorDate: Fri Mar 15 15:05:18 2019 +0330

    THRIFT-4811: Add CMake config file and targets. (see #4752) (#1748)
    
    * Add CMake config file and targets. (see #4752)
    * Exclude cygwin
    
    Co-Authored-By: soroshsabz <soorosh_...@hotmail.com>
---
 CMakeLists.txt                            |  3 +++
 build/cmake/DefineInstallationPaths.cmake |  3 ++-
 build/cmake/GenerateConfigModule.cmake    | 44 +++++++++++++++++++++++++++++++
 build/cmake/ThriftConfig.cmake.in         | 42 +++++++++++++++++++++++++++++
 build/cmake/ThriftMacros.cmake            | 12 +++++++--
 5 files changed, 101 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c77a601..1880b79 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,6 +53,9 @@ include(StaticCodeAnalysis)
 # Generate the config.h file
 include(ConfigureChecks)
 
+# Generate the ThriftConfig.cmake module
+include(GenerateConfigModule)
+
 # Packaging
 include(CPackConfig)
 
diff --git a/build/cmake/DefineInstallationPaths.cmake 
b/build/cmake/DefineInstallationPaths.cmake
index d9a7174..0c824cc 100644
--- a/build/cmake/DefineInstallationPaths.cmake
+++ b/build/cmake/DefineInstallationPaths.cmake
@@ -22,10 +22,11 @@
 set(BIN_INSTALL_DIR "bin" CACHE PATH "The binary install dir (default: bin)")
 set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "The library install dir 
(default: lib${LIB_SUFFIX})")
 set(INCLUDE_INSTALL_DIR "include" CACHE PATH "The library install dir 
(default: include)")
-set(CMAKE_INSTALL_DIR "cmake" CACHE PATH "The subdirectory to install cmake 
config files (default: cmake)")
+set(CMAKE_INSTALL_DIR "lib/cmake" CACHE PATH "The subdirectory to install 
cmake config files (default: cmake)")
 set(PKGCONFIG_INSTALL_DIR "lib/pkgconfig" CACHE PATH "The subdirectory to 
install pkgconfig config files (default: lib/pkgconfig)")
 set(DOC_INSTALL_DIR "share/doc" CACHE PATH "The subdirectory to install 
documentation files (default: share/doc)")
 set(prefix "${CMAKE_INSTALL_PREFIX}")
 set(exec_prefix "${CMAKE_INSTALL_PREFIX}/bin")
 set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
 set(includedir "${CMAKE_INSTALL_PREFIX}/include")
+set(cmakedir "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DIR}")
diff --git a/build/cmake/GenerateConfigModule.cmake 
b/build/cmake/GenerateConfigModule.cmake
new file mode 100644
index 0000000..9533c82
--- /dev/null
+++ b/build/cmake/GenerateConfigModule.cmake
@@ -0,0 +1,44 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+include(CMakePackageConfigHelpers)
+set(PACKAGE_INCLUDE_INSTALL_DIR "${includedir}/thrift")
+set(PACKAGE_CMAKE_INSTALL_DIR "${cmakedir}/thrift")
+set(PACKAGE_BIN_INSTALL_DIR "${exec_prefix}")
+
+# In CYGWIN enviroment below commands does not work properly
+if (NOT CYGWIN)
+               
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/ThriftConfig.cmake.in"
+                                               
"${CMAKE_CURRENT_BINARY_DIR}/ThriftConfig.cmake"
+                                               INSTALL_DESTINATION 
"${CMAKE_INSTALL_DIR}/thrift"
+                                               PATH_VARS
+                                               PACKAGE_INCLUDE_INSTALL_DIR
+                                               PACKAGE_CMAKE_INSTALL_DIR
+                                               PACKAGE_BIN_INSTALL_DIR
+                                               )
+
+               
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/ThriftConfigVersion.cmake"
+                                               VERSION 
${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH}
+                                               COMPATIBILITY SameMajorVersion
+                                               )
+
+               install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ThriftConfig.cmake"
+                                               
"${CMAKE_CURRENT_BINARY_DIR}/ThriftConfigVersion.cmake"
+                                               DESTINATION 
"${CMAKE_INSTALL_DIR}/thrift")
+endif()
diff --git a/build/cmake/ThriftConfig.cmake.in 
b/build/cmake/ThriftConfig.cmake.in
new file mode 100644
index 0000000..c304da0
--- /dev/null
+++ b/build/cmake/ThriftConfig.cmake.in
@@ -0,0 +1,42 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+set(THRIFT_VERSION ${thrift_VERSION})
+
+@PACKAGE_INIT@
+
+set_and_check(THRIFT_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
+set_and_check(THRIFT_CMAKE_DIR "@PACKAGE_CMAKE_INSTALL_DIR@")
+set_and_check(THRIFT_BIN_DIR "@PACKAGE_BIN_INSTALL_DIR@")
+
+if (NOT TARGET thrift::thrift)
+  include("${THRIFT_CMAKE_DIR}/thriftTargets.cmake")
+endif()
+
+set(THRIFT_LIBRARIES thrift::thrift)
+
+if ("${THRIFT_LIBRARIES}" STREQUAL "")
+       message(FATAL_ERROR "thrift libraries were not found")
+endif()
+
+if (NOT Thrift_FIND_QUIETLY)
+  message(STATUS "Found thrift: ${PACKAGE_PREFIX_DIR}")
+endif()
+
+check_required_components(Thrift)
diff --git a/build/cmake/ThriftMacros.cmake b/build/cmake/ThriftMacros.cmake
index 8f370df..d068b2a 100644
--- a/build/cmake/ThriftMacros.cmake
+++ b/build/cmake/ThriftMacros.cmake
@@ -23,18 +23,26 @@ macro(ADD_PKGCONFIG_THRIFT name)
         DESTINATION "${PKGCONFIG_INSTALL_DIR}")
 endmacro(ADD_PKGCONFIG_THRIFT)
 
-
 macro(ADD_LIBRARY_THRIFT name)
     add_library(${name} ${ARGN})
     set_target_properties(${name} PROPERTIES
         OUTPUT_NAME ${name}${THRIFT_RUNTIME_POSTFIX}   # windows link variants 
(/MT, /MD, /MTd, /MDd) get different names
         VERSION ${thrift_VERSION} )
     # set_target_properties(${name} PROPERTIES PUBLIC_HEADER 
"${thriftcpp_HEADERS}")
-    install(TARGETS ${name}
+    install(TARGETS ${name} EXPORT "${name}Targets"
         RUNTIME DESTINATION "${BIN_INSTALL_DIR}"
         LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
         ARCHIVE DESTINATION "${LIB_INSTALL_DIR}"
         PUBLIC_HEADER DESTINATION "${INCLUDE_INSTALL_DIR}")
+
+       export(EXPORT "${name}Targets"
+               FILE "${CMAKE_CURRENT_BINARY_DIR}/${name}/${name}Targets.cmake"
+               NAMESPACE "${name}::")
+
+       install(EXPORT "${name}Targets"
+               FILE "${name}Targets.cmake"
+               NAMESPACE "${name}::"
+               DESTINATION "${CMAKE_INSTALL_DIR}/thrift")
 endmacro()
 
 macro(TARGET_INCLUDE_DIRECTORIES_THRIFT name)

Reply via email to