FindProtobuf: usage broken in cross-platform oriented build
Behavior of the FindProtobuf module is broken in unclear way by two commands frequently used in cross-platform builds:
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
Simple example to replicate error:
Main CMakeLists.txt of an empty project
cmake_minimum_required(VERSION 3.22)
# set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
# set(CMAKE_SYSTEM_NAME Generic)
project(TestProject)
set(CMAKE_CXX_STANDARD 20)
add_executable(TestProject main.cpp)
find_package(Python3 REQUIRED)
find_package(Protobuf REQUIRED)
On the system with a valid Protobuf installation find_package(Protobuf REQUIRED)
works as expected if both of the commands mentioned above are commented out. Uncommenting either of them produces the following error report:
CMake Error at /snap/clion/198/bin/cmake/linux/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Protobuf (missing: Protobuf_LIBRARIES Protobuf_INCLUDE_DIR)
Call Stack (most recent call first):
/snap/clion/198/bin/cmake/linux/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/snap/clion/198/bin/cmake/linux/share/cmake-3.22/Modules/FindProtobuf.cmake:650 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:13 (find_package)
Note that find_package(Python3 REQUIRED)
has been added as a test group, and its functionality appears to be unaffected by use of those two commands.
Edited by Hrvoje Brezak