Skip to content

Commit

Permalink
THRIFT-5667: Make ThriftConfig.cmake relocatable
Browse files Browse the repository at this point in the history
Client: cpp

The current ThriftConfig.cmake isn't relocatable. It means that we
can't move ThriftConfig.cmake installed by "make install".

In general, users don't need to move ThriftConfig.cmake installed by
"make install" but some packaging systems such as conda and MSYS2 needs
to move. Because users of these packaging systems may use different
prefix. For example, conda may be used with ~alice/my-conda and
~bob/conda as base directory.

CMake has a feature to make Config.cmake relocatable:
https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html

We can use it to make ThriftConfig.cmake relocatable.
  • Loading branch information
kou authored and Jens-G committed Feb 19, 2025
1 parent 24df0a5 commit 951bb18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
11 changes: 4 additions & 7 deletions build/cmake/GenerateConfigModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,16 @@
#

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
# In CYGWIN environment 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
INCLUDE_INSTALL_DIR
CMAKE_INSTALL_DIR
BIN_INSTALL_DIR
)

write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/ThriftConfigVersion.cmake"
Expand Down
5 changes: 3 additions & 2 deletions build/cmake/ThriftConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ 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_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}")

set_and_check(THRIFT_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@/thrift")
set_and_check(THRIFT_BIN_DIR "@PACKAGE_BIN_INSTALL_DIR@")
if(NOT DEFINED THRIFT_COMPILER)
set(THRIFT_COMPILER "${THRIFT_BIN_DIR}/thrift@CMAKE_EXECUTABLE_SUFFIX@")
Expand Down

0 comments on commit 951bb18

Please sign in to comment.