Skip to content

Commit c315736

Browse files
svenevswjakob
authored andcommitted
fix XCode build (#304)
- Revives original solution proposed in #220 - Adds exclusion of GLFW library, XCode fails to link this
1 parent bfd6c33 commit c315736

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

CMakeLists.txt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,30 @@ add_library(nanogui-obj OBJECT
381381
include/nanogui/nanogui.h
382382
)
383383

384-
add_library(nanogui ${NANOGUI_LIBRARY_TYPE}
385-
$<TARGET_OBJECTS:nanogui-obj>
386-
$<TARGET_OBJECTS:glfw_objects>
387-
)
384+
# XCode has a serious bug where the XCode project produces an invalid target
385+
# that will not get linked if it consists only of objects from object libraries,
386+
# it will not generate any products (executables, libraries). The only work
387+
# around is to add a dummy source file to the library definition. This is an
388+
# XCode, not a CMake bug. See: https://itk.org/Bug/view.php?id=14044
389+
if (CMAKE_GENERATOR STREQUAL Xcode)
390+
set(XCODE_DUMMY ${CMAKE_CURRENT_BINARY_DIR}/xcode_dummy.cpp)
391+
file(WRITE ${XCODE_DUMMY} "")
392+
add_library(nanogui ${NANOGUI_LIBRARY_TYPE}
393+
${XCODE_DUMMY}
394+
$<TARGET_OBJECTS:nanogui-obj>
395+
$<TARGET_OBJECTS:glfw_objects>
396+
)
397+
398+
# XCode also fails at linking GLFW, so we exclude it. Note that the actual
399+
# component we need to build is 'glfw_objects', which is merged into the
400+
# NanoGUI library itself.
401+
set_target_properties(glfw PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
402+
else()
403+
add_library(nanogui ${NANOGUI_LIBRARY_TYPE}
404+
$<TARGET_OBJECTS:nanogui-obj>
405+
$<TARGET_OBJECTS:glfw_objects>
406+
)
407+
endif()
388408

389409
if (NANOGUI_BUILD_SHARED)
390410
set_property(TARGET nanogui-obj PROPERTY POSITION_INDEPENDENT_CODE ON)

0 commit comments

Comments
 (0)