Skip to content

Commit

Permalink
Make native dialogs optional.
Browse files Browse the repository at this point in the history
If linking against big GTK+ library is undesired.
  • Loading branch information
JoelLinn committed Jun 16, 2020
1 parent 2b6e422 commit 44b43a2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
39 changes: 24 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ else()
option(MAHI_GUI_EXAMPLES "Turn ON to build mahi-gui example(s)" OFF)
endif()

option(MAHI_GUI_NATIVE_DIAGS "Turn ON to build native file dialog support" ON)

#===============================================================================
# FRONT MATTER
#===============================================================================
Expand Down Expand Up @@ -54,24 +56,26 @@ set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(3rdparty/glfw)
install(TARGETS glfw EXPORT mahi-gui-targets
install(TARGETS glfw EXPORT mahi-gui-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

# GLAD
add_subdirectory(3rdparty/glad)
install(TARGETS glad EXPORT mahi-gui-targets
install(TARGETS glad EXPORT mahi-gui-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

# NATIVE FILE DIALOG
add_subdirectory(3rdparty/nativefiledialog-extended)
install(TARGETS nfd EXPORT mahi-gui-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
if (MAHI_GUI_NATIVE_DIAGS)
add_subdirectory(3rdparty/nativefiledialog-extended)
install(TARGETS nfd EXPORT mahi-gui-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()

# IMGUI
set(IMGUI_HEADERS
Expand All @@ -80,7 +84,7 @@ set(IMGUI_HEADERS
3rdparty/imgui/imgui.h
3rdparty/imgui/imstb_rectpack.h
3rdparty/imgui/imstb_textedit.h
3rdparty/imgui/imstb_truetype.h
3rdparty/imgui/imstb_truetype.h
3rdparty/imgui/imgui_stdlib.h
)

Expand All @@ -103,7 +107,7 @@ set(IMPLOT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/implot)

# NANOVG
add_subdirectory(3rdparty/nanovg)
install(TARGETS nanovg EXPORT mahi-gui-targets
install(TARGETS nanovg EXPORT mahi-gui-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
Expand All @@ -113,7 +117,7 @@ set(NANOSVG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/nanosvg/src)

# CLIPPER
add_subdirectory(3rdparty/clipper)
install(TARGETS clipper EXPORT mahi-gui-targets
install(TARGETS clipper EXPORT mahi-gui-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
Expand All @@ -122,8 +126,8 @@ install(TARGETS clipper EXPORT mahi-gui-targets
# MAHI UTIL
#===============================================================================

include(FetchContent)
FetchContent_Declare(mahi-util GIT_REPOSITORY https://github.com/mahilab/mahi-util.git)
include(FetchContent)
FetchContent_Declare(mahi-util GIT_REPOSITORY https://github.com/mahilab/mahi-util.git)
FetchContent_MakeAvailable(mahi-util)

#===============================================================================
Expand All @@ -135,14 +139,17 @@ add_library(gui "")
add_library(mahi::gui ALIAS gui)
set_target_properties(gui PROPERTIES DEBUG_POSTFIX -d)
target_compile_features(gui PUBLIC cxx_std_17)
install(TARGETS gui EXPORT mahi-gui-targets
install(TARGETS gui EXPORT mahi-gui-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
set_target_properties(gui PROPERTIES OUTPUT_NAME "mahi-gui")

# defines
target_compile_definitions(gui PUBLIC MAHI_GUI IMGUI_IMPL_OPENGL_LOADER_GLAD)
if(MAHI_GUI_NATIVE_DIAGS)
target_compile_definitions(gui PUBLIC MAHI_NATIVE_DIAGS)
endif()

# add source files
add_subdirectory(src/Mahi/Gui)
Expand All @@ -152,7 +159,7 @@ target_sources(gui PRIVATE ${IMPLOT_SRC} ${IMPLOT_HEADERS})

# add include files
file(GLOB_RECURSE MAHI_GUI_INCLUDE "include/*.hpp" "include/*.inl" "include/*.h")
target_sources(gui PRIVATE ${MAHI_GUI_INCLUDE}) # for intellisense
target_sources(gui PRIVATE ${MAHI_GUI_INCLUDE}) # for intellisense
target_include_directories(gui
PUBLIC
$<INSTALL_INTERFACE:include>
Expand All @@ -170,7 +177,9 @@ target_link_libraries(gui PUBLIC glfw)
target_link_libraries(gui PUBLIC glad)
target_link_libraries(gui PUBLIC nanovg)
target_link_libraries(gui PUBLIC clipper)
target_link_libraries(gui PUBLIC nfd)
if(MAHI_GUI_NATIVE_DIAGS)
target_link_libraries(gui PUBLIC nfd)
endif()
if(CMAKE_SYSTEM MATCHES "Linux")
# https://techoverflow.net/2019/04/17/how-to-fix-gcc-undefined-reference-to-std-experimental-filesystem/
target_link_libraries(gui PUBLIC GL stdc++fs)
Expand Down
7 changes: 5 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ mahi_gui_example(imgui_demo)
mahi_gui_example(implot_demo)
mahi_gui_example(plots_benchmark)
mahi_gui_example(alix)
mahi_gui_example(files)
mahi_gui_example(likert)
mahi_gui_example(events)
mahi_gui_example(hidden)
Expand All @@ -26,7 +25,11 @@ mahi_gui_example(raw_glfw)
mahi_gui_example(shapes)
mahi_gui_example(transparent)

mahi_gui_example(svg)
if (MAHI_GUI_NATIVE_DIAGS)
mahi_gui_example(files)
mahi_gui_example(svg)
endif()

mahi_gui_example(nvg_fbo)
mahi_gui_example(nvg_demo)
target_sources(nvg_demo PUBLIC "${CMAKE_SOURCE_DIR}/3rdparty/nanovg/example/demo.c")
Expand Down
2 changes: 2 additions & 0 deletions include/Mahi/Gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <Mahi/Gui/Icons/IconsFontAwesome5.hpp>
#include <Mahi/Gui/Icons/IconsFontAwesome5Brands.hpp>
#include <Mahi/Gui/Macros.hpp>
#if MAHI_NATIVE_DIAGS
#include <Mahi/Gui/Native.hpp>
#endif
#include <Mahi/Gui/Rect.hpp>
#include <Mahi/Gui/Sequence.hpp>
#include <Mahi/Gui/Shape.hpp>
Expand Down
7 changes: 5 additions & 2 deletions src/Mahi/Gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ target_sources(gui
PRIVATE
Application.cpp
Color.cpp
Native.cpp
Shape.cpp
Transform.cpp
Transformable.cpp
imgui_custom.cpp
nanovg_custom.cpp
)

add_subdirectory(Fonts)
if(MAHI_GUI_NATIVE_DIAGS)
target_sources(gui PRIVATE Native.cpp)
endif()

add_subdirectory(Fonts)

0 comments on commit 44b43a2

Please sign in to comment.