-
Notifications
You must be signed in to change notification settings - Fork 200
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
Tweak CMakeLists.txt with necessary OpenGL and GLFW changes to get Linux/Wayland working #135
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,9 +220,7 @@ if (NANOGUI_BUILD_GLFW) | |
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL " " FORCE) | ||
set(GLFW_BUILD_TESTS OFF CACHE BOOL " " FORCE) | ||
set(GLFW_BUILD_DOCS OFF CACHE BOOL " " FORCE) | ||
set(GLFW_BUILD_INSTALL OFF CACHE BOOL " " FORCE) | ||
set(GLFW_INSTALL OFF CACHE BOOL " " FORCE) | ||
set(GLFW_USE_CHDIR OFF CACHE BOOL " " FORCE) | ||
set(GLFW_INSTALL NANOGUI_INSTALL CACHE BOOL " " FORCE) # install GLFW if nanogui install requested | ||
set(BUILD_SHARED_LIBS ${NANOGUI_BUILD_SHARED} CACHE BOOL " " FORCE) | ||
|
||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
|
@@ -231,18 +229,11 @@ if (NANOGUI_BUILD_GLFW) | |
endif() | ||
|
||
add_subdirectory(ext/glfw) | ||
|
||
# Two targets have now been defined: `glfw_objects`, which will be merged into | ||
# NanoGUI at the end, and `glfw`. The `glfw` target is the library itself | ||
# (e.g., libglfw.so), but can be skipped as we do not need to link against it | ||
# (because we merge `glfw_objects` into NanoGUI). Skipping is required for | ||
# XCode, but preferable for all build systems (reduces build artifacts). | ||
set_target_properties(glfw PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) | ||
list(APPEND NANOGUI_LIBS glfw) | ||
|
||
mark_as_advanced( | ||
GLFW_BUILD_DOCS GLFW_BUILD_EXAMPLES GLFW_BUILD_INSTALL GLFW_BUILD_TESTS | ||
GLFW_DOCUMENT_INTERNALS GLFW_INSTALL GLFW_USE_CHDIR GLFW_USE_MENUBAR | ||
GLFW_USE_OSMESA GLFW_VULKAN_STATIC GLFW_USE_RETINA GLFW_USE_MIR | ||
GLFW_BUILD_DOCS GLFW_BUILD_EXAMPLES GLFW_BUILD_TESTS | ||
GLFW_INSTALL GLFW_USE_OSMESA GLFW_VULKAN_STATIC | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed options that GLFW no longer uses. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Been looong time since I looked under hood at NanoGUI. Why did you drop GLFW_USE_MENUBAR? I'm asking because I wonder if this precludes having a nice menu bar with NanoGUI on Wayland. If I'm off in the weeds with this question feel free to say so. I've been deep in CopperSpice and CsScintilla lately. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was removed in GLFW 3.3. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the link! |
||
BUILD_SHARED_LIBS USE_MSVC_RUNTIME_LIBRARY_DLL) | ||
endif() | ||
|
||
|
@@ -302,9 +293,10 @@ elseif (APPLE) | |
list(APPEND NANOGUI_EXTRA src/darwin.mm src/autorelease.mm) | ||
set_property(SOURCE src/autorelease.mm PROPERTY COMPILE_FLAGS -fno-objc-arc) | ||
elseif (CMAKE_SYSTEM MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "BSD") | ||
list(APPEND NANOGUI_LIBS X11 pthread) | ||
list(APPEND NANOGUI_LIBS pthread) | ||
if (NANOGUI_BACKEND STREQUAL "OpenGL") | ||
list(APPEND NANOGUI_LIBS GL) | ||
find_package(OpenGL REQUIRED COMPONENTS OpenGL) | ||
list(APPEND NANOGUI_LIBS OpenGL::OpenGL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a possibility that this will not work with non-GLVND linux systems, though I can't tell how common these systems actually are. CMake's FindOpenGL module doesn't provide clear guidance on the correct cross-platform solution here. |
||
elseif (NANOGUI_BACKEND STREQUAL "GLES 2") | ||
list(APPEND NANOGUI_LIBS GLESv2) | ||
elseif (NANOGUI_BACKEND STREQUAL "GLES 3") | ||
|
@@ -379,10 +371,6 @@ if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") | |
add_compile_options(-fobjc-arc) | ||
endif() | ||
|
||
if (NANOGUI_BUILD_GLFW) | ||
list(APPEND NANOGUI_EXTRA $<TARGET_OBJECTS:glfw_objects>) | ||
endif() | ||
|
||
# Compile main NanoGUI library | ||
add_library(nanogui ${NANOGUI_LIBRARY_TYPE} | ||
# Merge NanoVG into the NanoGUI library | ||
|
@@ -515,11 +503,6 @@ if (NANOGUI_INSTALL) | |
install(DIRECTORY ext/nanovg/src/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nanovg | ||
FILES_MATCHING PATTERN "*.h") | ||
|
||
if (NANOGUI_BUILD_GLFW) | ||
install(DIRECTORY ext/glfw/include/GLFW DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
FILES_MATCHING PATTERN "*.h") | ||
endif() | ||
|
||
if (NANOGUI_BUILD_GLAD) | ||
install(DIRECTORY ext/glad/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/glad | ||
FILES_MATCHING PATTERN "*.h") | ||
|
@@ -564,10 +547,10 @@ if (NANOGUI_BUILD_EXAMPLES) | |
add_executable(example4 src/example4.cpp) | ||
add_executable(example_icons src/example_icons.cpp) | ||
|
||
target_link_libraries(example1 nanogui) | ||
target_link_libraries(example1 nanogui glfw) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is odd as well, though without it I get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have two further questions
Thinking out loud before I've finished the first Diet Dew of the morning . . . Your target link libraries issue above is because "static" has the GLFW currently built into it while shared builds a GLFW library, parks it somewhere, then, most likely, the CMakeLists.txt doesn't add the library to the project. If you are using Ubuntu, you can test the above by simply removing that glfw addition and installing the Wayland glfw package: While I hate stack overflow, this message thread has a good explanation of adding libraries This is the path I was on with the WaylandGUI fork. Life gets a lot easier if you just use the system GLFW. There is even a .cmake to make it easy to add.
Just my 0.0002 cents |
||
target_link_libraries(example2 nanogui) | ||
target_link_libraries(example3 nanogui ${NANOGUI_LIBS}) # For OpenGL | ||
target_link_libraries(example4 nanogui) | ||
target_link_libraries(example4 nanogui glfw) | ||
target_link_libraries(example_icons nanogui) | ||
|
||
# Copy icons for example application | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is odd but I believe has the desired effect.