Custom Properties for Controlling Linking Behavior in CMake


  • Properties
    Targets can have properties associated with them, which control various aspects of the build process. These properties are set using the set_target_properties command.
  • Targets
    In CMake, targets represent the final output of your build process, which can be executables, libraries, or other artifacts.

It's possible that "LINK_INTERFACE_MULTIPLICITY_CONFIG" is a custom property defined in your specific CMake project. Custom properties are created using the target_compile_definitions command to define preprocessor macros.

Here are some possibilities:

  • It could be related to linker options that specify how to handle symbols with the same name coming from different libraries.
  • It might be a project-specific flag to control how target linking behaves when there are multiple definitions of the same interface.


# Define a custom property to indicate a target requires special linking
set_target_properties(my_target PROPERTIES LINK_INTERFACE_MULTIPLICITY CUSTOM)

# Target that depends on my_target, link with special options
add_executable(depending_target target.cpp)
target_link_libraries(depending_target PRIVATE my_target)

# During linking, check for the custom property and add specific linker options
if (TARGET_LINKER_LIBRARIES_${depending_target} MATCHES "CUSTOM")
  target_link_options(depending_target PRIVATE -special_linker_flag)
endif()


  1. Target Interface Flags
  • You could define a flag indicating the need for special linking and check for its presence in the depending target.
  • CMake allows setting interface flags for targets using the target_compile_definitions command. These flags are propagated to dependent targets and can influence linking behavior.
  1. Link Libraries with Options
  • Use target_link_libraries with the PRIVATE keyword to link the library and specify linker options after a colon (:).
  • Instead of a custom property, consider linking the special library with specific linker options directly.
  1. Custom Linker Script
  • This approach requires more advanced knowledge of linker scripts specific to your platform.
  • For complex linking scenarios, create a custom linker script that handles symbol conflicts or other situations based on interface definitions.
  • Custom Linker Script (Advanced Situations)
    • Offers maximum control over linking behavior.
    • Requires more effort and knowledge of linker scripts.
  • Link Libraries with Options (Efficient for Specific Libraries)
    • Clearer separation between library and linking behavior.
    • Options are specific to the library.
  • Target Interface Flags (Recommended for Simple Cases)
    • Easy to implement for basic scenarios.
    • Flags are visible in dependent targets for easier debugging.