Skip to content

Commit

Permalink
CMAKE: support static builds with -DOSGEARTH_LIBRARY_STATIC
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Oct 11, 2024
1 parent c016748 commit c91fdb7
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 64 deletions.
18 changes: 11 additions & 7 deletions cmake/FindCesiumNative.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#
set(CESIUM_NATIVE_DIR "" CACHE PATH "Root directory of cesium-native distribution")

set(CESIUM_NATIVE_FOUND FALSE)
unset(CESIUM_NATIVE_FOUND)

# Location the cesium-native installation:
find_path(CESIUM_NATIVE_INCLUDE_DIR CesiumUtility/Uri.h
Expand All @@ -26,6 +26,8 @@ find_path(CESIUM_NATIVE_INCLUDE_DIR CesiumUtility/Uri.h
PATH_SUFFIXES
include )

set(CESIUM_ANY_LIBRARY_MISSING FALSE)

# Macro to locate each cesium library.
macro(find_cesium_library MY_LIBRARY_VAR MY_LIBRARY_NAME)

Expand All @@ -34,7 +36,7 @@ macro(find_cesium_library MY_LIBRARY_VAR MY_LIBRARY_NAME)
unset(${MY_LIBRARY_VAR}_LIBRARY_DEBUG CACHE)
unset(${MY_LIBRARY_VAR}_LIBRARY_RELEASE CACHE)

if (NOT CESIUM_LIBRARY_MISSING)
if (NOT CESIUM_ANY_LIBRARY_MISSING)
find_library(${MY_LIBRARY_VAR}_LIBRARY_DEBUG
NAMES
${MY_LIBRARY_NAME}d
Expand Down Expand Up @@ -76,8 +78,8 @@ 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(NOTICE "Cesium Native: Could not find ${MY_LIBRARY_NAME} ... ")
set(CESIUM_LIBRARY_MISSING TRUE)
message(WARNING "Cesium Native: Could NOT find ${MY_LIBRARY_NAME}")
set(CESIUM_ANY_LIBRARY_MISSING TRUE)
endif()
endif()
endmacro()
Expand Down Expand Up @@ -116,7 +118,7 @@ find_cesium_library(CESIUM_NATIVE_MESHOPTIMIZER meshoptimizer)



if(NOT CESIUM_LIBRARY_MISSING)
if(NOT CESIUM_ANY_LIBRARY_MISSING)
set(CESIUM_NATIVE_FOUND TRUE)

# Assemble all the component libraries into one single import library:
Expand All @@ -126,6 +128,8 @@ if(NOT CESIUM_LIBRARY_MISSING)

set_property(TARGET OE::CESIUM_NATIVE PROPERTY
INTERFACE_LINK_LIBRARIES ${CESIUM_NATIVE_IMPORT_LIBRARIES} )
else()
message(WARN "Failed to find all Cesium Native libraries. Check CESIUM_NATIVE_DIR.")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CesiumNative DEFAULT_MSG CESIUM_NATIVE_FOUND)

5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ list(APPEND OSGEARTH_COMPONENTS osgEarth)
# A list of public-facing dependencies for the packaging targets
set(OSGEARTH_PUBLIC_DEPENDENCIES)

# For a static build, we set the define OSGEARTH_STATIC_LIBRARY
# for both building the osgEarth.lib AND for building consumer libraries.
if(NOT OSGEARTH_BUILD_SHARED_LIBS)
add_definitions(-DOSGEARTH_LIBRARY_STATIC)
endif()

if(OSGEARTH_BUILD_IMGUI_NODEKIT)
add_subdirectory(osgEarthImGui)
Expand Down
4 changes: 4 additions & 0 deletions src/applications/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
if(NOT OSGEARTH_BUILD_PLATFORM_IPHONE)

if(NOT OSGEARTH_BUILD_SHARED_LIBS)
add_definitions(-DOSGEARTH_LIBRARY_STATIC)
endif()

# Tools:
if(OSGEARTH_BUILD_TOOLS)
set(TARGET_DEFAULT_LABEL_PREFIX "Tool")
Expand Down
7 changes: 4 additions & 3 deletions src/osgEarth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

if(OSGEARTH_BUILD_SHARED_LIBS)
add_definitions(-DOSGEARTH_LIBRARY)
else()
add_definitions(-DOSGEARTH_LIBRARY_STATIC)
endif()

# Dependencies ...................................................
Expand All @@ -16,10 +14,13 @@ find_package(SQLite3 REQUIRED)
# optional
find_package(geos QUIET)
find_package(blend2d QUIET)
find_package(blosc QUIET)
find_package(spdlog QUIET)
find_package(meshoptimizer QUIET)

if(OSGEARTH_BUILD_SHARED_LIBS)
find_package(blosc QUIET)
endif()

if(OSGEARTH_BUILD_ZIP_PLUGIN)
find_package(LibZip QUIET)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarthImGui/Common
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#pragma warning( disable : 4996 )
#endif

// note: No Windows declspec's here because we are using CMAKE_EXINDOWS_EXPORT_ALL_SYMBOLS
// note: No Windows declspec's here because we are using CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS

#ifndef IMGUI_VERSION
#include <GL/glew.h>
Expand Down
2 changes: 0 additions & 2 deletions src/osgEarthProcedural/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#
if(OSGEARTH_BUILD_SHARED_LIBS)
add_definitions(-DOSGEARTHPROCEDURAL_LIBRARY)
else()
add_definitions(-DOSGEARTHPROCEDURAL_LIBRARY_STATIC)
endif()

SET(LIB_NAME osgEarthProcedural)
Expand Down
12 changes: 2 additions & 10 deletions src/osgEarthProcedural/Export
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/

/* -*-c++-*-
* Derived from osg/Export
*/

#ifndef OSGEARTH_PROCEDURAL_EXPORT_H
#define OSGEARTH_PROCEDURAL_EXPORT_H 1
#pragma once

#if defined(_MSC_VER)
#pragma warning( disable : 4244 )
Expand All @@ -36,7 +30,7 @@
#endif

#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
# if defined( OSGEARTHPROCEDURAL_LIBRARY_STATIC )
# if defined( OSGEARTH_LIBRARY_STATIC )
# define OSGEARTHPROCEDURAL_EXPORT
# elif defined( OSGEARTHPROCEDURAL_LIBRARY )
# define OSGEARTHPROCEDURAL_EXPORT __declspec(dllexport)
Expand All @@ -54,5 +48,3 @@
# endif
#endif

#endif

2 changes: 0 additions & 2 deletions src/osgEarthSilverLining/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ set(OSGEARTH_HAVE_SILVERLINING_NODEKIT ON PARENT_SCOPE) # for BuildConfig

if(OSGEARTH_BUILD_SHARED_LIBS)
add_definitions(-DOSGEARTHSILVERLINING_LIBRARY)
else()
add_definitions(-DOSGEARTHSILVERLINING_LIBRARY_STATIC)
endif()

option(SILVERLINING_USE_PRE_5_079_API "Whether to use the pre-5.079 API due to an API change" OFF)
Expand Down
14 changes: 2 additions & 12 deletions src/osgEarthSilverLining/Export
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/

/* -*-c++-*-
* Derived from osg/Export
*/

#ifndef OSGEARTH_SILVERLINING_EXPORT_H
#define OSGEARTH_SILVERLINING_EXPORT_H 1
#pragma

#if defined(_MSC_VER)
#pragma warning( disable : 4244 )
Expand All @@ -36,7 +30,7 @@
#endif

#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
# if defined( OSGEARTHSILVERLINING_LIBRARY_STATIC )
# if defined( OSGEARTH_LIBRARY_STATIC )
# define OSGEARTHSILVERLINING_EXPORT
# elif defined( OSGEARTHSILVERLINING_LIBRARY )
# define OSGEARTHSILVERLINING_EXPORT __declspec(dllexport)
Expand All @@ -63,7 +57,3 @@
#define NULL ((void *)0)
#endif
#endif


#endif // OSGEARTH_SILVERLINING_EXPORT_H

2 changes: 0 additions & 2 deletions src/osgEarthSplat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ set(OSGEARTH_HAVE_LEGACY_SPLAT_NODEKIT ON PARENT_SCOPE) # for BuildConfig

if(OSGEARTH_BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOSGEARTHSPLAT_LIBRARY)
else()
ADD_DEFINITIONS(-DOSGEARTHSPLAT_LIBRARY_STATIC)
endif()

set(TARGET_GLSL
Expand Down
13 changes: 2 additions & 11 deletions src/osgEarthSplat/Export
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/

/* -*-c++-*-
* Derived from osg/Export
*/

#ifndef OSGEARTH_SPLAT_EXPORT_H
#define OSGEARTH_SPLAT_EXPORT_H 1
#pragma once

#if defined(_MSC_VER)
#pragma warning( disable : 4244 )
Expand All @@ -36,7 +30,7 @@
#endif

#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
# if defined( OSGEARTHSPLAT_LIBRARY_STATIC )
# if defined( OSGEARTH_LIBRARY_STATIC )
# define OSGEARTHSPLAT_EXPORT
# elif defined( OSGEARTHSPLAT_LIBRARY )
# define OSGEARTHSPLAT_EXPORT __declspec(dllexport)
Expand All @@ -53,6 +47,3 @@
# define __STL_MEMBER_TEMPLATES
# endif
#endif

#endif

2 changes: 0 additions & 2 deletions src/osgEarthTriton/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ set(OSGEARTH_HAVE_TRITON_NODEKIT ON PARENT_SCOPE) # BuildConfig

if(OSGEARTH_BUILD_SHARED_LIBS)
add_definitions(-DOSGEARTHTRITON_LIBRARY)
else()
add_definitions(-DOSGEARTHTRITON_LIBRARY_STATIC)
endif()

SET(TARGET_H
Expand Down
14 changes: 2 additions & 12 deletions src/osgEarthTriton/Export
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/

/* -*-c++-*-
* Derived from osg/Export
*/

#ifndef OSGEARTH_TRITON_EXPORT_H
#define OSGEARTH_TRITON_EXPORT_H 1
#pragma once

#if defined(_MSC_VER)
#pragma warning( disable : 4244 )
Expand All @@ -36,7 +30,7 @@
#endif

#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
# if defined( OSGEARTHTRITON_LIBRARY_STATIC )
# if defined( OSGEARTH_LIBRARY_STATIC )
# define OSGEARTHTRITON_EXPORT
# elif defined( OSGEARTHTRITON_LIBRARY )
# define OSGEARTHTRITON_EXPORT __declspec(dllexport)
Expand All @@ -63,7 +57,3 @@
#define NULL ((void *)0)
#endif
#endif


#endif // OSGEARTH_TRITON_EXPORT_H

0 comments on commit c91fdb7

Please sign in to comment.