|
1 | | -cmake_minimum_required(VERSION 3.28...3.30) |
2 | | - |
3 | | -include(./lib/atkaudio/cmake/preconfig.cmake) |
4 | | -include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/common/bootstrap.cmake") |
5 | | - |
6 | | -project(${_name} VERSION ${_version}) |
7 | | - |
8 | | -option(ENABLE_FRONTEND_API "Use obs-frontend-api for UI functionality" OFF) |
9 | | -option(ENABLE_QT "Use Qt functionality" OFF) |
10 | | - |
11 | | -include(compilerconfig) |
12 | | -include(defaults) |
13 | | -include(helpers) |
14 | | - |
15 | | -add_library(${CMAKE_PROJECT_NAME} MODULE) |
16 | | - |
17 | | -find_package(libobs REQUIRED) |
18 | | -target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::libobs) |
19 | | - |
20 | | -if(ENABLE_FRONTEND_API) |
21 | | - find_package(obs-frontend-api REQUIRED) |
22 | | - target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::obs-frontend-api) |
23 | | -endif() |
24 | | - |
25 | | -if(ENABLE_QT) |
26 | | - find_package(Qt6 COMPONENTS Widgets Core) |
27 | | - target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Qt6::Core Qt6::Widgets) |
28 | | - target_compile_options( |
29 | | - ${CMAKE_PROJECT_NAME} |
30 | | - PRIVATE |
31 | | - $<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-quoted-include-in-framework-header |
32 | | - -Wno-comma> |
33 | | - ) |
34 | | - set_target_properties( |
35 | | - ${CMAKE_PROJECT_NAME} |
36 | | - PROPERTIES AUTOMOC ON AUTOUIC ON AUTORCC ON |
37 | | - ) |
38 | | -endif() |
39 | | - |
40 | | -file(GLOB_RECURSE _sources CONFIGURE_DEPENDS src/*.cpp) |
41 | | -target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${_sources}) |
42 | | - |
43 | | -set_target_properties_plugin(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${_name}) |
44 | | - |
45 | | -set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CXX_STANDARD 23) |
46 | | - |
47 | | -add_subdirectory(lib/atkaudio) |
48 | | - |
49 | | -file(READ "${CMAKE_SOURCE_DIR}/buildspec.json" buildspec) |
50 | | -string(JSON PLUGIN_DISPLAY_NAME GET ${buildspec} displayName) |
51 | | -string(JSON PLUGIN_AUTHOR GET ${buildspec} author) |
52 | | -string(JSON PLUGIN_OBS_VERSION_REQUIRED GET ${buildspec} dependencies obs-studio version) |
53 | | -string(TIMESTAMP PLUGIN_YEAR "%Y") |
54 | | -set(PLUGIN_AUTHOR "${PLUGIN_AUTHOR}") |
55 | | - |
56 | | -configure_file(src/config.h.in config.h @ONLY) |
57 | | - |
58 | | -include(./lib/atkaudio/cmake/cpack.cmake) |
| 1 | +cmake_minimum_required(VERSION 3.28...3.30) |
| 2 | + |
| 3 | +include(./lib/atkaudio/cmake/preconfig.cmake) |
| 4 | +include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/common/bootstrap.cmake") |
| 5 | + |
| 6 | +project(${_name} VERSION ${_version}) |
| 7 | + |
| 8 | +# Set default build type to Debug |
| 9 | +if(NOT CMAKE_BUILD_TYPE) |
| 10 | + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build (Debug or Release)" FORCE) |
| 11 | +endif() |
| 12 | +message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") |
| 13 | + |
| 14 | +option(ENABLE_FRONTEND_API "Use obs-frontend-api for UI functionality" ON) |
| 15 | + |
| 16 | +include(compilerconfig) |
| 17 | +include(defaults) |
| 18 | +include(helpers) |
| 19 | + |
| 20 | +# Read buildspec.json early for Qt configuration |
| 21 | +file(READ "${CMAKE_SOURCE_DIR}/buildspec.json" buildspec) |
| 22 | +string(JSON QT6_VERSION GET ${buildspec} dependencies qt6 version) |
| 23 | + |
| 24 | +# Define architecture-specific dependency directory in the build directory |
| 25 | +# Use CMAKE_BINARY_DIR so it works with any configured build directory |
| 26 | +set(DEPS_DIR "${CMAKE_BINARY_DIR}/obs-deps") |
| 27 | + |
| 28 | +# Configure Qt paths for cross-compilation on Windows |
| 29 | +if(WIN32) |
| 30 | + if(CMAKE_VS_PLATFORM_NAME STREQUAL "ARM64") |
| 31 | + # ARM64 Cross-compilation setup |
| 32 | + set(QT_HOST_PATH "${DEPS_DIR}/obs-deps-qt6-${QT6_VERSION}-x64") |
| 33 | + set(Qt6_DIR "${DEPS_DIR}/obs-deps-qt6-${QT6_VERSION}-ARM64/lib/cmake/Qt6" CACHE STRING "Qt6 ARM64 CMake directory" FORCE) |
| 34 | + |
| 35 | + message(STATUS "ARM64 Cross-compilation detected") |
| 36 | + message(STATUS "QT_HOST_PATH: ${QT_HOST_PATH}") |
| 37 | + message(STATUS "Qt6_DIR: ${Qt6_DIR}") |
| 38 | + |
| 39 | + # Check if x64 Qt host tools exist |
| 40 | + if(EXISTS "${QT_HOST_PATH}/bin/moc.exe") |
| 41 | + message(STATUS "Found x64 Qt host tools at: ${QT_HOST_PATH}") |
| 42 | + else() |
| 43 | + message(FATAL_ERROR "x64 Qt host tools not found at: ${QT_HOST_PATH}. ARM64 cross-compilation requires both x64 and ARM64 Qt dependencies.") |
| 44 | + endif() |
| 45 | + |
| 46 | + # Set Qt host tools for cross-compilation (use x64 tools for ARM64 builds) |
| 47 | + set(Qt6CoreTools_DIR "${QT_HOST_PATH}/lib/cmake/Qt6CoreTools" CACHE STRING "Qt6 x64 Core Tools" FORCE) |
| 48 | + set(Qt6GuiTools_DIR "${QT_HOST_PATH}/lib/cmake/Qt6GuiTools" CACHE STRING "Qt6 x64 GUI Tools" FORCE) |
| 49 | + set(Qt6WidgetsTools_DIR "${QT_HOST_PATH}/lib/cmake/Qt6WidgetsTools" CACHE STRING "Qt6 x64 Widget Tools" FORCE) |
| 50 | + |
| 51 | + # Explicitly set tool executables that AUTOMOC/AUTOUIC/AUTORCC will use |
| 52 | + set(CMAKE_AUTOMOC_MOC_EXECUTABLE "${QT_HOST_PATH}/bin/moc.exe" CACHE FILEPATH "MOC executable for ARM64 cross-compilation" FORCE) |
| 53 | + set(CMAKE_AUTOUIC_UIC_EXECUTABLE "${QT_HOST_PATH}/bin/uic.exe" CACHE FILEPATH "UIC executable for ARM64 cross-compilation" FORCE) |
| 54 | + set(CMAKE_AUTORCC_RCC_EXECUTABLE "${QT_HOST_PATH}/bin/rcc.exe" CACHE FILEPATH "RCC executable for ARM64 cross-compilation" FORCE) |
| 55 | + |
| 56 | + # Also set the legacy variables for compatibility |
| 57 | + set(QT_MOC_EXECUTABLE "${QT_HOST_PATH}/bin/moc.exe") |
| 58 | + set(QT_RCC_EXECUTABLE "${QT_HOST_PATH}/bin/rcc.exe") |
| 59 | + set(QT_UIC_EXECUTABLE "${QT_HOST_PATH}/bin/uic.exe") |
| 60 | + |
| 61 | + message(STATUS "Set CMAKE_AUTOMOC_MOC_EXECUTABLE to: ${CMAKE_AUTOMOC_MOC_EXECUTABLE}") |
| 62 | + else() |
| 63 | + # x64 build - set paths to x64 Qt |
| 64 | + set(Qt6_DIR "${DEPS_DIR}/obs-deps-qt6-${QT6_VERSION}-x64/lib/cmake/Qt6" CACHE STRING "Qt6 x64 CMake directory" FORCE) |
| 65 | + message(STATUS "x64 build detected - using x64 Qt at: ${Qt6_DIR}") |
| 66 | + endif() |
| 67 | +endif() |
| 68 | + |
| 69 | +add_library(${CMAKE_PROJECT_NAME} MODULE) |
| 70 | + |
| 71 | +find_package(libobs REQUIRED) |
| 72 | +find_package(obs-frontend-api REQUIRED) |
| 73 | +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::libobs) |
| 74 | + |
| 75 | +if(ENABLE_FRONTEND_API) |
| 76 | + target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::obs-frontend-api) |
| 77 | + target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE ENABLE_FRONTEND_API) |
| 78 | +endif() |
| 79 | + |
| 80 | +# Qt is always required for proper window parenting |
| 81 | +find_package(Qt6 COMPONENTS Widgets Core REQUIRED) |
| 82 | +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Qt6::Core Qt6::Widgets) |
| 83 | +target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE ENABLE_QT) |
| 84 | +target_compile_options( |
| 85 | + ${CMAKE_PROJECT_NAME} |
| 86 | + PRIVATE |
| 87 | + $<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-quoted-include-in-framework-header |
| 88 | + -Wno-comma> |
| 89 | +) |
| 90 | +set_target_properties( |
| 91 | + ${CMAKE_PROJECT_NAME} |
| 92 | + PROPERTIES AUTOMOC ON AUTOUIC ON AUTORCC ON |
| 93 | +) |
| 94 | + |
| 95 | +file(GLOB_RECURSE _sources CONFIGURE_DEPENDS src/*.cpp) |
| 96 | +target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${_sources}) |
| 97 | + |
| 98 | +set_target_properties_plugin(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${_name}) |
| 99 | + |
| 100 | +set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CXX_STANDARD 23) |
| 101 | + |
| 102 | +add_subdirectory(lib/atkaudio) |
| 103 | + |
| 104 | +string(JSON PLUGIN_DISPLAY_NAME GET ${buildspec} displayName) |
| 105 | +string(JSON PLUGIN_AUTHOR GET ${buildspec} author) |
| 106 | +string(JSON PLUGIN_OBS_VERSION_REQUIRED GET ${buildspec} dependencies obs-studio version) |
| 107 | +string(TIMESTAMP PLUGIN_YEAR "%Y") |
| 108 | +set(PLUGIN_AUTHOR "${PLUGIN_AUTHOR}") |
| 109 | + |
| 110 | +configure_file(src/config.h.in config.h @ONLY) |
| 111 | + |
| 112 | +include(./lib/atkaudio/cmake/cpack.cmake) |
| 113 | + |
| 114 | +# Automatically run install after build (skip in CI or when installing to system directories without permissions) |
| 115 | +if(NOT DEFINED ENV{CI} OR NOT CMAKE_INSTALL_PREFIX MATCHES "^/usr") |
| 116 | + add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD |
| 117 | + COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --config $<CONFIG> --component plugin |
| 118 | + COMMENT "Installing plugin after build..." |
| 119 | + ) |
| 120 | +endif() |
| 121 | + |
| 122 | +# On non-CI Linux builds, copy plugin to user home directory after build |
| 123 | +if(NOT DEFINED ENV{CI} AND UNIX AND NOT APPLE) |
| 124 | + if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 125 | + set(_user_arch "64bit") |
| 126 | + else() |
| 127 | + set(_user_arch "32bit") |
| 128 | + endif() |
| 129 | + |
| 130 | + add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD |
| 131 | + COMMAND ${CMAKE_COMMAND} -E make_directory "$ENV{HOME}/.config/obs-studio/plugins/${_name}/bin/${_user_arch}" |
| 132 | + COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:${CMAKE_PROJECT_NAME}>" "$ENV{HOME}/.config/obs-studio/plugins/${_name}/bin/${_user_arch}/" |
| 133 | + COMMAND ${CMAKE_COMMAND} -E make_directory "$ENV{HOME}/.config/obs-studio/plugins/${_name}/data" |
| 134 | + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/data" "$ENV{HOME}/.config/obs-studio/plugins/${_name}/data" |
| 135 | + COMMENT "Copying ${_name} to user home OBS plugins directory..." |
| 136 | + VERBATIM |
| 137 | + ) |
| 138 | +endif() |
0 commit comments