Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propagate libcxx flags to CMake consumers #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,32 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

# Prefer libc++ in conjunction with Clang
set(NANOGUI_USED_LIBCXX OFF) # Used in installation logic.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+")
CHECK_CXX_COMPILER_AND_LINKER_FLAGS(HAS_LIBCPP "-stdlib=libc++" "-stdlib=libc++")
if (APPLE OR HAS_LIBCPP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -D_LIBCPP_VERSION")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++")
set(NANOGUI_USED_LIBCXX ON)
# NOTE: spaces matter for expansion in CMAKE_*_FLAGS and nanoguiConfig.cmake.in.
set(nanogui_libcxx_cxx_flags "-stdlib=libc++ -D_LIBCPP_VERSION")
set(nanogui_libcxx_link_flags "-stdlib=libc++")
message(STATUS "NanoGUI: using libc++.")
else()
CHECK_CXX_COMPILER_AND_LINKER_FLAGS(HAS_LIBCPP_AND_CPPABI "-stdlib=libc++" "-stdlib=libc++ -lc++abi")
if (HAS_LIBCPP_AND_CPPABI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -D_LIBCPP_VERSION")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
# NOTE: spaces matter for expansion in CMAKE_*_FLAGS and nanoguiConfig.cmake.in.
set(NANOGUI_USED_LIBCXX ON)
set(nanogui_libcxx_cxx_flags "-stdlib=libc++ -D_LIBCPP_VERSION")
set(nanogui_libcxx_link_flags "-stdlib=libc++ -lc++abi")
message(STATUS "NanoGUI: using libc++ and libc++abi.")
else()
message(FATAL_ERROR "When Clang is used to compile NanoGUI, libc++ must be available -- GCC's libstdc++ is not supported! (please insteall the libc++ development headers, provided e.g. by the packages 'libc++-dev' and 'libc++abi-dev' on Debian/Ubuntu).")
endif()
endif()
if (NANOGUI_USED_LIBCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${nanogui_libcxx_cxx_flags}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${nanogui_libcxx_link_flags}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${nanogui_libcxx_link_flags}")
endif()
endif()

# Compile GLFW
Expand Down
10 changes: 10 additions & 0 deletions resources/nanoguiConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ check_required_components(nanogui)

include("${CMAKE_CURRENT_LIST_DIR}/nanoguiTargets.cmake")

# If nanogui used libcxx, propagate this to consumers.
if (@NANOGUI_USED_LIBCXX@)
foreach (flag @nanogui_libcxx_cxx_flags@)
target_compile_options(nanogui INTERFACE ${flag})
endforeach()
foreach (flag @nanogui_libcxx_link_flags@)
target_link_options(nanogui INTERFACE ${flag})
endforeach()
endif()

if(NOT nanogui_FIND_QUIETLY)
message(STATUS "Found nanogui: ${nanogui_INCLUDE_DIR} (found version \"${nanogui_VERSION}\" ${nanogui_VERSION_TYPE})")
endif()
Expand Down