Skip to content

Commit

Permalink
Update the CMake config generator to support all nodekits
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Aug 29, 2024
1 parent 4fadb61 commit 94eaa90
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 115 deletions.
13 changes: 1 addition & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ endif()

# Bring in our utility macros that sub-projects will use to configure themselves.
include(cmake/osgearth-macros.cmake)
include(cmake/install-package-config-files.cmake)

# Detect the OSG version so we can append it to plugin DLLs just like OSG does.
detect_osg_version()
Expand Down Expand Up @@ -188,18 +189,6 @@ add_subdirectory(src)
if(OSGEARTH_BUILD_DOCS)
add_subdirectory(docs)
endif()


# CMake Config File Creation .............................................

include(cmake/install-package-config-files.cmake)

osgearth_install_package_config_files(
osgEarth
${OSGEARTH_VERSION}
${CMAKE_INSTALL_PREFIX}/include
${CMAKE_INSTALL_PREFIX}/${INSTALL_LIBRARY_FOLDER})



# IDE configuration ......................................................
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ cmake_minimum_required(VERSION 3.20)
project(myApp)
find_package(osgEarth CONFIG REQUIRED)
add_executable(myApp main.cpp)
target_link_libraries(myApp PRIVATE osgEarth)
target_link_libraries(myApp PRIVATE osgEarth::osgEarth)
install(TARGETS myApp RUNTIME DESTINATION bin)
```
main.cpp
Expand Down
49 changes: 32 additions & 17 deletions cmake/install-package-config-files.cmake
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
function(osgearth_install_package_config_files TARGET TARGET_VERSION INCLUDE_INSTALL_DIR LIBRARY_INSTALL_DIR)
# osgearth_package_install_config_file
#
# Creates and installs the top-level LIBNAME-config.cmake file for a library
#
function(osgearth_package_install_config_files INCLUDE_INSTALL_DIR LIBRARY_INSTALL_DIR)

include(CMakePackageConfigHelpers)
set(PACKAGE_INSTALL_DIR share/osgEarth)

set(PACKAGE_INSTALL_DIR share/osgearth)
#set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR})
#set(LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
include(CMakePackageConfigHelpers)

configure_package_config_file(
"${TARGET}-config.cmake.in"
"${TARGET}-config.cmake"
"${CMAKE_SOURCE_DIR}/cmake/osgEarth-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/osgEarth-config.cmake"
INSTALL_DESTINATION ${PACKAGE_INSTALL_DIR}
PATH_VARS INCLUDE_INSTALL_DIR LIBRARY_INSTALL_DIR)

write_basic_package_version_file(
"${TARGET}-configVersion.cmake"
VERSION ${TARGET_VERSION}
"${CMAKE_CURRENT_BINARY_DIR}/osgEarth-configVersion.cmake"
VERSION ${OSGEARTH_VERSION}
COMPATIBILITY AnyNewerVersion)

install(
EXPORT ${TARGET}Targets
FILE ${TARGET}-targets.cmake
NAMESPACE ${TARGET}::
DESTINATION ${PACKAGE_INSTALL_DIR} )

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${TARGET}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${TARGET}-configVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/osgEarth-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/osgEarth-configVersion.cmake"
DESTINATION
${PACKAGE_INSTALL_DIR} )

endfunction()


# osgearth_package_install_library_target
#
# Installs the -targets.cmake file for the library "MY_TARGET".
# Each -targets.cmaks file corresond to one "component" or "nodekit" library,
# and is included from the top-level osgEarth-config.cmake file.
#
function(osgearth_package_install_library_target MY_TARGET)

set(PACKAGE_INSTALL_DIR share/osgEarth)

install(
EXPORT ${MY_TARGET}Targets
FILE ${MY_TARGET}-targets.cmake
NAMESPACE osgEarth::
DESTINATION ${PACKAGE_INSTALL_DIR} )

endfunction()
39 changes: 39 additions & 0 deletions cmake/osgEarth-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# CMake Config TEMPLATE
# Inputs:
# OSGEARTH_VERSION : osgEarth version string
# OSGEARTH_COMPONENTS : list of libraries for which to create namespaced imports
#
cmake_minimum_required(VERSION 3.10.0)

@PACKAGE_INIT@

set(osgEarth_VERSION @OSGEARTH_VERSION@)
set(OSGEARTH_VERSION @OSGEARTH_VERSION@)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()

set(osgEarth_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
set(osgEarth_SHARE_DIR "${PACKAGE_PREFIX_DIR}/share/osgEarth")
set_and_check(osgEarth_BUILD_DIR "${PACKAGE_PREFIX_DIR}")

# always depend on the public-facing OSG libraries
include(CMakeFindDependencyMacro)
find_dependency(OpenSceneGraph REQUIRED COMPONENTS osg osgDB osgGA osgUtil osgViewer OpenThreads)

# must foreably include the OSG include root
include_directories(${OPENSCENEGRAPH_INCLUDE_DIR})

# include the target for each library in OSGEARTH_COMPONENTS:
foreach(MY_COMPONENT @OSGEARTH_COMPONENTS@)
if(NOT TARGET osgEarth::${MY_COMPONENT})
include("${CMAKE_CURRENT_LIST_DIR}/${MY_COMPONENT}-targets.cmake")
endif()
endforeach()

set(osgEarth_FOUND TRUE)
set(OSGEARTH_FOUND TRUE)
12 changes: 9 additions & 3 deletions cmake/osgearth-macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,22 @@ macro(add_osgearth_library)
RUNTIME DESTINATION ${INSTALL_RUNTIME_FOLDER}
LIBRARY DESTINATION ${INSTALL_LIBRARY_FOLDER}
ARCHIVE DESTINATION ${INSTALL_ARCHIVE_FOLDER}
INCLUDES DESTINATION include # ${CMAKE_INSTALL_INCLUDEDIR}
)

# deploy the shaders for this library, if requested.
if(OSGEARTH_INSTALL_SHADERS)
install(
FILES ${MY_SHADERS}
DESTINATION resources/shaders )
DESTINATION share/osgEarth/shaders )
endif()

# on Windows, install pdb files
# https://stackoverflow.com/a/40860436/4218920
if(OSGEARTH_INSTALL_PDBS)
install(FILES $<TARGET_PDB_FILE:${MY_TARGET}> DESTINATION ${INSTALL_LIBRARY_FOLDER} OPTIONAL)
install(
FILES $<TARGET_PDB_FILE:${MY_TARGET}>
DESTINATION ${INSTALL_LIBRARY_FOLDER} OPTIONAL)
endif()


Expand All @@ -264,11 +267,14 @@ macro(add_osgearth_library)
INSTALL_NAME_DIR "${OSGEARTH_BUILD_FRAMEWORKS_INSTALL_NAME_DIR}"
)
endif()

# generate and install a packaging target for this library:
osgearth_package_install_library_target(${MY_TARGET})

# IDE location:
if (MY_FOLDER)
set_property(TARGET ${MY_TARGET} PROPERTY FOLDER "${MY_FOLDER}")
endif()
endif()

endmacro()

Expand Down
80 changes: 0 additions & 80 deletions osgEarth-config.cmake.in

This file was deleted.

18 changes: 17 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@

# A list to collect all libraries for packaging:
set(OSGEARTH_COMPONENTS)
list(APPEND OSGEARTH_COMPONENTS osgEarth)

if(OSGEARTH_BUILD_IMGUI_NODEKIT)
add_subdirectory(osgEarthImGui)
list(APPEND OSGEARTH_COMPONENTS osgEarthImGui)
endif()

if(OSGEARTH_BUILD_PROCEDURAL_NODEKIT)
add_subdirectory(osgEarthProcedural)
list(APPEND OSGEARTH_COMPONENTS osgEarthProcedural)
endif()

if(OSGEARTH_BUILD_CESIUM_NODEKIT)
add_subdirectory(osgEarthCesium)
list(APPEND OSGEARTH_COMPONENTS osgEarthCesium)
endif()

if(OSGEARTH_BUILD_TRITON_NODEKIT)
add_subdirectory(osgEarthTriton)
list(APPEND OSGEARTH_COMPONENTS osgEarthTriton)
endif()

if(OSGEARTH_BUILD_SILVERLINING_NODEKIT)
add_subdirectory(osgEarthSilverLining)
list(APPEND OSGEARTH_COMPONENTS osgEarthSilverLining)
endif()

if(OSGEARTH_BUILD_LEGACY_SPLAT_NODEKIT)
add_subdirectory(osgEarthSplat)
list(APPEND OSGEARTH_COMPONENTS osgEarthSplat)
endif()

# plugins:
Expand All @@ -38,5 +48,11 @@ endif()
# Do this LAST since we are generating the BuildConfig header
# based on everything that's happened so far
add_subdirectory(osgEarth)

set_property(TARGET osgEarth PROPERTY FOLDER "Core")

# Finally, generate and install the packaging config file (osgEarth-config.cmake)
osgearth_package_install_config_files(
osgEarth
${OSGEARTH_VERSION}
${CMAKE_INSTALL_PREFIX}/include
${CMAKE_INSTALL_PREFIX}/${INSTALL_LIBRARY_FOLDER})
2 changes: 1 addition & 1 deletion src/osgEarthImGui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ add_osgearth_library(
TARGET ${LIB_NAME}
SOURCES ${LIB_SOURCES} ${IMGUI_SOURCES}
PUBLIC_HEADERS ${LIB_HEADERS} ${IMGUI_HEADERS} ${STOCK_PANELS}
LIBRARIES PUBLIC GLEW::GLEW OpenGL::GL
LIBRARIES PRIVATE GLEW::GLEW OpenGL::GL

This comment has been minimized.

Copy link
@remoe

remoe Aug 30, 2024

Contributor

Switched here to private, so external application doesn't need GLEW includes for osgEarthImGui.
But in osgEarthImGui/Common it has:

#ifndef IMGUI_VERSION
#include <GL/glew.h>
#include <osgEarthImGui/imgui.h>
#endif

Error:

osgEarthImGui/Common(18,10): fatal error C1083: Cannot open include file: 'GL/glew.h': No such file or directory

Then, one need to remove #include <GL/glew.h> right? But this doesn't compile :)

osgEarthImGui\ImGuiEventHandler.cpp(59,13): error C3861: 'glewInit': identifier not found
osgEarthImGui\ImGuiEventHandler.cpp(59,27): error C2065: 'GLEW_OK': undeclared identifier

or

the application osgearth_imgui need GLEW as dependency ?

This comment has been minimized.

Copy link
@emminizer

emminizer Aug 30, 2024

Contributor

Seconded with remoe. Either GL/glew.h needs to be removed from headers, or GLEW needs to stay as a public dependency of this. Getting build failures on our nightly probably in the same spot as remoe.

This comment has been minimized.

Copy link
@gwaldron

gwaldron Aug 30, 2024

Author Owner

Yall are right. I tested the external build but missed this detail. Let me see what can be done if anything.

This comment has been minimized.

Copy link
@gwaldron

gwaldron Aug 30, 2024

Author Owner

I pushed a fix for this; please report back.

By the way, if you DO use osgEarthImGui, it's important to include its header first (before other OSG or osgEarth stuff) since GLEW itself needs to be included before osg/GL. Later I'll look for a way to enforce this at compile time.

This comment has been minimized.

Copy link
@emminizer

emminizer Aug 30, 2024

Contributor

Yes, noted about include order. The fix works great for me, just finished all of our builds. Thanks for the quick fix.

FOLDER "NodeKits")

0 comments on commit 94eaa90

Please sign in to comment.