Skip to content

Commit

Permalink
CMake install targets and integration the vsg-way
Browse files Browse the repository at this point in the history
  • Loading branch information
geefr committed Dec 18, 2022
1 parent 4b7a68a commit 4ea9429
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 35 deletions.
65 changes: 38 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ project(vsgvr
DESCRIPTION "VulkanSceneGraph based virtual reality viewer"
LANGUAGES CXX
)

set(VSGVR_SOVERSION 0)


option( BUILD_SHARED_LIBS "Build shared libraries" OFF )
option( VSGVR_BUILD_EXAMPLES "Whether to build VSGVR examples" ON )

if( NOT CMAKE_BUILD_TYPE AND NOT MSVC )
set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE )
set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "MinSizeRel" "RelWithDebInfo" )
endif()

if( NOT VSGVR_XR_PLATFORM )
# OPENXR_GENERIC - The standard openxr_loader.so, built from deps/openxr
# OPENXR_SYSTEM - Whatever OpenXR is available via find_package
Expand All @@ -30,11 +25,47 @@ set( OpenGL_GL_PREFERENCE GLVND )

# Package/System requirements
if(ANDROID)
# On Android, allow vsg to be located outside the Android sysroot
find_package(vsg 1.0.0 NO_CMAKE_FIND_ROOT_PATH)
else()
find_package(vsg 1.0.0)
endif()

# vsgMacros.cmake - Follow vsg conventions for the most part
vsg_setup_dir_vars()
vsg_setup_build_vars()
set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "MinSizeRel" "RelWithDebInfo" )
get_property( generator_is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
if( generator_is_multi_config )
set( CMAKE_CONFIGURATION_TYPES "Release;Debug;MinSizeRel;RelWithDebInfo" CACHE STRING "Build configuration types")
endif()

# TODO: Will re-visit these, and fix when vsgvr is more mature
# (Dev primarily on Windows/Visual Studio, or in Android Studio)
#
# vsg_add_target_clang_format(
# FILES
# ${PROJECT_SOURCE_DIR}/vsgvr/include/vsgvr/*.h
# ${PROJECT_SOURCE_DIR}/vsgvr/srv/vsgvr/*.cpp
# )
# vsg_add_target_cppcheck(
# FILES
# ${PROJECT_SOURCE_DIR}/vsgvr/include/vsgvr/*.h
# ${PROJECT_SOURCE_DIR}/vsgvr/srv/vsgvr/*.cpp
# )
# vsg_add_target_docs(
# FILES
# ${PROJECT_SOURCE_DIR}/vsgvr/include
# )
# vsg_add_target_clobber()

vsg_add_target_uninstall()
vsg_add_feature_summary()
vsg_add_cmake_support_files(
CONFIG_TEMPLATE vsgvrConfig.cmake.in
)

# Other Dependencies
find_package(Vulkan REQUIRED)

set(OpenXR_LIBRARY openxr_loader)
Expand All @@ -60,30 +91,10 @@ elseif( VSGVR_XR_PLATFORM STREQUAL "OPENXR_OCULUS_MOBILE" )
"${VSGVR_OCULUS_OPENXR_MOBILE_SDK}/3rdParty/khronos/openxr/OpenXR-SDK/include")
endif()

vsg_setup_dir_vars()
vsg_setup_build_vars()

vsg_add_target_clang_format(
FILES
${PROJECT_SOURCE_DIR}/vsgvr/include/vsgvr/*.h
${PROJECT_SOURCE_DIR}/vsgvr/srv/vsgvr/*.cpp
)
vsg_add_target_cppcheck(
FILES
${PROJECT_SOURCE_DIR}/vsgvr/include/vsgvr/*.h
${PROJECT_SOURCE_DIR}/vsgvr/srv/vsgvr/*.cpp
)
vsg_add_target_clobber()
vsg_add_target_docs(
FILES
${PROJECT_SOURCE_DIR}/vsgvr/include
)
vsg_add_target_uninstall()

# VSGVR
add_subdirectory( vsgvr )

if( VSGVR_BUILD_EXAMPLES )
add_subdirectory( examples )
endif()

vsg_add_feature_summary()
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

if(ANDROID)
# Quest sample is loaded backwards - Open the project in Android Studio, and VSGVR will be included through CMake
# Quest samples are loaded backwards - Open the project in Android Studio, and VSGVR will be included through CMake
else()
add_subdirectory( generic )
endif()
Expand Down
4 changes: 4 additions & 0 deletions examples/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

add_executable( vsgvr_example_generic main.cpp )

target_link_libraries( vsgvr_example_generic vsg::vsg vsgvr )

install(TARGETS vsgvr_example_generic)

set_target_properties( vsgvr_example_generic PROPERTIES FOLDER "examples" )
38 changes: 31 additions & 7 deletions vsgvr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@

set( SOURCES
set( HEADERS_ACTIONS
include/vsgvr/actions/OpenXRAction.h
include/vsgvr/actions/OpenXRActionPoseBinding.h
include/vsgvr/actions/OpenXRActionSet.h
)

set( HEADERS_APP
include/vsgvr/app/OpenXRViewer.h
)

set( HEADERS_XR
include/vsgvr/xr/OpenXRCommon.h
include/vsgvr/xr/OpenXREventHandler.h
include/vsgvr/xr/OpenXRGraphicsBindingVulkan.h
Expand All @@ -13,7 +19,9 @@ set( SOURCES
include/vsgvr/xr/OpenXRSwapchain.h
include/vsgvr/xr/OpenXRTraits.h
include/vsgvr/xr/OpenXRViewMatrix.h
)

set( SOURCES
src/vsgvr/actions/OpenXRAction.cpp
src/vsgvr/actions/OpenXRActionPoseBinding.cpp
src/vsgvr/actions/OpenXRActionSet.cpp
Expand All @@ -27,24 +35,40 @@ set( SOURCES
)

if( ANDROID )
list(APPEND SOURCES
list(APPEND HEADERS_XR
include/vsgvr/xr/OpenXRAndroidTraits.h
)
list(APPEND SOURCES
src/vsgvr/xr/OpenXRAndroidTraits.cpp
)
endif()

add_library( vsgvr ${SOURCES} ${HEADERS} )
add_library( vsgvr ${HEADERS_ACTIONS} ${HEADERS_APP} ${HEADERS_XR} ${SOURCES} )

target_include_directories(
vsgvr PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
target_include_directories(vsgvr PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_link_libraries( vsgvr PUBLIC vsg::vsg ${OpenXR_LIBRARY} )

set_target_properties( vsgvr PROPERTIES FOLDER "vsgvr" )

# TODO: This needs to be in a header - Otherwise anyone linking to vsgvr without
# going through CMake will have to define it themselves
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(vsgvr PRIVATE "VSGVR_DECLSPEC=__declspec(dllexport)")
target_compile_definitions(vsgvr INTERFACE "VSGVR_DECLSPEC=__declspec(dllimport)")
else()
target_compile_definitions( vsgvr PUBLIC "VSGVR_DECLSPEC=" )
target_compile_definitions(vsgvr PUBLIC "VSGVR_DECLSPEC=")
endif()

set_target_properties(vsgvr PROPERTIES
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
SOVERSION ${VSGVR_SOVERSION}
)

install(TARGETS vsgvr ${INSTALL_TARGETS_DEFAULT_FLAGS})
install(FILES ${HEADERS_ACTIONS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vsgvr/actions)
install(FILES ${HEADERS_APP} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vsgvr/app)
install(FILES ${HEADERS_XR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vsgvr/xr)
File renamed without changes.

0 comments on commit 4ea9429

Please sign in to comment.