From 1cc248404051effe861fe0efb72e03233b17d7bd Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Fri, 9 Aug 2024 16:18:05 +0200 Subject: [PATCH] build: factor out thrift setup from main CMakeLists.txt --- CMakeLists.txt | 47 ++---------------------------------- cmake/thrift.cmake | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 45 deletions(-) create mode 100644 cmake/thrift.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7de00f6c..e561adb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -193,7 +193,6 @@ if(ENABLE_STACKTRACE) endif() include(${CMAKE_SOURCE_DIR}/cmake/version.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/thrift_library.cmake) if(NOT PRJ_VERSION_FULL) message(FATAL_ERROR "PRJ_VERSION_FULL is not set") @@ -342,9 +341,6 @@ endif() find_package(PkgConfig) if(APPLE) - # For whatever reason, thrift is unhappy if we don't do this - find_package(OpenSSL 1.1.1 MODULE REQUIRED) - if(USE_HOMEBREW_LIBARCHIVE) find_program(HOMEBREW_EXE brew) execute_process( @@ -402,14 +398,8 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") endif() include(${CMAKE_SOURCE_DIR}/cmake/folly.cmake) - -if(DWARFS_GIT_BUILD) - set(THRIFT_COMPILER_ONLY - ON - CACHE BOOL "only build thrift compiler") - - add_subdirectory(fbthrift EXCLUDE_FROM_ALL SYSTEM) -endif() +include(${CMAKE_SOURCE_DIR}/cmake/thrift.cmake) +include(${CMAKE_SOURCE_DIR}/cmake/thrift_library.cmake) if(WITH_TESTS) if(PREFER_SYSTEM_GTEST) @@ -868,39 +858,6 @@ if(WITH_MAN_PAGES) endif() endif() -if(DWARFS_GIT_BUILD) - set(THRIFT_GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR}) -else() - set(THRIFT_GENERATED_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -endif() - -add_library( - dwarfs_thrift_lite OBJECT - ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp/protocol/TProtocolException.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp/util/VarintUtils.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/FieldRef.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/frozen/Frozen.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/frozen/FrozenUtil.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/frozen/schema/MemorySchema.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/gen/module_types_cpp.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/protocol/BinaryProtocol.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/protocol/CompactProtocol.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/protocol/DebugProtocol.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/protocol/JSONProtocol.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/protocol/JSONProtocolCommon.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/protocol/Protocol.cpp - ${THRIFT_GENERATED_DIR}/thrift/lib/thrift/gen-cpp2/frozen_data.cpp - ${THRIFT_GENERATED_DIR}/thrift/lib/thrift/gen-cpp2/frozen_types.cpp -) - -set_property(TARGET dwarfs_thrift_lite PROPERTY CXX_STANDARD 20) -target_link_libraries(dwarfs_thrift_lite PUBLIC dwarfs_folly_lite) - -target_include_directories(dwarfs_thrift_lite SYSTEM PUBLIC - $ - $ -) - target_link_libraries(dwarfs_common PRIVATE dwarfs_thrift_lite) add_cpp2_thrift_library(fbthrift/thrift/lib/thrift/frozen.thrift diff --git a/cmake/thrift.cmake b/cmake/thrift.cmake new file mode 100644 index 00000000..f67d6557 --- /dev/null +++ b/cmake/thrift.cmake @@ -0,0 +1,60 @@ +# +# Copyright (c) Marcus Holland-Moritz +# +# This file is part of dwarfs. +# +# dwarfs is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# dwarfs is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# dwarfs. If not, see . +# + +cmake_minimum_required(VERSION 3.28.0) + +if(APPLE) + # For whatever reason, thrift is unhappy if we don't do this + find_package(OpenSSL 1.1.1 MODULE REQUIRED) +endif() + +if(DWARFS_GIT_BUILD) + set(THRIFT_COMPILER_ONLY ON CACHE BOOL "only build thrift compiler") + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/fbthrift EXCLUDE_FROM_ALL SYSTEM) + set(THRIFT_GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR}) +else() + set(THRIFT_GENERATED_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +endif() + +add_library( + dwarfs_thrift_lite OBJECT + ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp/protocol/TProtocolException.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp/util/VarintUtils.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/FieldRef.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/frozen/Frozen.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/frozen/FrozenUtil.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/frozen/schema/MemorySchema.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/gen/module_types_cpp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/protocol/BinaryProtocol.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/protocol/CompactProtocol.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/protocol/DebugProtocol.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/protocol/JSONProtocol.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/protocol/JSONProtocolCommon.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/fbthrift/thrift/lib/cpp2/protocol/Protocol.cpp + ${THRIFT_GENERATED_DIR}/thrift/lib/thrift/gen-cpp2/frozen_data.cpp + ${THRIFT_GENERATED_DIR}/thrift/lib/thrift/gen-cpp2/frozen_types.cpp +) + +set_property(TARGET dwarfs_thrift_lite PROPERTY CXX_STANDARD 20) +target_link_libraries(dwarfs_thrift_lite PUBLIC dwarfs_folly_lite) + +target_include_directories(dwarfs_thrift_lite SYSTEM PUBLIC + $ + $ +) +