Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some problems with the Protobuf CMake file #4262

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Review comments.
  • Loading branch information
fruffy committed Jan 3, 2024
commit 8c28a5797a729e5968aa0fef9ce241ea1a1efc10
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Set the required options for a (mostly) static release build.
if(BUILD_STATIC_RELEASE_SANS_GLIBC)
message(STATUS "Building static release binaries")
message(WARNING "glibc is linked dynamically in current static builds.")
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
# Link Boost statically
Expand Down
44 changes: 5 additions & 39 deletions cmake/Protobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,8 @@ macro(p4c_obtain_protobuf)
if(NOT Protobuf_FOUND)
find_package(Protobuf REQUIRED)
endif()
# Backwards compatibility
# Define camel case versions of input variables
foreach(UPPER
PROTOBUF_SRC_ROOT_FOLDER
PROTOBUF_IMPORT_DIRS
PROTOBUF_DEBUG
PROTOBUF_LIBRARY
PROTOBUF_PROTOC_LIBRARY
PROTOBUF_INCLUDE_DIR
PROTOBUF_PROTOC_EXECUTABLE
PROTOBUF_LIBRARY_DEBUG
PROTOBUF_PROTOC_LIBRARY_DEBUG
PROTOBUF_LITE_LIBRARY
PROTOBUF_LITE_LIBRARY_DEBUG
)
if (DEFINED ${UPPER})
string(REPLACE "PROTOBUF_" "Protobuf_" Camel ${UPPER})
if (NOT DEFINED ${Camel})
set(${Camel} ${${UPPER}})
endif()
endif()
endforeach()
# Protobuf sets the protoc binary to a generator expression, which are highly problematic.
# They are problematic because they are basically evaluated at build time.
# Protobuf sets the protoc binary to a generator expression, which are problematic.
# They are problematic because they are only evaluated at build time.
# However, we may have scripts that depend on the actual build time during the configure phase.
# Hard code a custom binary instead.
find_program(PROTOC_BINARY protoc)
Expand Down Expand Up @@ -69,18 +47,6 @@ macro(p4c_obtain_protobuf)
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "Build Shared Libraries")
# This is necessary to be able to call FindPackage.
set(protobuf_INSTALL ON CACHE BOOL "Install Protobuf")
# Derive the target architecture in order to build the right architecture.
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL
"arm64"
)
set(protobuf_ARCH "aarch_64")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL
"amd64"
)
set(protobuf_ARCH "x86_64")
else()
message(FATAL_ERROR "Unsupported host architecture `${CMAKE_HOST_SYSTEM_PROCESSOR}`")
endif()

fetchcontent_declare(
protobuf
Expand All @@ -105,10 +71,10 @@ macro(p4c_obtain_protobuf)
set(Protobuf_LIBRARY "protobuf::libprotobuf")
set(Protobuf_PROTOC_LIBRARY "protobuf::libprotoc")
set(Protobuf_PROTOC_EXECUTABLE $<TARGET_FILE:protoc>)
# Protobuf sets the protoc binary to a generator expression, which are highly problematic.
# They are problematic because they are basically evaluated at build time.
# Protobuf sets the protoc binary to a generator expression, which are problematic.
# They are problematic because they are only evaluated at build time.
# However, we may have scripts that depend on the actual build time during the configure phase.
# Hard code a custom binary instead.
# Hard code a custom binary which we can use in addition to the generator expression.
set(PROTOC_BINARY ${protobuf_BINARY_DIR}/protoc)
set(Protobuf_INCLUDE_DIR "${protobuf_SOURCE_DIR}/src/")

Expand Down
Loading