Skip to content

Commit

Permalink
cmake: Update CMake files to current state found on obs-studio
Browse files Browse the repository at this point in the history
  • Loading branch information
PatTheMav committed Aug 11, 2024
1 parent 1f99d40 commit fc49c72
Show file tree
Hide file tree
Showing 24 changed files with 503 additions and 646 deletions.
8 changes: 0 additions & 8 deletions .github/scripts/build-ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,6 @@ ${_usage_host:-}"
local cmake_version
read -r _ _ cmake_version <<< "$(cmake --version)"
if [[ ${CPUTYPE} != ${target##*-} ]] {
if is-at-least 3.21.0 ${cmake_version}; then
cmake_args+=(--toolchain "${project_root}/cmake/linux/toolchains/${target##*-}-linux-gcc.cmake")
else
cmake_args+=(-D"CMAKE_TOOLCHAIN_FILE=${project_root}/cmake/linux/toolchains/${target##*-}-linux-gcc.cmake")
fi
}
cmake_build_args+=(--preset ${_preset}-${target##*-} --config ${config})
if [[ ${generator} == 'Unix Makefiles' ]] {
cmake_build_args+=(--parallel $(( $(nproc) + 1 )))
Expand Down
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16...3.26)
cmake_minimum_required(VERSION 3.22...3.26)

include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/common/bootstrap.cmake" NO_POLICY_SCOPE)

Expand All @@ -25,13 +25,13 @@ if(ENABLE_QT)
find_package(Qt6 COMPONENTS Widgets Core)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Qt6::Core Qt6::Widgets)
target_compile_options(
${CMAKE_PROJECT_NAME} PRIVATE $<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-quoted-include-in-framework-header
-Wno-comma>)
${CMAKE_PROJECT_NAME}
PRIVATE $<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-quoted-include-in-framework-header -Wno-comma>
)
set_target_properties(
${CMAKE_PROJECT_NAME}
PROPERTIES AUTOMOC ON
AUTOUIC ON
AUTORCC ON)
PROPERTIES AUTOMOC ON AUTOUIC ON AUTORCC ON
)
endif()

target_sources(${CMAKE_PROJECT_NAME} PRIVATE src/plugin-main.c)
Expand Down
71 changes: 15 additions & 56 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
}
},
{
"name": "linux-x86_64",
"displayName": "Linux x86_64",
"description": "Build for Linux x86_64",
"name": "ubuntu-x86_64",
"displayName": "Ubuntu x86_64",
"description": "Build for Ubuntu x86_64",
"inherits": ["template"],
"binaryDir": "${sourceDir}/build_x86_64",
"condition": {
Expand All @@ -88,37 +88,10 @@
}
},
{
"name": "linux-ci-x86_64",
"inherits": ["linux-x86_64"],
"displayName": "Linux x86_64 CI build",
"description": "Build for Linux x86_64 on CI",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_COMPILE_WARNING_AS_ERROR": true
}
},
{
"name": "linux-aarch64",
"displayName": "Linux aarch64",
"description": "Build for Linux aarch64",
"inherits": ["template"],
"binaryDir": "${sourceDir}/build_aarch64",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"generator": "Ninja",
"warnings": {"dev": true, "deprecated": true},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "linux-ci-aarch64",
"inherits": ["linux-aarch64"],
"displayName": "Linux aarch64 CI build",
"description": "Build for Linux aarch64 on CI",
"name": "ubuntu-ci-x86_64",
"inherits": ["ubuntu-x86_64"],
"displayName": "Ubuntu x86_64 CI build",
"description": "Build for Ubuntu x86_64 on CI",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_COMPILE_WARNING_AS_ERROR": true
Expand Down Expand Up @@ -155,31 +128,17 @@
"configuration": "RelWithDebInfo"
},
{
"name": "linux-x86_64",
"configurePreset": "linux-x86_64",
"displayName": "Linux x86_64",
"description": "Linux build for x86_64",
"configuration": "RelWithDebInfo"
},
{
"name": "linux-ci-x86_64",
"configurePreset": "linux-ci-x86_64",
"displayName": "Linux x86_64 CI",
"description": "Linux CI build for x86_64",
"configuration": "RelWithDebInfo"
},
{
"name": "linux-aarch64",
"configurePreset": "linux-aarch64",
"displayName": "Linux aarch64",
"description": "Linux build for aarch64",
"name": "ubuntu-x86_64",
"configurePreset": "ubuntu-x86_64",
"displayName": "Ubuntu x86_64",
"description": "Ubuntu build for x86_64",
"configuration": "RelWithDebInfo"
},
{
"name": "linux-ci-aarch64",
"configurePreset": "linux-ci-aarch64",
"displayName": "Linux aarch64 CI",
"description": "Linux CI build for aarch64",
"name": "ubuntu-ci-x86_64",
"configurePreset": "ubuntu-ci-x86_64",
"displayName": "Ubuntu x86_64 CI",
"description": "Ubuntu CI build for x86_64",
"configuration": "RelWithDebInfo"
}
]
Expand Down
26 changes: 13 additions & 13 deletions buildspec.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
{
"dependencies": {
"obs-studio": {
"version": "30.1.2",
"version": "30.2.2",
"baseUrl": "https://github.com/obsproject/obs-studio/archive/refs/tags",
"label": "OBS sources",
"hashes": {
"macos": "490bae1c392b3b344b0270afd8cb887da4bc50bd92c0c426e96713c1ccb9701a",
"windows-x64": "c2dd03fa7fd01fad5beafce8f7156da11f9ed9a588373fd40b44a06f4c03b867"
"macos": "ce8c6ae586df17fef6c2473883531291010dfbb8fc1ce20582e23d3c41df41ba",
"windows-x64": "536b58a31c852b7490c3a96546b5b6fc4257f56e63f35a95f11cb5857ebead45"
}
},
"prebuilt": {
"version": "2024-03-19",
"version": "2024-05-08",
"baseUrl": "https://github.com/obsproject/obs-deps/releases/download",
"label": "Pre-Built obs-deps",
"hashes": {
"macos": "2e9bfb55a5e0e4c1086fa1fda4cf268debfead473089df2aaea80e1c7a3ca7ff",
"windows-x64": "6e86068371526a967e805f6f9903f9407adb683c21820db5f07da8f30d11e998"
"macos": "da3167a3efecfa67dd72e4f2b7964c3456d74c639d4c62aa21ec300ebd5007a8",
"windows-x64": "773c87a0d173125ef2768aaca6f6de64a7d6053213cc9f7d3970a301152042d8"
}
},
"qt6": {
"version": "2024-03-19",
"version": "2024-05-08",
"baseUrl": "https://github.com/obsproject/obs-deps/releases/download",
"label": "Pre-Built Qt6",
"hashes": {
"macos": "694f1e639c017e3b1f456f735330dc5afae287cbea85757101af1368de3142c8",
"windows-x64": "72d1df34a0ef7413a681d5fcc88cae81da60adc03dcd23ef17862ab170bcc0dd"
"macos": "248fb342e7ddf574af0960aaedeffb832deda1485dc81583302646e979593a6e",
"windows-x64": "8f459af5115ce081ae24b108712327e113893f250e14a902b1bd188b43873ed1"
},
"debugSymbols": {
"windows-x64": "fbddd1f659c360f2291911ac5709b67b6f8182e6bca519d24712e4f6fd3cc865"
"windows-x64": "e4bc882f23195becbe53f1594fe75bdb9ff4f1d01e319f6caf8e0a38000cb42b"
}
}
},
"platformConfig": {
"macos": {
"bundleId": "com.example.obs-plugintemplate"
"bundleId": "com.example.plugintemplate-for-obs"
}
},
"name": "obs-plugintemplate",
"displayName": "OBS Plugin Template",
"name": "plugintemplate-for-obs",
"displayName": "Plugin Template for OBS",
"version": "1.0.0",
"author": "Your Name Here",
"website": "https://example.com",
Expand Down
83 changes: 51 additions & 32 deletions cmake/common/bootstrap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,41 @@ cmake_minimum_required(VERSION 3.16...3.26)

include_guard(GLOBAL)

# Enable automatic PUSH and POP of policies to parent scope
if(POLICY CMP0011)
cmake_policy(SET CMP0011 NEW)
endif()

# Enable distinction between Clang and AppleClang
if(POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif()

# Enable strict checking of "break()" usage
if(POLICY CMP0055)
cmake_policy(SET CMP0055 NEW)
endif()

# Honor visibility presets for all target types (executable, shared, module, static)
if(POLICY CMP0063)
cmake_policy(SET CMP0063 NEW)
endif()

# Disable export function calls to populate package registry by default
if(POLICY CMP0090)
cmake_policy(SET CMP0090 NEW)
endif()
# Map fallback configurations for optimized build configurations
# gersemi: off
set(
CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO
RelWithDebInfo
Release
MinSizeRel
None
""
)
set(
CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL
MinSizeRel
Release
RelWithDebInfo
None
""
)
set(
CMAKE_MAP_IMPORTED_CONFIG_RELEASE
Release
RelWithDebInfo
MinSizeRel
None
""
)
# gersemi: on

# Prohibit in-source builds
if("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
message(FATAL_ERROR "In-source builds are not supported. "
"Specify a build directory via 'cmake -S <SOURCE DIRECTORY> -B <BUILD_DIRECTORY>' instead.")
message(
FATAL_ERROR
"In-source builds are not supported. "
"Specify a build directory via 'cmake -S <SOURCE DIRECTORY> -B <BUILD_DIRECTORY>' instead."
)
file(REMOVE_RECURSE "${CMAKE_CURRENT_SOURCE_DIR}/CMakeCache.txt" "${CMAKE_CURRENT_SOURCE_DIR}/CMakeFiles")
endif()

Expand All @@ -42,31 +48,44 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/common")

file(READ "${CMAKE_CURRENT_SOURCE_DIR}/buildspec.json" buildspec)

# cmake-format: off
string(JSON _name GET ${buildspec} name)
string(JSON _website GET ${buildspec} website)
string(JSON _author GET ${buildspec} author)
string(JSON _email GET ${buildspec} email)
string(JSON _version GET ${buildspec} version)
string(JSON _bundleId GET ${buildspec} platformConfig macos bundleId)
string(JSON _windowsAppUUID GET ${buildspec} uuids windowsApp)
# cmake-format: on

set(PLUGIN_AUTHOR ${_author})
set(PLUGIN_WEBSITE ${_website})
set(PLUGIN_EMAIL ${_email})
set(PLUGIN_VERSION ${_version})
set(MACOS_BUNDLEID ${_bundleId})

string(REPLACE "." ";" _version_canonical "${_version}")
list(GET _version_canonical 0 PLUGIN_VERSION_MAJOR)
list(GET _version_canonical 1 PLUGIN_VERSION_MINOR)
list(GET _version_canonical 2 PLUGIN_VERSION_PATCH)
unset(_version_canonical)

include(buildnumber)
include(osconfig)

# Allow selection of common build types via UI
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE
if(NOT CMAKE_GENERATOR MATCHES "(Xcode|Visual Studio .+)")
if(NOT CMAKE_BUILD_TYPE)
set(
CMAKE_BUILD_TYPE
"RelWithDebInfo"
CACHE STRING "OBS build type [Release, RelWithDebInfo, Debug, MinSizeRel]" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Release RelWithDebInfo Debug MinSizeRel)
CACHE STRING
"OBS build type [Release, RelWithDebInfo, Debug, MinSizeRel]"
FORCE
)
set_property(
CACHE CMAKE_BUILD_TYPE
PROPERTY STRINGS Release RelWithDebInfo Debug MinSizeRel
)
endif()
endif()

# Disable exports automatically going into the CMake package registry
Expand Down
37 changes: 20 additions & 17 deletions cmake/common/buildnumber.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@
include_guard(GLOBAL)

# Define build number cache file
set(_BUILD_NUMBER_CACHE
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/.CMakeBuildNumber"
CACHE INTERNAL "OBS build number cache file")
set(
_BUILD_NUMBER_CACHE
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/.CMakeBuildNumber"
CACHE INTERNAL
"OBS build number cache file"
)

# Read build number from cache file or manual override
if(NOT DEFINED PLUGIN_BUILD_NUMBER AND EXISTS "${_BUILD_NUMBER_CACHE}")
file(READ "${_BUILD_NUMBER_CACHE}" PLUGIN_BUILD_NUMBER)
math(EXPR PLUGIN_BUILD_NUMBER "${PLUGIN_BUILD_NUMBER}+1")
elseif(NOT DEFINED PLUGIN_BUILD_NUMBER)
if($ENV{CI})
if($ENV{GITHUB_RUN_ID})
set(PLUGIN_BUILD_NUMBER "$ENV{GITHUB_RUN_ID}")
elseif($ENV{GITLAB_RUN_ID})
set(PLUGIN_BUILD_NUMBER "$ENV{GITLAB_RUN_ID}")
else()
set(PLUGIN_BUILD_NUMBER "1")
endif()
if(NOT DEFINED PLUGIN_BUILD_NUMBER)
if(EXISTS "${_BUILD_NUMBER_CACHE}")
file(READ "${_BUILD_NUMBER_CACHE}" PLUGIN_BUILD_NUMBER)
math(EXPR PLUGIN_BUILD_NUMBER "${PLUGIN_BUILD_NUMBER}+1")
else()
set(PLUGIN_BUILD_NUMBER "1")
if("$ENV{CI}")
if("$ENV{GITHUB_RUN_ID}")
set(PLUGIN_BUILD_NUMBER "$ENV{GITHUB_RUN_ID}")
elseif("$ENV{GITLAB_RUN_ID}")
set(PLUGIN_BUILD_NUMBER "$ENV{GITLAB_RUN_ID}")
else()
set(PLUGIN_BUILD_NUMBER "1")
endif()
endif()
endif()
file(WRITE "${_BUILD_NUMBER_CACHE}" "${PLUGIN_BUILD_NUMBER}")
endif()
file(WRITE "${_BUILD_NUMBER_CACHE}" "${PLUGIN_BUILD_NUMBER}")
Loading

0 comments on commit fc49c72

Please sign in to comment.