diff options
author | soroshsabz <soorosh_abi@hotmail.com> | 2019-03-15 15:05:18 +0330 |
---|---|---|
committer | James E. King III <jking@apache.org> | 2019-03-15 07:35:18 -0400 |
commit | 0c4e96f956cd7e3dc527ef215b14c0407148f46c (patch) | |
tree | 2bc1d8477988206f8a16dad9357d630a164e0594 /build/cmake | |
parent | bf27637960aca6a6c3c5eb700a677e57b88b2409 (diff) | |
download | thrift-0c4e96f956cd7e3dc527ef215b14c0407148f46c.tar.gz |
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_abi@hotmail.com>
Diffstat (limited to 'build/cmake')
-rw-r--r-- | build/cmake/DefineInstallationPaths.cmake | 3 | ||||
-rw-r--r-- | build/cmake/GenerateConfigModule.cmake | 44 | ||||
-rw-r--r-- | build/cmake/ThriftConfig.cmake.in | 42 | ||||
-rw-r--r-- | build/cmake/ThriftMacros.cmake | 12 |
4 files changed, 98 insertions, 3 deletions
diff --git a/build/cmake/DefineInstallationPaths.cmake b/build/cmake/DefineInstallationPaths.cmake index d9a7174ac..0c824cc7a 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 000000000..9533c8235 --- /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 000000000..c304da04d --- /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 8f370df6c..d068b2ae6 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) |