Bläddra i källkod

cmake: Add updated Windows CMake scripts

PatTheMav 2 år sedan
förälder
incheckning
ebc753ba10

+ 24 - 0
cmake/windows/buildspec.cmake

@@ -0,0 +1,24 @@
+# CMake Windows build dependencies module
+
+include_guard(GLOBAL)
+
+include(buildspec_common)
+
+# _check_dependencies_windows: Set up Windows slice for _check_dependencies
+function(_check_dependencies_windows)
+  set(arch ${CMAKE_GENERATOR_PLATFORM})
+  set(platform windows-${arch})
+
+  set(dependencies_dir "${CMAKE_CURRENT_SOURCE_DIR}/.deps")
+  set(prebuilt_filename "windows-deps-VERSION-ARCH-REVISION.zip")
+  set(prebuilt_destination "obs-deps-VERSION-ARCH")
+  set(qt6_filename "windows-deps-qt6-VERSION-ARCH-REVISION.zip")
+  set(qt6_destination "obs-deps-qt6-VERSION-ARCH")
+  set(obs-studio_filename "VERSION.zip")
+  set(obs-studio_destination "obs-studio-VERSION")
+  set(dependencies_list prebuilt qt6 obs-studio)
+
+  _check_dependencies()
+endfunction()
+
+_check_dependencies_windows()

+ 35 - 0
cmake/windows/compilerconfig.cmake

@@ -0,0 +1,35 @@
+# CMake Windows compiler configuration module
+
+include_guard(GLOBAL)
+
+include(compiler_common)
+
+# CMake 3.24 introduces a bug mistakenly interpreting MSVC as supporting the '-pthread' compiler flag
+if(CMAKE_VERSION VERSION_EQUAL 3.24.0)
+  set(THREADS_HAVE_PTHREAD_ARG FALSE)
+endif()
+
+message(DEBUG "Current Windows API version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
+if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM)
+  message(DEBUG "Maximum Windows API version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM}")
+endif()
+
+if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION VERSION_LESS 10.0.20348)
+  message(FATAL_ERROR "OBS requires Windows 10 SDK version 10.0.20348.0 or more recent.\n"
+                      "Please download and install the most recent Windows platform SDK.")
+endif()
+
+add_compile_options(
+  /W3 /utf-8 "$<$<COMPILE_LANG_AND_ID:C,MSVC>:/MP>" "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/MP>"
+  "$<$<COMPILE_LANG_AND_ID:C,Clang>:${_obs_clang_c_options}>"
+  "$<$<COMPILE_LANG_AND_ID:CXX,Clang>:${_obs_clang_cxx_options}>")
+
+add_compile_definitions(UNICODE _UNICODE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS $<$<CONFIG:DEBUG>:DEBUG>
+                        $<$<CONFIG:DEBUG>:_DEBUG>)
+
+add_link_options("$<$<NOT:$<CONFIG:Debug>>:/OPT:REF>" "$<$<CONFIG:Debug>:/INCREMENTAL:NO>"
+                 "$<$<CONFIG:RelWithDebInfo>:/INCREMENTAL:NO>" "$<$<CONFIG:RelWithDebInfo>:/OPT:ICF>")
+
+if(CMAKE_COMPILE_WARNING_AS_ERROR)
+  add_link_options(/WX)
+endif()

+ 8 - 0
cmake/windows/defaults.cmake

@@ -0,0 +1,8 @@
+# CMake Windows defaults module
+
+include_guard(GLOBAL)
+
+# Enable find_package targets to become globally available targets
+set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL TRUE)
+
+include(buildspec)

+ 130 - 0
cmake/windows/helpers.cmake

@@ -0,0 +1,130 @@
+# CMake Windows helper functions module
+
+# cmake-format: off
+# cmake-lint: disable=C0103
+# cmake-format: on
+
+include_guard(GLOBAL)
+
+include(helpers_common)
+
+# set_target_properties_plugin: Set target properties for use in obs-studio
+function(set_target_properties_plugin target)
+  set(options "")
+  set(oneValueArgs "")
+  set(multiValueArgs PROPERTIES)
+  cmake_parse_arguments(PARSE_ARGV 0 _STPO "${options}" "${oneValueArgs}" "${multiValueArgs}")
+
+  message(DEBUG "Setting additional properties for target ${target}...")
+
+  while(_STPO_PROPERTIES)
+    list(POP_FRONT _STPO_PROPERTIES key value)
+    set_property(TARGET ${target} PROPERTY ${key} "${value}")
+  endwhile()
+
+  string(TIMESTAMP CURRENT_YEAR "%Y")
+
+  set_target_properties(${target} PROPERTIES VERSION 0 SOVERSION ${PLUGIN_VERSION})
+
+  install(
+    TARGETS ${target}
+    RUNTIME DESTINATION bin/64bit
+    LIBRARY DESTINATION obs-plugins/64bit)
+
+  install(
+    FILES "$<TARGET_PDB_FILE:${target}>"
+    CONFIGURATIONS RelWithDebInfo Debug
+    DESTINATION obs-plugins/64bit
+    OPTIONAL)
+
+  if(OBS_BUILD_DIR)
+    add_custom_command(
+      TARGET ${target}
+      POST_BUILD
+      COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_BUILD_DIR}/obs-plugins/64bit"
+      COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:${target}>"
+              "$<$<CONFIG:Debug,RelWithDebInfo>:$<TARGET_PDB_FILE:${target}>>" "${OBS_BUILD_DIR}/obs-plugin/64bit"
+      COMMENT "Copy ${target} to obs-studio directory ${OBS_BUILD_DIR}"
+      VERBATIM)
+  endif()
+
+  if(TARGET plugin-support)
+    target_link_libraries(${target} PRIVATE plugin-support)
+  endif()
+
+  target_install_resources(${target})
+
+  get_target_property(target_sources ${target} SOURCES)
+  set(target_ui_files ${target_sources})
+  list(FILTER target_ui_files INCLUDE REGEX ".+\\.(ui|qrc)")
+  source_group(
+    TREE "${CMAKE_CURRENT_SOURCE_DIR}"
+    PREFIX "UI Files"
+    FILES ${target_ui_files})
+
+  set(valid_uuid FALSE)
+  check_uuid(${_windowsAppUUID} valid_uuid)
+  if(NOT valid_uuid)
+    message(FATAL_ERROR "Specified Windows package UUID is not a valid UUID value: ${_windowsAppUUID}")
+  else()
+    set(UUID_APP ${_windowsAppUUID})
+  endif()
+
+  configure_file(cmake/windows/resources/installer-Windows.iss.in
+                 "${CMAKE_CURRENT_BINARY_DIR}/installer-Windows.generated.iss")
+
+  configure_file(cmake/windows/resources/resource.rc.in "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.rc")
+  target_sources(${CMAKE_PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.rc")
+endfunction()
+
+# Helper function to add resources into bundle
+function(target_install_resources target)
+  message(DEBUG "Installing resources for target ${target}...")
+  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/data")
+    file(GLOB_RECURSE data_files "${CMAKE_CURRENT_SOURCE_DIR}/data/*")
+    foreach(data_file IN LISTS data_files)
+      cmake_path(RELATIVE_PATH data_file BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/" OUTPUT_VARIABLE
+                 relative_path)
+      cmake_path(GET relative_path PARENT_PATH relative_path)
+      target_sources(${target} PRIVATE "${data_file}")
+      source_group("Resources/${relative_path}" FILES "${data_file}")
+    endforeach()
+
+    install(
+      DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/"
+      DESTINATION data/obs-plugins/${target}
+      USE_SOURCE_PERMISSIONS)
+
+    if(OBS_BUILD_DIR)
+      add_custom_command(
+        TARGET ${target}
+        POST_BUILD
+        COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_BUILD_DIR}/data/obs-plugins/${target}"
+        COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/data"
+                "${OBS_BUILD_DIR}/data/obs-plugins/${target}"
+        COMMENT "Copy ${target} resources to data directory"
+        VERBATIM)
+    endif()
+  endif()
+endfunction()
+
+# Helper function to add a specific resource to a bundle
+function(target_add_resource target resource)
+  message(DEBUG "Add resource '${resource}' to target ${target} at destination '${target_destination}'...")
+
+  install(
+    FILES "${resource}"
+    DESTINATION data/obs-plugins/${target}
+    COMPONENT Runtime)
+
+  if(OBS_BUILD_DIR)
+    add_custom_command(
+      TARGET ${target}
+      POST_BUILD
+      COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_BUILD_DIR}/data/obs-plugins/${target}"
+      COMMAND "${CMAKE_COMMAND}" -E copy "${resource}" "${OBS_BUILD_DIR}/data/obs-plugins/${target}"
+      COMMENT "Copy ${target} resource ${resource} to library directory"
+      VERBATIM)
+  endif()
+  source_group("Resources" FILES "${resource}")
+endfunction()

+ 64 - 0
cmake/windows/resources/installer-Windows.iss.in

@@ -0,0 +1,64 @@
+#define MyAppName "@CMAKE_PROJECT_NAME@"
+#define MyAppVersion "@CMAKE_PROJECT_VERSION@"
+#define MyAppPublisher "@PLUGIN_AUTHOR@"
+#define MyAppURL "@PLUGIN_WEBSITE@"
+
+[Setup]
+; NOTE: The value of AppId uniquely identifies this application.
+; Do not use the same AppId value in installers for other applications.
+; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
+AppId={{@UUID_APP@}
+AppName={#MyAppName}
+AppVersion={#MyAppVersion}
+AppPublisher={#MyAppPublisher}
+AppPublisherURL={#MyAppURL}
+AppSupportURL={#MyAppURL}
+AppUpdatesURL={#MyAppURL}
+DefaultDirName={code:GetDirName}
+DefaultGroupName={#MyAppName}
+OutputBaseFilename={#MyAppName}-{#MyAppVersion}-Windows-Installer
+Compression=lzma
+SolidCompression=yes
+DirExistsWarning=no
+
+[Languages]
+Name: "english"; MessagesFile: "compiler:Default.isl"
+
+[Files]
+Source: "..\release\Package\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
+Source: "..\LICENSE"; Flags: dontcopy
+; NOTE: Don't use "Flags: ignoreversion" on any shared system files
+
+[Icons]
+Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}"
+Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
+
+[Code]
+procedure InitializeWizard();
+var
+  GPLText: AnsiString;
+  Page: TOutputMsgMemoWizardPage;
+begin
+  ExtractTemporaryFile('LICENSE');
+  LoadStringFromFile(ExpandConstant('{tmp}\LICENSE'), GPLText);
+  Page := CreateOutputMsgMemoPage(wpWelcome,
+    'License Information', 'Please review the license terms before installing {#MyAppName}',
+    'Press Page Down to see the rest of the agreement. Once you are aware of your rights, click Next to continue.',
+    String(GPLText)
+  );
+end;
+
+// credit where it's due :
+// following function come from https://github.com/Xaymar/obs-studio_amf-encoder-plugin/blob/master/%23Resources/Installer.in.iss#L45
+function GetDirName(Value: string): string;
+var
+  InstallPath: string;
+begin
+  // initialize default path, which will be returned when the following registry
+  // key queries fail due to missing keys or for some different reason
+  Result := '{autopf}\obs-studio';
+  // query the first registry value; if this succeeds, return the obtained value
+  if RegQueryStringValue(HKLM32, 'SOFTWARE\OBS Studio', '', InstallPath) then
+    Result := InstallPath
+end;
+

+ 32 - 0
cmake/windows/resources/resource.rc.in

@@ -0,0 +1,32 @@
+1 VERSIONINFO
+ FILEVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0
+ PRODUCTVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0
+ FILEFLAGSMASK 0x0L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x0L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "040904b0"
+        BEGIN
+            VALUE "CompanyName", "${PLUGIN_AUTHOR}"
+            VALUE "FileDescription", "${PROJECT_NAME}"
+            VALUE "FileVersion", "${PROJECT_VERSION}"
+            VALUE "InternalName", "${PROJECT_NAME}"
+            VALUE "LegalCopyright", "(C) ${CURRENT_YEAR} ${PLUGIN_AUTHOR}"
+            VALUE "OriginalFilename", "${PROJECT_NAME}"
+            VALUE "ProductName", "${PROJECT_NAME}"
+            VALUE "ProductVersion", "${PROJECT_VERSION}"
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x409, 1200
+    END
+END