From 62bdcca689b75fab042204be876289144c581999 Mon Sep 17 00:00:00 2001 From: yanzixiang Date: Fri, 18 Apr 2025 10:33:37 +0800 Subject: [PATCH 1/5] export target osg-qt::osgQOpenGL to cmake --- CMakeLists.txt | 34 +++++++++++++++++++++++++++++++++- osgQOpenGLConfig.cmake.in | 2 ++ usage | 4 ++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 osgQOpenGLConfig.cmake.in create mode 100644 usage diff --git a/CMakeLists.txt b/CMakeLists.txt index 66e989a..640ce99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE) set_property(GLOBAL PROPERTY USE_FOLDERS ON) -CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0 FATAL_ERROR) +CMAKE_MINIMUM_REQUIRED(VERSION 3.15 FATAL_ERROR) IF(APPLE) # Get OSX version in MAJOR.MINOR format @@ -926,3 +926,35 @@ ADD_CUSTOM_TARGET(uninstall # +add_library(osg-qt ALIAS osgQOpenGL) +add_library(osgqt ALIAS osgQOpenGL) + +install(TARGETS osgQOpenGL + EXPORT osgQOpenGL-targets +) + +install(EXPORT osgQOpenGL-targets + FILE osg-qtTargets.cmake + NAMESPACE osg-qt:: + DESTINATION "share/cmake/osg-qt" +) + +include(CMakePackageConfigHelpers) # 引入模块 [3,5](@ref) + +configure_package_config_file( + "osgQOpenGLConfig.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/osg-qtConfig.cmake" + INSTALL_DESTINATION "share/cmake/osg-qt" +) + +write_basic_package_version_file( + "osg-qtConfigVersion.cmake" + VERSION 1.0.0 + COMPATIBILITY SameMajorVersion +) + +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/osg-qtConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/osg-qtConfigVersion.cmake" + DESTINATION "share/cmake/osg-qt" +) diff --git a/osgQOpenGLConfig.cmake.in b/osgQOpenGLConfig.cmake.in new file mode 100644 index 0000000..a855839 --- /dev/null +++ b/osgQOpenGLConfig.cmake.in @@ -0,0 +1,2 @@ +include(CMakeFindDependencyMacro) +include("${CMAKE_CURRENT_LIST_DIR}/osg-qtTargets.cmake") \ No newline at end of file diff --git a/usage b/usage new file mode 100644 index 0000000..56ed164 --- /dev/null +++ b/usage @@ -0,0 +1,4 @@ +osg-qt provides CMake targets: + + find_package(osg-qt REQUIRED) + target_link_libraries(main PRIVATE osg-qt::osgQOpenGL) \ No newline at end of file From 2afd77a983a0b61c7129073671c32ccd9ec2c25f Mon Sep 17 00:00:00 2001 From: Daniel Emminizer Date: Mon, 19 May 2025 10:13:12 -0400 Subject: [PATCH 2/5] Export Target fixes for transitive properties: Include directory now correctly set; Qt5 and OSG are now correctly searched for if needed; link libraries and include path are now set transitively based on current system's OSG libraries, improving portability of install. --- osgQOpenGLConfig.cmake.in | 24 +++++++++++++++++++++++- src/osgQOpenGL/CMakeLists.txt | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/osgQOpenGLConfig.cmake.in b/osgQOpenGLConfig.cmake.in index a855839..2b275f9 100644 --- a/osgQOpenGLConfig.cmake.in +++ b/osgQOpenGLConfig.cmake.in @@ -1,2 +1,24 @@ +if(TARGET osg-qt::osgQOpenGL) + set(_OSGQOPENGL_ALREADY_DEFINED ON) +endif() + include(CMakeFindDependencyMacro) -include("${CMAKE_CURRENT_LIST_DIR}/osg-qtTargets.cmake") \ No newline at end of file + +if(NOT TARGET Qt5::OpenGL) + find_dependency(Qt5 COMPONENTS Gui OpenGL REQUIRED) +endif() +# Instead of checking OPENSCENEGRAPH_LIBRARIES, check osgViewer and osgUtil specifically +if(NOT DEFINED OSGUTIL_LIBRARIES OR NOT DEFINED OSGVIEWER_LIBRARIES OR NOT DEFINED OPENSCENEGRAPH_INCLUDE_DIRS) + find_dependency(OpenSceneGraph COMPONENTS osgUtil osgViewer REQUIRED) +endif() + +include("${CMAKE_CURRENT_LIST_DIR}/osg-qtTargets.cmake") + +if(NOT _OSGQOPENGL_ALREADY_DEFINED) + # Replace the interface link libraries with those found by OSG, to allow this to be more easily relocatable. + # Without this, absolute paths to OSG are stored in the target, making the output library non-relocatable + # to other machines unless they have OSG in the exact same location. + set_target_properties(osg-qt::osgQOpenGL PROPERTIES INTERFACE_LINK_LIBRARIES "Qt5::Widgets;Qt5::OpenGL") + target_link_libraries(osg-qt::osgQOpenGL INTERFACE ${OPENSCENEGRAPH_LIBRARIES}) + target_include_directories(osg-qt::osgQOpenGL INTERFACE ${OPENSCENEGRAPH_INCLUDE_DIRS}) +endif() diff --git a/src/osgQOpenGL/CMakeLists.txt b/src/osgQOpenGL/CMakeLists.txt index eb7b077..21e6ce0 100644 --- a/src/osgQOpenGL/CMakeLists.txt +++ b/src/osgQOpenGL/CMakeLists.txt @@ -50,6 +50,7 @@ IF ( Qt5Widgets_FOUND ) SETUP_LIBRARY(${LIB_NAME}) + target_include_directories(${LIB_NAME} PUBLIC $) generate_export_header(${LIB_NAME} EXPORT_FILE_NAME "Export") ENDIF() From bfa769f5c928a89888d556a651f56716921e5887 Mon Sep 17 00:00:00 2001 From: Daniel Emminizer Date: Mon, 19 May 2025 11:29:23 -0400 Subject: [PATCH 3/5] CMakeLists: Use GNUInstallDirs to fix Linux duplication issue of lib64 vs lib. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 640ce99..d83e105 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,7 @@ ENDIF() PROJECT(osgQt) +INCLUDE(GNUInstallDirs) FIND_PACKAGE(OpenSceneGraph 3.6.0 REQUIRED osgDB osgGA osgUtil osgText osgViewer osgWidget) SET(OPENSCENEGRAPH_SOVERSION 145) From 9954ba6dccaf73a2a6c6323cac6f6a77829bb863 Mon Sep 17 00:00:00 2001 From: whyzix Date: Tue, 20 May 2025 16:15:23 +0800 Subject: [PATCH 4/5] Update osgQOpenGLConfig.cmake.in Co-authored-by: Kai Pastor --- osgQOpenGLConfig.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osgQOpenGLConfig.cmake.in b/osgQOpenGLConfig.cmake.in index 2b275f9..216739d 100644 --- a/osgQOpenGLConfig.cmake.in +++ b/osgQOpenGLConfig.cmake.in @@ -9,7 +9,7 @@ if(NOT TARGET Qt5::OpenGL) endif() # Instead of checking OPENSCENEGRAPH_LIBRARIES, check osgViewer and osgUtil specifically if(NOT DEFINED OSGUTIL_LIBRARIES OR NOT DEFINED OSGVIEWER_LIBRARIES OR NOT DEFINED OPENSCENEGRAPH_INCLUDE_DIRS) - find_dependency(OpenSceneGraph COMPONENTS osgUtil osgViewer REQUIRED) + find_dependency(OpenSceneGraph COMPONENTS osgUtil osgViewer) endif() include("${CMAKE_CURRENT_LIST_DIR}/osg-qtTargets.cmake") From a204392539bf518c60190c6757ea53a31a212a09 Mon Sep 17 00:00:00 2001 From: whyzix Date: Tue, 20 May 2025 16:15:47 +0800 Subject: [PATCH 5/5] Update osgQOpenGLConfig.cmake.in Co-authored-by: Kai Pastor --- osgQOpenGLConfig.cmake.in | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/osgQOpenGLConfig.cmake.in b/osgQOpenGLConfig.cmake.in index 216739d..69ca8d3 100644 --- a/osgQOpenGLConfig.cmake.in +++ b/osgQOpenGLConfig.cmake.in @@ -4,9 +4,7 @@ endif() include(CMakeFindDependencyMacro) -if(NOT TARGET Qt5::OpenGL) - find_dependency(Qt5 COMPONENTS Gui OpenGL REQUIRED) -endif() +find_dependency(Qt5 COMPONENTS Widgets OpenGL) # Instead of checking OPENSCENEGRAPH_LIBRARIES, check osgViewer and osgUtil specifically if(NOT DEFINED OSGUTIL_LIBRARIES OR NOT DEFINED OSGVIEWER_LIBRARIES OR NOT DEFINED OPENSCENEGRAPH_INCLUDE_DIRS) find_dependency(OpenSceneGraph COMPONENTS osgUtil osgViewer)