set_target_properties doesn't work properly

Hi CMake community,

I got a small piece of code where set_target_properties doesn’t work as expected.

add_compile_definitions(
  TARGET_NAME="PluginInterface"
  DEBUG_PREFIX="PluginInterface"
  )

add_llvm_library(PluginInterface OBJECT
    PluginInterface.cpp GlobalHandler.cpp

  BUILDTREE_ONLY

  LINK_COMPONENTS
    Support

  LINK_LIBS
  PRIVATE
    elf_common
    MemoryManager
)

set_target_properties(PluginInterface PROPERTIES
  POSITION_INDEPENDENT_CODE ON
  CXX_VISIBILITY_PRESET protected)

target_include_directories(PluginInterface INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(PluginInterface PRIVATE ${LIBOMPTARGET_INCLUDE_DIR})

I set CXX_VISIBILITY_PRESET of the target PluginInterface to protected. It is expected to have -fvisibility=protected when the two cpp files are compiled. However, -fvisibility=protected doesn’t exist. Of course -fPIC neither. If I replace add_llvm_library with add_library, and of course remove those arguments that add_library doesn’t recognize, things work pretty fine.

I’m wondering what could potentially cause this issue, and what I should look into add_llvm_library. I did use cmake_print_properties on PluginInterface and CXX_VISIBILITY_PRESET is properly set, but just not in the compile flags. Any suggestion would be appreciated. Thanks!

I would use cmake --trace-expand to see what add_llvm_library is actually doing. If I had to guess, there’s an internal target with the sources and the name you give is some “facade” target that just puts things together in some way. But I don’t know.

1 Like

Thanks! It is something like that, but add_llvm_library does create a target using the name I give by add_library. It turns out add_llvm_library has more problems of using object libraries, so I eventually give it up.