From 339a9f5e1347976d69e369e4ec99e8e59d321acc Mon Sep 17 00:00:00 2001 From: Mengna Li <95600143+Adela0814@users.noreply.github.com> Date: Thu, 30 Jun 2022 06:48:26 +0800 Subject: [PATCH] [nanogui] add glad support (#25169) * add glad support * use Glad in windows * Fix glad linkage issue * update * add license * format * update license --- ports/nanogui/fix-glad-dependence.patch | 101 ++++++++++++++++++++++++ ports/nanogui/portfile.cmake | 26 ++++-- ports/nanogui/vcpkg.json | 17 +++- versions/baseline.json | 2 +- versions/n-/nanogui.json | 5 ++ 5 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 ports/nanogui/fix-glad-dependence.patch diff --git a/ports/nanogui/fix-glad-dependence.patch b/ports/nanogui/fix-glad-dependence.patch new file mode 100644 index 0000000000..03a3475ccd --- /dev/null +++ b/ports/nanogui/fix-glad-dependence.patch @@ -0,0 +1,101 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 3fe6f5d..22dc16f 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -87,7 +87,7 @@ endif() + + # Shared library mode: add dllimport/dllexport flags to all symbols + if (NANOGUI_BUILD_SHARED) +- list(APPEND NANOGUI_EXTRA_DEFS -DNANOGUI_SHARED -DNVG_SHARED -DGLAD_GLAPI_EXPORT) ++ list(APPEND NANOGUI_EXTRA_DEFS -DNANOGUI_SHARED -DNVG_SHARED) + endif() + + if (MSVC) +@@ -196,21 +196,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + endif() + endif() + +-if (NANOGUI_USE_GLAD) +- # Build and include GLAD on Windows +- list(APPEND LIBNANOGUI_EXTRA_SOURCE +- "${CMAKE_CURRENT_SOURCE_DIR}/ext/glad/src/glad.c" +- "${CMAKE_CURRENT_SOURCE_DIR}/ext/glad/include/glad/glad.h" +- "${CMAKE_CURRENT_SOURCE_DIR}/ext/glad/include/KHR/khrplatform.h") +- if (MSVC) +- set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/ext/glad/src/glad.c" +- PROPERTIES COMPILE_FLAGS "/wd4055 ") +- endif() +- include_directories(ext/glad/include) +- list(APPEND NANOGUI_EXTRA_DEFS -DNANOGUI_GLAD) +- list(APPEND NANOGUI_EXTRA_INCS "${CMAKE_CURRENT_SOURCE_DIR}/ext/glad/include") +-endif() +- + list(APPEND NANOGUI_EXTRA_INCS + "${CMAKE_CURRENT_SOURCE_DIR}/ext/glfw/include" + "${CMAKE_CURRENT_SOURCE_DIR}/ext/nanovg/src" +@@ -299,8 +284,6 @@ if (APPLE) + add_compile_options(-fobjc-arc) + endif() + +-add_definitions(${NANOGUI_EXTRA_DEFS}) +- + # Compile main NanoGUI library + add_library(nanogui-obj OBJECT + # Merge NanoVG into the NanoGUI library +@@ -373,6 +356,14 @@ find_package(Eigen3 CONFIG REQUIRED) + find_package(glfw3 CONFIG REQUIRED) + target_link_libraries(nanogui glfw nanovg::nanovg Eigen3::Eigen) + ++if (NANOGUI_USE_GLAD) ++ find_package(glad CONFIG REQUIRED) ++ target_link_libraries(nanogui glad::glad) ++ list(APPEND NANOGUI_EXTRA_DEFS -DNANOGUI_GLAD) ++endif() ++ ++add_definitions(${NANOGUI_EXTRA_DEFS}) ++ + if (NANOGUI_BUILD_SHARED) + set_property(TARGET nanogui-obj PROPERTY POSITION_INDEPENDENT_CODE ON) + endif() +@@ -380,11 +371,6 @@ endif() + # Compile/link flags for NanoGUI + set_property(TARGET nanogui-obj APPEND PROPERTY COMPILE_DEFINITIONS "NANOGUI_BUILD;NVG_BUILD") + +-if (NANOGUI_USE_GLAD AND NANOGUI_BUILD_SHARED) +- set_property(TARGET nanogui-obj APPEND PROPERTY COMPILE_DEFINITIONS +- "GLAD_GLAPI_EXPORT;GLAD_GLAPI_EXPORT_BUILD") +-endif() +- + if (NANOGUI_BUILD_SHARED) + target_link_libraries(nanogui ${NANOGUI_EXTRA_LIBS}) + endif() +diff --git a/include/nanogui/opengl.h b/include/nanogui/opengl.h +index f5abcb2..1c20653 100644 +--- a/include/nanogui/opengl.h ++++ b/include/nanogui/opengl.h +@@ -17,10 +17,6 @@ + + #ifndef DOXYGEN_SHOULD_SKIP_THIS + #if defined(NANOGUI_GLAD) +- #if defined(NANOGUI_SHARED) && !defined(GLAD_GLAPI_EXPORT) +- #define GLAD_GLAPI_EXPORT +- #endif +- + #include + #else + #if defined(__APPLE__) +diff --git a/src/example3.cpp b/src/example3.cpp +index 3d2ecfa..72deaa8 100644 +--- a/src/example3.cpp ++++ b/src/example3.cpp +@@ -14,10 +14,6 @@ + // GLFW + // + #if defined(NANOGUI_GLAD) +- #if defined(NANOGUI_SHARED) && !defined(GLAD_GLAPI_EXPORT) +- #define GLAD_GLAPI_EXPORT +- #endif +- + #include + #else + #if defined(__APPLE__) diff --git a/ports/nanogui/portfile.cmake b/ports/nanogui/portfile.cmake index 937c2c0a00..390f54bd45 100644 --- a/ports/nanogui/portfile.cmake +++ b/ports/nanogui/portfile.cmake @@ -1,3 +1,10 @@ +if (VCPKG_HOST_IS_WINDOWS) + set(USE_GLAD -DNANOGUI_USE_GLAD=ON) + vcpkg_check_linkage(ONLY_STATIC_LIBRARY) +else() + set(USE_GLAD -DNANOGUI_USE_GLAD=OFF) +endif() + vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO wjakob/nanogui @@ -6,18 +13,25 @@ vcpkg_from_github( HEAD_REF master PATCHES fix-cmakelists.patch + fix-glad-dependence.patch ) -vcpkg_configure_cmake( - SOURCE_PATH ${SOURCE_PATH} - OPTIONS +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS +FEATURES + "example" NANOGUI_BUILD_EXAMPLE +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS ${FEATURE_OPTIONS} -DNANOGUI_EIGEN_INCLUDE_DIR=${CURRENT_INSTALLED_DIR}/include/eigen3 -DEIGEN_INCLUDE_DIR=${CURRENT_INSTALLED_DIR}/include/eigen3 + ${USE_GLAD} ) -vcpkg_install_cmake() +vcpkg_cmake_install() vcpkg_copy_pdbs() -file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") # Handle copyright -file(INSTALL ${SOURCE_PATH}/LICENSE.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) +file(INSTALL "${SOURCE_PATH}/LICENSE.txt" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) diff --git a/ports/nanogui/vcpkg.json b/ports/nanogui/vcpkg.json index f075b3dc6a..a53f09f69b 100644 --- a/ports/nanogui/vcpkg.json +++ b/ports/nanogui/vcpkg.json @@ -1,13 +1,24 @@ { "name": "nanogui", "version-date": "2019-09-23", - "port-version": 3, + "port-version": 4, "description": "NanoGUI is a minimalistic cross-platform widget library for OpenGL 3.x or higher.", "homepage": "https://github.com/wjakob/nanogui", + "license": "BSD-3-Clause", "supports": "!uwp", "dependencies": [ "eigen3", + "glad", "glfw3", - "nanovg" - ] + "nanovg", + { + "name": "vcpkg-cmake", + "host": true + } + ], + "features": { + "example": { + "description": "Build NanoGUI example application" + } + } } diff --git a/versions/baseline.json b/versions/baseline.json index 1801b90d03..eff4c418ae 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -4798,7 +4798,7 @@ }, "nanogui": { "baseline": "2019-09-23", - "port-version": 3 + "port-version": 4 }, "nanomsg": { "baseline": "1.1.5", diff --git a/versions/n-/nanogui.json b/versions/n-/nanogui.json index 25cc3e33a7..332617a169 100644 --- a/versions/n-/nanogui.json +++ b/versions/n-/nanogui.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "7b0c7f8295a21f967bfd880956f6d51b98d26874", + "version-date": "2019-09-23", + "port-version": 4 + }, { "git-tree": "55a7f3e088fe04ac01f7693c0685770ba865e6ae", "version-date": "2019-09-23",