Xilinx / Vitis-AI

Vitis AI is Xilinx’s development stack for AI inference on Xilinx hardware platforms, including both edge devices and Alveo cards.
https://www.xilinx.com/ai
Apache License 2.0
1.47k stars 630 forks source link

xir-config.cmake sets Protobuf_USE_STATIC_LIBS to ON when flag BUILD_SHARED_LIBS is not set #1316

Open federico-lmo opened 1 year ago

federico-lmo commented 1 year ago

I'm working on a CMake project which uses the Petalinux SDK with the sysroot environment generated by the script board_setup/mpsoc/host_cross_compiler_setup.sh. The application uses the xir library, whose package information is loaded via find_package(xir).

When the flag BUILD_SHARED_LIBS is not set, building will fail because there are no Protobuf static libraries available in the sysroot.

The reason is this extract from petalinux_sdk_2022.2/sysroots/cortexa72-cortexa53-xilinx-linux/usr/share/cmake/xir/xir-config.cmake

if(NOT BUILD_SHARED_LIBS)
  find_package(Boost REQUIRED)
  if(BUILD_SHARED_LIBS)
     set(Protobuf_USE_STATIC_LIBS OFF)
  else(BUILD_SHARED_LIBS)
     set(Protobuf_USE_STATIC_LIBS ON)
  endif(BUILD_SHARED_LIBS)
  find_package(Protobuf REQUIRED)
endif(NOT BUILD_SHARED_LIBS)

My understanding from the BUILD_SHARED_LIBS flag documentation is that it is meant to be used from the command line (or from a CMake preset) if one wants to force building all the libraries provided by a project as dynamic libraries. Whether the project dependencies are linked to dynamically or statically should mainly depend on what is available. Hard-coding the BUILD_SHARED_LIBS flag in the project CMakeLists.txt works but it is not a proper solution as it forces everything to be dynamic. Commenting out set(Protobuf_USE_STATIC_LIBS ON) makes the compilation succeed and I wonder if this can be fixed upstream.

INFO: Petalinux SDK: 2022.2 Vitis-AI: 3.0 CMake: 3.25.1

lishixlnx commented 1 year ago

You comment is correct. There is some issue in this cmake file. It is fixed in v3.5 which is:

_if(NOT BUILD_SHARED_LIBS) find_package(Boost REQUIRED) option(Protobuf_USE_STATIC_LIBS "protobuf static lib" OFF) find_package(Protobuf REQUIRED) endif(NOT BUILD_SHAREDLIBS)