Skip to content

Fix CMake compile flags definition.#398

Open
jdumas wants to merge 1 commit into
RenderKit:masterfrom
jdumas:jdumas/cmake-compile-flags
Open

Fix CMake compile flags definition.#398
jdumas wants to merge 1 commit into
RenderKit:masterfrom
jdumas:jdumas/cmake-compile-flags

Conversation

@jdumas
Copy link
Copy Markdown

@jdumas jdumas commented Aug 31, 2022

When building embree as a subproject (via add_subdirectory()) and as a static library on Windows, I do get a bunch of errors of the sort:

error LNK2019: unresolved external symbol __imp_rtcNewDevice referenced in function XXX

This is because the compile flag EMBREE_STATIC_LIB is only defined for embree files (such as rtcore.cpp), but is NOT propagated transitively to downstream targets. The reason is that Embree's CMake uses the deprecated construct add_definitions(), which adds flags to a folder property. The modern CMake way to do this is to work with target properties instead, attaching compile flags to targets and properly express which ones should be transitively propagated (PUBLIC or INTERFACE properties).

This PR remedies this shortcoming by attaching all compilation flags to a new INTERFACE target embree_config, which will properly propagate the information to downstream targets.

@jdumas
Copy link
Copy Markdown
Author

jdumas commented Oct 11, 2022

@svenwoop can we get any feedback on this PR please?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes Embree’s CMake compile-flag propagation to fix downstream link/compile issues when Embree is built as a subproject (e.g., via add_subdirectory()) and as a static library on Windows. It introduces an INTERFACE config target intended to carry compile definitions transitively to downstream targets.

Changes:

  • Introduces a new INTERFACE target embree_config (aliased as embree::config) to carry Embree build configuration compile definitions.
  • Replaces directory-scope add_definitions() usage with target-scoped compile definitions on embree_config.
  • Links internal component libraries and ISA-specific libraries against embree::config to pick up configuration defines.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
CMakeLists.txt Adds embree_config interface target and moves various global -D... defines to target properties.
kernels/CMakeLists.txt Moves EMBREE_CONFIG define to embree_config, links kernel/ISA libs to embree::config, and installs embree_config.
common/tasking/CMakeLists.txt Links tasking to embree::config (TBB path) to inherit configuration defines.
common/sys/CMakeLists.txt Links sys to embree::config to inherit configuration defines.
common/simd/CMakeLists.txt Links simd to embree::config to inherit configuration defines.
common/math/CMakeLists.txt Links math to embree::config to inherit configuration defines.
common/lexers/CMakeLists.txt Links lexers to embree::config to inherit configuration defines.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CMakeLists.txt
Comment on lines 111 to 114
IF (EMBREE_STATIC_LIB)
SET(EMBREE_LIB_TYPE STATIC)
ADD_DEFINITIONS(-DEMBREE_STATIC_LIB)
TARGET_COMPILE_DEFINITIONS(embree_config INTERFACE -DEMBREE_STATIC_LIB)
ELSE()
Comment thread CMakeLists.txt
Comment on lines 182 to 187
IF (EMBREE_TASKING_SYSTEM STREQUAL "TBB")
SET(TASKING_TBB ON )
SET(TASKING_INTERNAL OFF)
SET(TASKING_PPL OFF )
ADD_DEFINITIONS(-DTASKING_TBB)
TARGET_COMPILE_DEFINITIONS(embree_config INTERFACE -DTASKING_TBB)
LIST(APPEND ISPC_DEFINITIONS -DTASKING_TBB)
Comment thread CMakeLists.txt
Comment on lines 188 to 193
ELSEIF (EMBREE_TASKING_SYSTEM STREQUAL "PPL")
SET(TASKING_PPL ON )
SET(TASKING_TBB OFF )
SET(TASKING_INTERNAL OFF)
ADD_DEFINITIONS(-DTASKING_PPL)
TARGET_COMPILE_DEFINITIONS(embree_config INTERFACE -DTASKING_PPL)
LIST(APPEND ISPC_DEFINITIONS -DTASKING_PPL)
Comment thread CMakeLists.txt
Comment on lines 194 to 199
ELSE()
SET(TASKING_INTERNAL ON )
SET(TASKING_TBB OFF)
SET(TASKING_PPL OFF )
ADD_DEFINITIONS(-DTASKING_INTERNAL)
TARGET_COMPILE_DEFINITIONS(embree_config INTERFACE -DTASKING_INTERNAL)
LIST(APPEND ISPC_DEFINITIONS -DTASKING_INTERNAL)
Comment thread CMakeLists.txt
Comment on lines 485 to 487
IF (EMBREE_ISA_SSE2)
ADD_DEFINITIONS(-DEMBREE_TARGET_SSE2)
TARGET_COMPILE_DEFINITIONS(embree_config INTERFACE -DEMBREE_TARGET_SSE2)
IF (NOT EMBREE_ARM)
Comment thread CMakeLists.txt
Comment on lines 519 to 521
IF (EMBREE_ISA_AVX2)
ADD_DEFINITIONS(-DEMBREE_TARGET_AVX2)
TARGET_COMPILE_DEFINITIONS(embree_config INTERFACE -DEMBREE_TARGET_AVX2)
IF (NOT EMBREE_ARM)
Comment thread CMakeLists.txt
Comment on lines 531 to 533
IF (EMBREE_ISA_AVX512)
ADD_DEFINITIONS(-DEMBREE_TARGET_AVX512)
TARGET_COMPILE_DEFINITIONS(embree_config INTERFACE -DEMBREE_TARGET_AVX512)
IF (NOT EMBREE_ARM)
Comment thread kernels/CMakeLists.txt
Comment on lines 4 to 6
IF (EMBREE_CONFIG)
ADD_DEFINITIONS(-DEMBREE_CONFIG="${EMBREE_CONFIG}")
TARGET_COMPILE_DEFINITIONS(embree_config INTERFACE -DEMBREE_CONFIG="${EMBREE_CONFIG}")
ENDIF()
Comment on lines +17 to 21
TARGET_LINK_LIBRARIES(tasking PUBLIC embree::config)

if (TARGET TBB::${EMBREE_TBB_COMPONENT})
message("-- TBB: reuse existing TBB::${TBB_COMPONENT} target")
TARGET_LINK_LIBRARIES(tasking PUBLIC TBB::${EMBREE_TBB_COMPONENT})
Comment thread common/sys/CMakeLists.txt
Comment on lines 21 to 24
SET_PROPERTY(TARGET sys APPEND PROPERTY COMPILE_FLAGS " ${FLAGS_LOWEST}")

TARGET_LINK_LIBRARIES(sys ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
TARGET_LINK_LIBRARIES(sys embree::config ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants