Skip to content

Commit

Permalink
CMake cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Jun 6, 2024
1 parent 5a081c6 commit eaf65a9
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 98 deletions.
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,21 @@ include_directories(
${OSGEARTH_SOURCE_DIR}/src
${OPENSCENEGRAPH_INCLUDE_DIR})

# Dynamic vs Static Linking.
# The utilities in osgearth-macros will use this value.

# Shared v. static build .................................................

option(OSGEARTH_BUILD_SHARED_LIBS "ON to build shared libraries; OFF to build static libraries." ON)
if(OSGEARTH_BUILD_SHARED_LIBS)
set(OSGEARTH_DYNAMIC_OR_STATIC "SHARED")
else()
set(OSGEARTH_DYNAMIC_OR_STATIC "STATIC")
endif()

message(STATUS "Building ${OSGEARTH_DYNAMIC_OR_STATIC} libraries")

# Whether to append SOVERSIONs to libraries (unix)
option(OSGEARTH_SONAMES "ON to append so-version numbers to libraries" ON)


# Source code ............................................................

add_subdirectory(src)
Expand Down
60 changes: 40 additions & 20 deletions cmake/FindCesiumNative.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#
# FindCesiumNative.cmake
#
# Inputs:
# CESIUM_NATIVE_DIR : folder containing include/ and lib/ for Cesium Native
# (or "CESIUM_NATIVE_DIR" environment variable)
#
# Outputs:
# CESIUM_NATIVE_FOUND (boolean variable)
# OE::CESIUM_NATIVE (imported link library)
#
# Usage:
# find_package(CesiumNative)
# ...
# target_link_libraries(TARGET my_target PRIVATE OE::CESIUM_NATIVE)
#
set(CESIUM_NATIVE_DIR "" CACHE PATH "Root directory of cesium-native distribution")

set(CESIUM_NATIVE_FOUND FALSE)
Expand Down Expand Up @@ -46,6 +62,7 @@ macro(find_cesium_library MY_LIBRARY_VAR MY_LIBRARY_NAME)

# create the import library for this component:
add_library(${MY_IMPORT_LIBRARY_NAME} UNKNOWN IMPORTED)

set_target_properties(${MY_IMPORT_LIBRARY_NAME} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CESIUM_NATIVE_INCLUDE_DIR}"
IMPORTED_LOCATION ${MY_RELEASE_LIBRARY}
Expand All @@ -54,52 +71,55 @@ macro(find_cesium_library MY_LIBRARY_VAR MY_LIBRARY_NAME)
# finally, add it to the main list for later.
list(APPEND CESIUM_NATIVE_IMPORT_LIBRARIES "${MY_IMPORT_LIBRARY_NAME}")
else()
message(STATUS "Cesium Native: Could not find ${MY_LIBRARY_NAME}...")
message(NOTICE "Cesium Native: Could not find ${MY_LIBRARY_NAME} ... ")
set(CESIUM_LIBRARY_MISSING TRUE)
endif()
endif()
endmacro()

# Note, it's not strictly necessary to set all these cache variables,
# but it's nice to be able to see them in cmake-gui. -gw
find_cesium_library(CESIUM_NATIVE_ASYNC++ async++)
find_cesium_library(CESIUM_NATIVE_3DTILES Cesium3DTiles)
find_cesium_library(CESIUM_NATIVE_3DTILES_SELECTION Cesium3DTilesSelection)
find_cesium_library(CESIUM_NATIVE_GEOSPATIAL CesiumGeospatial)
find_cesium_library(CESIUM_NATIVE_UTILITY CesiumUtility)
find_cesium_library(CESIUM_NATIVE_ION_CLIENT CesiumIonClient)
find_cesium_library(CESIUM_NATIVE_GLTF_READER CesiumGltfReader)
find_cesium_library(CESIUM_NATIVE_3DTILES_READER Cesium3DTilesReader)
find_cesium_library(CESIUM_NATIVE_3DTILES_SELECTION Cesium3DTilesSelection)
find_cesium_library(CESIUM_NATIVE_ASYNC CesiumAsync)
find_cesium_library(CESIUM_NATIVE_GEOMETRY CesiumGeometry)
find_cesium_library(CESIUM_NATIVE_GEOSPATIAL CesiumGeospatial)
find_cesium_library(CESIUM_NATIVE_GLTF CesiumGltf)
find_cesium_library(CESIUM_NATIVE_KTX_READ ktx_read)
find_cesium_library(CESIUM_NATIVE_DRACO draco)
find_cesium_library(CESIUM_NATIVE_SPDLOG spdlog)
find_cesium_library(CESIUM_NATIVE_ASYNC++ async++)
find_cesium_library(CESIUM_NATIVE_WEBPDECODER webpdecoder)
find_cesium_library(CESIUM_NATIVE_MESHOPTIMIZER meshoptimizer)
find_cesium_library(CESIUM_NATIVE_URIPARSER uriparser)
find_cesium_library(CESIUM_NATIVE_TURBOJPEG turbojpeg)
find_cesium_library(CESIUM_NATIVE_CSPRNG csprng)
find_cesium_library(CESIUM_NATIVE_MODPB64 modp_b64)
find_cesium_library(CESIUM_NATIVE_GLTF_READER CesiumGltfReader)
find_cesium_library(CESIUM_NATIVE_ION_CLIENT CesiumIonClient)
find_cesium_library(CESIUM_NATIVE_JSONREADER CesiumJsonReader)
find_cesium_library(CESIUM_NATIVE_ASYNC CesiumAsync)
find_cesium_library(CESIUM_NATIVE_S2GEOMETRY s2geometry)
find_cesium_library(CESIUM_NATIVE_UTILITY CesiumUtility)

find_cesium_library(CESIUM_NATIVE_RASTER_OVERLAYS CesiumRasterOverlays)
find_cesium_library(CESIUM_NATIVE_3DTILES_CONTENT Cesium3DTilesContent)
find_cesium_library(CESIUM_NATIVE_GLTF_CONTENT CesiumGltfContent)

find_cesium_library(CESIUM_NATIVE_CSPRNG csprng)
find_cesium_library(CESIUM_NATIVE_DRACO draco)
find_cesium_library(CESIUM_NATIVE_KTX_READ ktx_read)
find_cesium_library(CESIUM_NATIVE_MODPB64 modp_b64)
find_cesium_library(CESIUM_NATIVE_S2GEOMETRY s2geometry)
find_cesium_library(CESIUM_NATIVE_SPDLOG spdlog)
find_cesium_library(CESIUM_NATIVE_TINYXML2 tinyxml2)
find_cesium_library(CESIUM_NATIVE_TURBOJPEG turbojpeg)
find_cesium_library(CESIUM_NATIVE_URIPARSER uriparser)
find_cesium_library(CESIUM_NATIVE_WEBPDECODER webpdecoder)
find_cesium_library(CESIUM_NATIVE_MESHOPTIMIZER meshoptimizer)



if(NOT CESIUM_LIBRARY_MISSING)
set(CESIUM_NATIVE_FOUND TRUE)

# Assemble all the CN components into one single import library:
# Assemble all the component libraries into one single import library:
# https://stackoverflow.com/a/48397346/4218920

add_library(OE::CESIUM_NATIVE INTERFACE IMPORTED)

set_property(TARGET OE::CESIUM_NATIVE PROPERTY
INTERFACE_LINK_LIBRARIES ${CESIUM_NATIVE_IMPORT_LIBRARIES} )
else()
message(FATAL_ERROR "Failed to find all Cesium Native libraries. Did you set CESIUM_NATIVE_DIR?")
message(WARN "Failed to find all Cesium Native libraries. Check CESIUM_NATIVE_DIR.")
endif()
26 changes: 4 additions & 22 deletions docs/source/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,8 @@
## Installation
The easiest way to install and use osgEarth is with the `vcpkg` package manager. There are two ways to go about it. But first...

### Update the OpenSceneGraph vcpkg build
OsgEarth depends on the OpenSceneGraph (OSG) SDK. OSG is available through vcpkg, but the confiruation is for OpenGL 2 and osgEarth needs to use OpenGL 3. So we need to make a simple change.

In the folder where you installed `vcpkg`, find the file `ports/osg/portfile.cmake`, and locate this block:
```
if(NOT DEFINED osg_OPENGL_PROFILE)
set(osg_OPENGL_PROFILE "GL2")
endif()
```
Set the `osg_OPENGL_PROFILE` variable to `GL3`. You are now good to go.

### Method 1: Do it manually
You can install osgEarth manually using this command:
You can install osgEarth on Windows manually using this command:
```
vcpkg install osgearth:x64-windows
```
Expand All @@ -41,7 +30,7 @@ Next you need to bootstrap CMake to use the vcpkg toolchain, using a command lik
cmake ^
-S %SOURCE_DIR% ^
-B %BUILD_DIR% ^
-G "Visual Studio 16 2019" ^
-G "Visual Studio 17 2022" ^
-A x64 ^
-DCMAKE_BUILD_TYPE=RelWithDebInfo ^
-DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% ^
Expand All @@ -60,22 +49,15 @@ cmake <build_dir>

## Sample CMakeLists.txt
```cmake
cmake_minimum_required(VERSION 3.7)
project(
myApp
VERSION 0.1.0
LANGUAGES CXX C
)
cmake_minimum_required(VERSION 3.20)
find_package(OpenSceneGraph REQUIRED COMPONENTS osg osgDB osgGA osgUtil osgViewer)
project(myApp)
find_package(osgEarth CONFIG REQUIRED)
add_executable(myApp main.cpp)
target_link_libraries(myApp PRIVATE osgEarth)
target_link_libraries(myApp PRIVATE ${OPENSCENEGRAPH_LIBRARIES})
install(TARGETS myApp RUNTIME DESTINATION bin)
```
Expand Down
2 changes: 0 additions & 2 deletions src/osgEarth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,6 @@ if(OSGEARTH_ENABLE_GEOCODER)
list(APPEND TARGET_SRC Geocoder.cpp)
endif()

message(STATUS "Building ${LIB_NAME} as a ${OSGEARTH_DYNAMIC_OR_STATIC} library")

# Declare the dynamic headers -- we'll generate them later when all the HAVE vars are set.
set(OSGEARTH_VERSION_HEADER "${OSGEARTH_BUILDTIME_INCLUDE_DIR}/osgEarth/Version")
set(OSGEARTH_BUILDCONFIG_HEADER "${OSGEARTH_BUILDTIME_INCLUDE_DIR}/osgEarth/BuildConfig")
Expand Down
105 changes: 54 additions & 51 deletions src/osgEarthCesium/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
find_package(CesiumNative REQUIRED)
find_package(CesiumNative)

set(LIB_NAME osgEarthCesium)
if (CESIUM_NATIVE_FOUND)

set(OSGEARTH_HAVE_CESIUM_NODEKIT ON PARENT_SCOPE) # for BuildConfig
message(STATUS "Found Cesium Native")

if(OSGEARTH_BUILD_SHARED_LIBS)
add_definitions(-DOSGEARTHCESIUM_LIBRARY)
else()
add_definitions(-DOSGEARTHCESIUM_LIBRARY_STATIC)
endif()
set(LIB_NAME osgEarthCesium)

# Add definitions for linking against async++ and spdlog. Found in the cesium-omniverse project.
add_definitions(-DSPDLOG_COMPILED_LIB -DLIBASYNC_STATIC -DGLM_FORCE_XYZW_ONLY -DGLM_FORCE_EXPLICIT_CTOR -DGLM_FORCE_SIZE_T_LENGTH)

set(TARGET_SRC
AssetAccessor.cpp
CesiumIon.cpp
CesiumCreditsNode.cpp
CesiumTilesetNode.cpp
CesiumLayer.cpp
Context.cpp
PrepareRenderResources.cpp
Settings.cpp
TaskProcessor.cpp)

set(TARGET_H
CesiumTilesetNode
CesiumCreditsNode
CesiumLayer
CesiumIon
Context
Export
Settings
AssetAccessor
PrepareRenderResources
TaskProcessor)

# ImGui headers:
if(OSGEARTH_HAVE_IMGUI)
set(TARGET_H_IMGUI ImGui/CesiumIonGUI)
endif()
set(OSGEARTH_HAVE_CESIUM_NODEKIT ON PARENT_SCOPE) # for BuildConfig

if(OSGEARTH_BUILD_SHARED_LIBS)
add_definitions(-DOSGEARTHCESIUM_LIBRARY)
else()
add_definitions(-DOSGEARTHCESIUM_LIBRARY_STATIC)
endif()

set(CMAKE_CXX_STANDARD 17)
# Add definitions for linking against async++ and spdlog. Found in the cesium-omniverse project.
add_definitions(-DSPDLOG_COMPILED_LIB -DLIBASYNC_STATIC -DGLM_FORCE_XYZW_ONLY -DGLM_FORCE_EXPLICIT_CTOR -DGLM_FORCE_SIZE_T_LENGTH)

add_osgearth_library(
TARGET ${LIB_NAME}
PUBLIC_HEADERS ${TARGET_H}
IMGUI_HEADERS ${TARGET_H_IMGUI}
SOURCES ${TARGET_SRC}
SHADERS ${TARGET_GLSL}
TEMPLATES ${TARGET_IN}
FOLDER "NodeKits")
set(TARGET_SRC
AssetAccessor.cpp
CesiumIon.cpp
CesiumCreditsNode.cpp
CesiumTilesetNode.cpp
CesiumLayer.cpp
Context.cpp
PrepareRenderResources.cpp
Settings.cpp
TaskProcessor.cpp)

set(TARGET_H
CesiumTilesetNode
CesiumCreditsNode
CesiumLayer
CesiumIon
Context
Export
Settings
AssetAccessor
PrepareRenderResources
TaskProcessor)

# Include the Cesium Native headers BEFORE anything else to ensure that dependencies that might be duplicated like spdlog are included from the Cesium Native headers.
include_directories(BEFORE ${CESIUM_NATIVE_INCLUDE_DIR})
# ImGui headers:
if(OSGEARTH_HAVE_IMGUI)
set(TARGET_H_IMGUI ImGui/CesiumIonGUI)
endif()

target_link_libraries(${LIB_NAME}
PRIVATE OE::CESIUM_NATIVE)
set(CMAKE_CXX_STANDARD 17)

add_osgearth_library(
TARGET ${LIB_NAME}
PUBLIC_HEADERS ${TARGET_H}
IMGUI_HEADERS ${TARGET_H_IMGUI}
SOURCES ${TARGET_SRC}
SHADERS ${TARGET_GLSL}
TEMPLATES ${TARGET_IN}
FOLDER "NodeKits")

# Include the Cesium Native headers BEFORE anything else to ensure that dependencies that might be duplicated like spdlog are included from the Cesium Native headers.
include_directories(BEFORE ${CESIUM_NATIVE_INCLUDE_DIR})

target_link_libraries(${LIB_NAME} PRIVATE OE::CESIUM_NATIVE)

endif()

0 comments on commit eaf65a9

Please sign in to comment.