Skip to content

Commit

Permalink
Depependency refactoring
Browse files Browse the repository at this point in the history
Adds support for vcpkg
Adds support for dynamic linkage (BUILD_SHARED_LIBS=ON)
Use alias targets when linking in cmake to avoid typos.
Use find_package and target_link_libraries for all dependencies, also header only dependencies.
  • Loading branch information
petersteneteg committed Mar 21, 2023
1 parent 2f82990 commit c3bdfcf
Show file tree
Hide file tree
Showing 97 changed files with 771 additions and 255 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/sgct.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build sgct

on:
push:
workflow_dispatch:

env:
VCPKG_BINARY_SOURCES: 'clear;nuget,GitHub,readwrite'

jobs:
build:
strategy:
matrix:
ext: ["submodule" ,"vcpkg"]
linkage: ["static", "dynamic"]
tracy: ["-tracy", ""]
fail-fast: false

runs-on: windows-latest
timeout-minutes: 360

steps:
- name: Clone VCPKG
uses: actions/checkout@v3
with:
repository: 'microsoft/vcpkg'
fetch-depth: 0
path: 'vcpkg'

# Cache built dependencies for faster subsequent builds
- name: 'Setup NuGet Credentials'
shell: bash
run: >
`vcpkg fetch nuget | tail -n 1`
sources add
-source "https://nuget.pkg.github.com/inviwo/index.json"
-storepasswordincleartext
-name "GitHub"
-username "inviwo"
-password "${{ secrets.GITHUB_TOKEN }}"
- name: Setup C++ Log matchers
uses: Trass3r/setup-cpp@v1

- name: Clone
uses: actions/checkout@v3
with:
path: sgct
submodules: recursive

- name: Configure
shell: bash
run: >
cmake -S sgct -B build --preset msvc-${{ matrix.ext }}-${{ matrix.linkage }}${{ matrix.tracy }}
-DCMAKE_BUILD_TYPE=Release
- name: Build
timeout-minutes: 360
shell: bash
run: cmake --build build --config Release --parallel

- name: Test
if: matrix.tracy == ''
timeout-minutes: 360
shell: bash
run: ctest --test-dir build --build-config Release --output-on-failure
47 changes: 35 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
cmake_policy(VERSION 3.25)
enable_testing()

project(sgct VERSION 3.0.0)

Expand All @@ -16,10 +17,11 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)


include(support/cmake/register_package.cmake)
file(REMOVE_RECURSE ${PROJECT_BINARY_DIR}/pkg)
list(APPEND CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/support/cmake/modules
${PROJECT_BINARY_DIR}/pkg
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/pkg)
list(APPEND CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/support/cmake/modules
${CMAKE_BINARY_DIR}/pkg
)

if (APPLE)
Expand All @@ -33,38 +35,59 @@ option(SGCT_EXAMPLES "Build SGCT examples" OFF)
option(SGCT_FREETYPE_SUPPORT "Build SGCT with Freetype2" ON)
option(SGCT_OPENVR_SUPPORT "SGCT OpenVR support" OFF)
option(SGCT_VRPN_SUPPORT "SGCT VRPN support" OFF)
option(SGCT_TRACY_SUPPORT "Build SGCT with Tracy" OFF)

if (WIN32)
option(SGCT_SPOUT_SUPPORT "SGCT Spout support" OFF)
endif ()

# Exceptions for external libraries
option(SGCT_DEP_INCLUDE_CATCH2 "Include Catch2 library" ON)
option(SGCT_DEP_INCLUDE_FMT "Include FMT library" ON)
option(SGCT_DEP_INCLUDE_SCN "Include SCN library" ON)
option(SGCT_DEP_INCLUDE_FREETYPE "Include FreeType library" ON)
option(SGCT_DEP_INCLUDE_GLAD "Include GLAD library" ON)
option(SGCT_DEP_INCLUDE_GLFW "Include GLFW library" ON)
option(SGCT_DEP_INCLUDE_GLM "Include GLM library" ON)
option(SGCT_DEP_INCLUDE_JSON "Include JSON library" ON)
option(SGCT_DEP_INCLUDE_LIBPNG "Include LibPNG library" ON)
option(SGCT_DEP_INCLUDE_FREETYPE "Include FreeType library" ON)
option(SGCT_DEP_INCLUDE_OPENVR "Include OpenVR library" ON)
option(SGCT_DEP_INCLUDE_SCN "Include SCN library" ON)
option(SGCT_DEP_INCLUDE_STB "Include STB library" ON)
option(SGCT_DEP_INCLUDE_TINYXML "Include TinyXML library" ON)
option(SGCT_DEP_INCLUDE_TRACY "Include Tracy library" ON)
option(SGCT_DEP_INCLUDE_VRPN "Include VRPN library" OFF)
option(SGCT_DEP_INCLUDE_GLAD "Include GLAD library" ON)
option(SGCT_DEP_INCLUDE_ZLIB "Include ZLIB library" ON)
option(SGCT_DEP_INCLUDE_GLM "Include GLM library" ON)
option(SGCT_DEP_INCLUDE_OPENVR "Include OpenVR library" ON)

if (WIN32)
option(SGCT_ENABLE_EDIT_CONTINUE "Enable Edit&Continue" ON)

if (TRACY_ENABLE AND SGCT_ENABLE_EDIT_CONTINUE)
message(WARNING "Tracy does not support compiling with Edit&Continue, so we have to disable that feature")
set(SGCT_ENABLE_EDIT_CONTINUE OFF CACHE BOOL "" FORCE)
endif ()
endif ()

if (UNIX)
option(SGCT_ENABLE_STATIC_ANALYZER "Enable Static analyzer" OFF)
endif ()

add_subdirectory(ext SYSTEM)
add_subdirectory(src)
option(SGCT_INSTALL "Install SGCT library" OFF)
option(SGCT_BUILD_TESTS "Build SGCT tests" ON)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

add_subdirectory(tests)
# add dummy uninstall target to avoid it beeing added by dependencies
if (NOT TARGET uninstall)
add_custom_target(uninstall)
endif()

add_subdirectory(ext SYSTEM)
add_subdirectory(src)
if (SGCT_BUILD_TESTS)
add_subdirectory(tests)
endif()
if (SGCT_EXAMPLES)
add_subdirectory(apps)
endif ()
109 changes: 109 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"version": 3,
"cmakeMinimumRequired": { "major": 3, "minor": 21, "patch": 0 },
"configurePresets": [
{
"name": "tracy",
"hidden": true,
"cacheVariables": {
"SGCT_ENABLE_EDIT_CONTINUE": { "type": "BOOL", "value": "OFF"},
"SGCT_TRACY_SUPPORT": { "type": "BOOL", "value": "ON"}
}
},
{
"name": "vcpkg",
"hidden": true,
"toolchainFile": "${sourceParentDir}/vcpkg/scripts/buildsystems/vcpkg.cmake",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE" : "${sourceParentDir}/vcpkg/scripts/buildsystems/vcpkg.cmake",
"SGCT_DEP_INCLUDE_CATCH2": { "type": "BOOL", "value": "OFF"},
"SGCT_DEP_INCLUDE_FMT": { "type": "BOOL", "value": "OFF"},
"SGCT_DEP_INCLUDE_FREETYPE": { "type": "BOOL", "value": "OFF"},
"SGCT_DEP_INCLUDE_GLAD": { "type": "BOOL", "value": "OFF"},
"SGCT_DEP_INCLUDE_GLFW": { "type": "BOOL", "value": "OFF"},
"SGCT_DEP_INCLUDE_GLM": { "type": "BOOL", "value": "OFF"},
"SGCT_DEP_INCLUDE_JSON": { "type": "BOOL", "value": "OFF"},
"SGCT_DEP_INCLUDE_LIBPNG": { "type": "BOOL", "value": "OFF"},
"SGCT_DEP_INCLUDE_OPENVR": { "type": "BOOL", "value": "OFF"},
"SGCT_DEP_INCLUDE_SCN": { "type": "BOOL", "value": "OFF"},
"SGCT_DEP_INCLUDE_STB": { "type": "BOOL", "value": "OFF"},
"SGCT_DEP_INCLUDE_TINYXML": { "type": "BOOL", "value": "OFF"},
"SGCT_DEP_INCLUDE_TRACY": { "type": "BOOL", "value": "OFF"},
"SGCT_DEP_INCLUDE_ZLIB": { "type": "BOOL", "value": "OFF"}
}
},
{
"name": "msvc",
"displayName": "MSVC 2022",
"generator": "Visual Studio 17 2022",
"architecture": "x64"
},
{
"name": "msvc-submodule-static",
"displayName": "MSVC 2022 Using submodules, static linking",
"inherits": ["msvc"],
"cacheVariables": {
"BUILD_SHARED_LIBS" : { "type": "BOOL", "value": "OFF"},
"SGCT_FREETYPE_SUPPORT" : { "type": "BOOL", "value": "ON"}
}
},
{
"name": "msvc-submodule-static-tracy",
"displayName": "MSVC 2022 Using submodules, static linking, tracy enabled",
"inherits": ["msvc", "tracy"]
},
{
"name": "msvc-submodule-dynamic",
"displayName": "MSVC 2022 Using submodules, dynamic linking",
"inherits": ["msvc"],
"cacheVariables": {
"BUILD_SHARED_LIBS" : { "type": "BOOL", "value": "ON"},
"SGCT_FREETYPE_SUPPORT" : { "type": "BOOL", "value": "ON"}
}
},
{
"name": "msvc-submodule-dynamic-tracy",
"displayName": "MSVC 2022 Using submodules, dynamic linking, tracy enabled",
"inherits": ["msvc", "tracy"]
},
{
"name": "msvc-vcpkg-static",
"displayName": "MSVC 2022 Using vcpkg, static linking",
"inherits": ["vcpkg", "msvc"],
"cacheVariables": {
"VCPKG_TARGET_TRIPLET" : "x64-windows-static-md",
"BUILD_SHARED_LIBS" : { "type": "BOOL", "value": "OFF"},
"VCPKG_MANIFEST_FEATURES" : "freetype",
"SGCT_FREETYPE_SUPPORT" : { "type": "BOOL", "value": "ON"}
}
},
{
"name": "msvc-vcpkg-static-tracy",
"displayName": "MSVC 2022 Using vcpkg, static linking, tracy enabled",
"inherits": ["vcpkg", "msvc", "tracy"],
"cacheVariables": {
"VCPKG_MANIFEST_FEATURES" : "freetype;tracy"
}
},
{
"name": "msvc-vcpkg-dynamic",
"displayName": "MSVC 2022 Using vcpkg, dynamic linking",
"inherits": ["vcpkg", "msvc"],
"cacheVariables": {
"VCPKG_TARGET_TRIPLET" : "x64-windows",
"BUILD_SHARED_LIBS" : { "type": "BOOL", "value": "ON"},
"VCPKG_MANIFEST_FEATURES" : "freetype",
"SGCT_FREETYPE_SUPPORT" : { "type": "BOOL", "value": "ON"}
}
},
{
"name": "msvc-vcpkg-dynamic-tracy",
"displayName": "MSVC 2022 Using vcpkg, dynamic linking, tracy enabled",
"inherits": ["vcpkg", "msvc", "tracy"],
"cacheVariables": {
"VCPKG_MANIFEST_FEATURES" : "freetype;tracy"
}
}
]
}

2 changes: 1 addition & 1 deletion apps/calibrator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
add_executable(calibrator main.cpp)
set_compile_options(calibrator)
find_package(glm REQUIRED)
target_link_libraries(calibrator PRIVATE sgct glm)
target_link_libraries(calibrator PRIVATE sgct::sgct glm::glm)

add_custom_command(
TARGET calibrator POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion apps/datatransfer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
add_executable(datatransfer main.cpp)
set_compile_options(datatransfer)
find_package(glm REQUIRED)
target_link_libraries(datatransfer PRIVATE sgct glm)
target_link_libraries(datatransfer PRIVATE sgct::sgct glm::glm)

add_custom_command(
TARGET datatransfer POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion apps/domeimageviewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

add_executable(domeimageviewer main.cpp)
set_compile_options(domeimageviewer)
target_link_libraries(domeimageviewer PRIVATE sgct)
target_link_libraries(domeimageviewer PRIVATE sgct::sgct)

add_custom_command(
TARGET domeimageviewer POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion apps/example1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
add_executable(example1 main.cpp)
set_compile_options(example1)
find_package(glm REQUIRED)
target_link_libraries(example1 PRIVATE sgct glm)
target_link_libraries(example1 PRIVATE sgct::sgct glm::glm)
set_property(TARGET example1 PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:example1>)
set_target_properties(example1 PROPERTIES FOLDER "Examples")

Expand Down
2 changes: 1 addition & 1 deletion apps/ffmpegcapture/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

add_executable(ffmpegcapture main.cpp capture.h capture.cpp)
set_compile_options(ffmpegcapture)
target_link_libraries(ffmpegcapture PRIVATE sgct)
target_link_libraries(ffmpegcapture PRIVATE sgct::sgct)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/user_cmake/Modules)

find_package(FFmpeg REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion apps/ffmpegcaptureanddomeimageviewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

add_executable(fmpegcaptureanddomeimageviewer main.cpp capture.h capture.cpp)
set_compile_options(fmpegcaptureanddomeimageviewer)
target_link_libraries(fmpegcaptureanddomeimageviewer PRIVATE sgct)
target_link_libraries(fmpegcaptureanddomeimageviewer PRIVATE sgct::sgct)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/user_cmake/Modules)

find_package(FFmpeg REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion apps/gamepad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

add_executable(gamepad main.cpp)
set_compile_options(gamepad)
target_link_libraries(gamepad PRIVATE sgct)
target_link_libraries(gamepad PRIVATE sgct::sgct)
set_property(TARGET gamepad PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:gamepad>)
set_target_properties(gamepad PROPERTIES FOLDER "Examples")

Expand Down
2 changes: 1 addition & 1 deletion apps/heightmapping/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
add_executable(heightmapping main.cpp)
set_compile_options(heightmapping)
find_package(glm REQUIRED)
target_link_libraries(heightmapping PRIVATE sgct glm)
target_link_libraries(heightmapping PRIVATE sgct::sgct glm::glm)

add_custom_command(
TARGET heightmapping POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion apps/multiplerendertargets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
add_executable(multiplerendertargets main.cpp)
set_compile_options(multiplerendertargets)
find_package(glm REQUIRED)
target_link_libraries(multiplerendertargets PRIVATE sgct glm)
target_link_libraries(multiplerendertargets PRIVATE sgct::sgct glm::glm)

add_custom_command(
TARGET multiplerendertargets POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion apps/network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
add_executable(network main.cpp)
set_compile_options(network)
find_package(glm REQUIRED)
target_link_libraries(network PRIVATE sgct glm)
target_link_libraries(network PRIVATE sgct::sgct glm::glm)

add_custom_command(
TARGET network POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion apps/omnistereo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
add_executable(omnistereo main.cpp)
set_compile_options(omnistereo)
find_package(glm REQUIRED)
target_link_libraries(omnistereo PRIVATE sgct glm)
target_link_libraries(omnistereo PRIVATE sgct::sgct glm::glm)

add_custom_command(
TARGET omnistereo POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion apps/simplenavigation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
add_executable(simplenavigation main.cpp)
set_compile_options(simplenavigation)
find_package(glm REQUIRED)
target_link_libraries(simplenavigation PRIVATE sgct glm)
target_link_libraries(simplenavigation PRIVATE sgct::sgct glm::glm)

add_custom_command(
TARGET simplenavigation POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion apps/sound/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

add_executable(sound main.cpp)
set_compile_options(sound)
target_link_libraries(sound PRIVATE sgct)
target_link_libraries(sound PRIVATE sgct::sgct)

find_library(ALUT_DEBUG_LIBRARY NAMES alutd libalutd libalut_cpp11d REQUIRED)
find_library(ALUT_RELEASE_LIBRARY NAMES alut libalut libalut_cpp11 REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion apps/spout/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
add_executable(spoutapp main.cpp)
set_compile_options(spoutapp)
find_package(GLM REQUIRED)
target_link_libraries(spoutapp PRIVATE sgct glm)
target_link_libraries(spoutapp PRIVATE sgct::sgct glm::glm)
set_property(TARGET spoutapp PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:spoutapp>)
set_target_properties(spoutapp PROPERTIES FOLDER "Examples")

Expand Down
Loading

0 comments on commit c3bdfcf

Please sign in to comment.