# set\_target\_properties doesn't work properly

**URL:** https://discourse.cmake.org/t/set-target-properties-doesnt-work-properly/7016
**Category:** Code
**Created:** [December 5, 2022, 8:23pm UTC](https://discourse.cmake.org/t/set-target-properties-doesnt-work-properly/7016 "2022-12-05T20:23:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![shiltian](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shiltian/32/2980_2.png) [@shiltian](https://discourse.cmake.org/u/shiltian)
#### Post date: [December 5, 2022, 8:23pm UTC](https://discourse.cmake.org/t/set-target-properties-doesnt-work-properly/7016/1 "2022-12-05T20:23:30Z")

</div>

Hi CMake community,

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

```cmake
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!

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 5, 2022, 10:18pm UTC](https://discourse.cmake.org/t/set-target-properties-doesnt-work-properly/7016/2 "2022-12-05T22:18:57Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![shiltian](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shiltian/32/2980_2.png) [@shiltian](https://discourse.cmake.org/u/shiltian)
#### Post date: [December 6, 2022, 3:44am UTC](https://discourse.cmake.org/t/set-target-properties-doesnt-work-properly/7016/3 "2022-12-06T03:44:11Z")

</div>

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.
