2019-10-15 21:08:45 -07:00
cmake_minimum_required ( VERSION 3.10 )
2014-01-20 07:58:58 -08:00
2018-08-07 16:22:00 -07:00
if ( UNIX AND POLICY CMP0072 )
# In case of both legacy and glvnd OpenGL libraries found. Prefer GLVND
cmake_policy ( SET CMP0072 NEW )
endif ( )
2014-01-20 07:58:58 -08:00
project ( obs-studio )
2020-10-14 18:42:22 -07:00
option ( DEBUG_FFMPEG_MUX "Debug FFmpeg muxer subprocess" FALSE )
2016-12-23 09:17:31 -08:00
2020-05-13 06:37:01 -07:00
set_property ( GLOBAL PROPERTY USE_FOLDERS ON )
2016-09-02 07:40:58 -07:00
if ( WIN32 )
2020-02-20 22:53:57 -08:00
cmake_minimum_required ( VERSION 3.16 )
2020-02-20 22:55:00 -08:00
2020-06-03 15:06:31 -07:00
# Check for Win SDK version 10.0.19041 or above
2020-02-20 22:55:00 -08:00
if ( MSVC AND MSVC_VERSION LESS 1920 )
message ( STATUS "Windows API version is ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}" )
string ( REPLACE "." ";" WINAPI_VER "${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}" )
list ( GET WINAPI_VER 0 WINAPI_VER_MAJOR )
list ( GET WINAPI_VER 1 WINAPI_VER_MINOR )
list ( GET WINAPI_VER 2 WINAPI_VER_BUILD )
set ( WINAPI_COMPATIBLE FALSE )
if ( WINAPI_VER_MAJOR EQUAL 10 )
if ( WINAPI_VER_MINOR EQUAL 0 )
2020-06-03 15:06:31 -07:00
if ( WINAPI_VER_BUILD GREATER_EQUAL 19041 )
2020-02-20 22:55:00 -08:00
set ( WINAPI_COMPATIBLE TRUE )
endif ( )
else ( )
set ( WINAPI_COMPATIBLE TRUE )
endif ( )
elseif ( WINAPI_VER_MAJOR GREATER 10 )
set ( WINAPI_COMPATIBLE TRUE )
endif ( )
if ( NOT WINAPI_COMPATIBLE )
2020-06-03 15:06:31 -07:00
message ( FATAL_ERROR "OBS requires Windows 10 SDK version 10.0.19041.0 and above to compile.\nPlease download the most recent Windows 10 SDK in order to compile (or update to Visual Studio 2019)." )
2020-02-20 22:55:00 -08:00
endif ( )
endif ( )
2016-09-02 07:40:58 -07:00
if ( QTDIR OR DEFINED ENV{QTDIR} OR DEFINED ENV{QTDIR32} OR DEFINED ENV{QTDIR64} )
# Qt path set by user or env var
else ( )
set ( QTDIR "" CACHE PATH "Path to Qt (e.g. C:/Qt/5.7/msvc2015_64)" )
message ( WARNING "QTDIR variable is missing. Please set this variable to specify path to Qt (e.g. C:/Qt/5.7/msvc2015_64)" )
endif ( )
if ( DepsPath OR DEFINED ENV{DepsPath} OR DEFINED ENV{DepsPath32} OR DEFINED ENV{DepsPath64} )
# Dependencies path set by user or env var
else ( )
set ( DepsPath "" CACHE PATH "Path to compiled dependencies (e.g. D:/dependencies/win64)" )
message ( WARNING "DepsPath variable is missing. Please set this variable to specify path to compiled dependencies (e.g. D:/dependencies/win64)" )
endif ( )
endif ( )
2014-01-20 07:58:58 -08:00
set ( CMAKE_MODULE_PATH ${ CMAKE_MODULE_PATH } "${CMAKE_SOURCE_DIR}/cmake/Modules/" )
2018-01-23 20:57:48 -08:00
set ( ENABLE_SCRIPTING TRUE CACHE BOOL "Enables scripting" )
2019-07-20 23:47:01 -07:00
set ( SCRIPTING_ENABLED OFF CACHE BOOL "Internal global cmake variable" FORCE )
2014-01-20 07:58:58 -08:00
2014-01-24 18:44:34 -08:00
include ( ObsHelpers )
2014-01-29 05:56:06 -08:00
include ( ObsCpack )
2016-06-07 07:18:55 -07:00
include ( GNUInstallDirs )
2020-08-18 05:50:50 -07:00
include ( CheckCCompilerFlag )
include ( CheckCXXCompilerFlag )
2014-01-29 05:56:06 -08:00
2018-08-13 00:24:30 -07:00
# Must be a string in the format of "x.x.x-rcx"
if ( DEFINED RELEASE_CANDIDATE )
set ( OBS_VERSION "${RELEASE_CANDIDATE}" )
string ( REPLACE "-rc" "." RC_SPLIT ${ RELEASE_CANDIDATE } )
string ( REPLACE "." ";" RC_SPLIT ${ RC_SPLIT } )
message ( WARNING "******************************************************************************\nRelease candidate deteced, OBS_VERSION is now: ${OBS_VERSION}\n******************************************************************************" )
list ( GET RC_SPLIT 0 OBS_RELEASE_CANDIDATE_MAJOR )
list ( GET RC_SPLIT 1 OBS_RELEASE_CANDIDATE_MINOR )
list ( GET RC_SPLIT 2 OBS_RELEASE_CANDIDATE_PATCH )
list ( GET RC_SPLIT 3 OBS_RELEASE_CANDIDATE )
else ( )
set ( OBS_RELEASE_CANDIDATE_MAJOR 0 )
set ( OBS_RELEASE_CANDIDATE_MINOR 0 )
set ( OBS_RELEASE_CANDIDATE_PATCH 0 )
set ( OBS_RELEASE_CANDIDATE 0 )
endif ( )
2019-03-15 20:28:19 -07:00
# Binary Versioning for Windows
if ( WIN32 )
string ( REPLACE "-" ";" UI_VERSION_SPLIT ${ OBS_VERSION } )
list ( GET UI_VERSION_SPLIT 0 UI_VERSION )
string ( REPLACE "." ";" UI_VERSION_SEMANTIC ${ UI_VERSION } )
list ( GET UI_VERSION_SEMANTIC 0 UI_VERSION_MAJOR )
list ( GET UI_VERSION_SEMANTIC 1 UI_VERSION_MINOR )
list ( GET UI_VERSION_SEMANTIC 2 UI_VERSION_PATCH )
2019-06-16 04:42:58 -07:00
set ( OBS_COMPANY_NAME "OBS" )
set ( OBS_PRODUCT_NAME "OBS Studio" )
set ( OBS_COMMENTS "Free and open source software for video recording and live streaming" )
set ( OBS_LEGAL_COPYRIGHT "(C) Hugh Bailey" )
set ( MODULE_DESCRIPTION "OBS Studio" )
2019-03-15 20:28:19 -07:00
configure_file ( UI/obs.rc.in ${ PROJECT_BINARY_DIR } /obs.rc )
endif ( )
2014-01-30 16:59:22 -08:00
if ( MSVC AND NOT EXISTS "${CMAKE_BINARY_DIR}/ALL_BUILD.vcxproj.user" )
file ( GENERATE
O U T P U T " $ { C M A K E _ B I N A R Y _ D I R } / A L L _ B U I L D . v c x p r o j . u s e r "
I N P U T " $ { C M A K E _ S O U R C E _ D I R } / c m a k e / A L L _ B U I L D . v c x p r o j . u s e r . i n " )
2014-01-20 07:58:58 -08:00
endif ( )
if ( NOT CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE RelWithDebInfo )
endif ( )
2019-10-15 21:08:45 -07:00
set ( CMAKE_CXX_STANDARD 17 )
set ( CMAKE_CXX_STANDARD_REQUIRED YES )
set ( CMAKE_CXX_EXTENSIONS NO )
2014-01-20 07:58:58 -08:00
if ( ${ CMAKE_C_COMPILER_ID } MATCHES "Clang" OR ${ CMAKE_CXX_COMPILER_ID } MATCHES "Clang" )
set ( CMAKE_COMPILER_IS_CLANG TRUE )
endif ( )
2020-01-21 21:56:34 -08:00
if ( MSVC_CXX_ARCHITECTURE_ID )
string ( TOLOWER ${ MSVC_CXX_ARCHITECTURE_ID } LOWERCASE_CMAKE_SYSTEM_PROCESSOR )
else ( )
string ( TOLOWER ${ CMAKE_SYSTEM_PROCESSOR } LOWERCASE_CMAKE_SYSTEM_PROCESSOR )
endif ( )
2020-08-18 05:57:05 -07:00
if ( LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(i[3-6]86|x86|x64|x86_64|amd64|e2k)" )
2020-01-21 21:56:34 -08:00
if ( NOT MSVC )
set ( ARCH_SIMD_FLAGS "-mmmx" "-msse" "-msse2" )
endif ( )
elseif ( LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64(le)?" )
2020-12-12 20:36:40 -08:00
set ( ARCH_SIMD_DEFINES "-DNO_WARN_X86_INTRINSICS" )
2020-01-21 21:56:34 -08:00
set ( ARCH_SIMD_FLAGS "-mvsx" )
2018-12-16 10:33:16 -08:00
add_compile_definitions ( NO_WARN_X86_INTRINSICS )
2020-01-21 21:56:34 -08:00
else ( )
2020-05-29 02:18:44 -07:00
if ( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
2020-08-18 05:50:50 -07:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSIMDE_ENABLE_OPENMP" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSIMDE_ENABLE_OPENMP" )
CHECK_C_COMPILER_FLAG ( "-fopenmp-simd" C_COMPILER_SUPPORTS_OPENMP_SIMD )
if ( C_COMPILER_SUPPORTS_OPENMP_SIMD )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp-simd" )
endif ( )
CHECK_CXX_COMPILER_FLAG ( "-fopenmp-simd" CXX_COMPILER_SUPPORTS_OPENMP_SIMD )
if ( CXX_COMPILER_SUPPORTS_OPENMP_SIMD )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp-simd" )
endif ( )
2020-05-29 02:18:44 -07:00
endif ( )
2020-01-21 21:56:34 -08:00
set ( ARCH_SIMD_FLAGS "" )
message ( STATUS "No Native SSE2 SIMD Support - Using SIMDE" )
2018-12-16 10:33:16 -08:00
endif ( )
2014-01-20 07:58:58 -08:00
if ( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG )
2019-08-21 09:29:34 -07:00
set ( CMAKE_CXX_FLAGS "-Wall -Wextra -Wvla -Wno-unused-function -Wno-missing-field-initializers ${CMAKE_CXX_FLAGS} -fno-strict-aliasing" )
2018-09-02 14:10:36 -07:00
set ( CMAKE_C_FLAGS "-Wall -Wextra -Wvla -Wno-unused-function -Werror-implicit-function-declaration -Wno-missing-braces -Wno-missing-field-initializers ${CMAKE_C_FLAGS} -std=gnu99 -fno-strict-aliasing" )
2014-03-30 18:53:50 -07:00
2014-01-20 07:58:58 -08:00
option ( USE_LIBC++ "Use libc++ instead of libstdc++" ${ APPLE } )
if ( USE_LIBC++ )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++" )
endif ( )
2014-06-25 00:38:23 -07:00
elseif ( MSVC )
if ( CMAKE_CXX_FLAGS MATCHES "/W[0-4]" )
string ( REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
else ( )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" )
endif ( )
# Disable pointless constant condition warnings
2018-03-12 16:16:38 -07:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4127 /wd4201 /wd4456 /wd4457 /wd4458 /wd4459 /wd4595" )
2014-01-20 07:58:58 -08:00
endif ( )
if ( WIN32 )
2017-06-27 09:54:53 -07:00
add_definitions ( -DUNICODE -D_UNICODE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS )
2014-01-20 07:58:58 -08:00
endif ( )
2014-04-05 07:32:48 -07:00
if ( MSVC )
2019-01-30 20:57:42 -08:00
add_compile_options ( "/MP" )
2014-04-05 07:32:48 -07:00
set ( CMAKE_C_FLAGS_DEBUG "/DDEBUG=1 /D_DEBUG=1 ${CMAKE_C_FLAGS_DEBUG}" )
set ( CMAKE_CXX_FLAGS_DEBUG "/DDEBUG=1 /D_DEBUG=1 ${CMAKE_C_FLAGS_DEBUG}" )
2014-09-16 01:37:08 -07:00
if ( NOT CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO" )
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO" )
set ( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO" )
endif ( )
2020-03-03 20:14:28 -08:00
2020-03-03 23:13:03 -08:00
foreach ( t EXE SHARED MODULE )
set ( CMAKE_ ${ t } _LINKER_FLAGS "${CMAKE_${t}_LINKER_FLAGS} /OPT:REF" )
set ( CMAKE_ ${ t } _LINKER_FLAGS_DEBUG "${CMAKE_${t}_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO" )
set ( CMAKE_ ${ t } _LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_${t}_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO" )
endforeach ( )
2014-04-05 07:32:48 -07:00
else ( )
2015-02-03 21:08:54 -08:00
if ( MINGW )
2015-03-04 02:28:13 -08:00
set ( CMAKE_WIDL "widl" CACHE STRING "wine IDL header file generation program" )
2015-02-03 21:08:54 -08:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_WIN32_WINNT=0x0600 -DWINVER=0x0600" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=0x0600 -DWINVER=0x0600" )
endif ( )
2014-04-05 07:32:48 -07:00
set ( CMAKE_C_FLAGS_DEBUG "-DDEBUG=1 -D_DEBUG=1 ${CMAKE_C_FLAGS_DEBUG}" )
set ( CMAKE_CXX_FLAGS_DEBUG "-DDEBUG=1 -D_DEBUG=1 ${CMAKE_C_FLAGS_DEBUG}" )
endif ( )
2014-01-20 07:58:58 -08:00
if ( APPLE )
set ( CMAKE_MACOSX_RPATH TRUE )
set ( CMAKE_BUILD_WITH_INSTALL_RPATH TRUE )
2014-01-27 23:43:59 -08:00
list ( APPEND CMAKE_INSTALL_RPATH "@loader_path/" "@executable_path/" )
2015-01-29 18:02:46 -08:00
elseif ( UNIX )
option ( USE_XDG "Utilize XDG Base Directory Specification" ON )
if ( USE_XDG )
add_definitions ( -DUSE_XDG )
endif ( )
if ( NOT UNIX_STRUCTURE )
list ( APPEND CMAKE_INSTALL_RPATH "$ORIGIN" )
endif ( )
2014-01-20 07:58:58 -08:00
endif ( )
2020-08-18 06:50:46 -07:00
if ( LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "e2k" )
foreach ( TEST_C_FLAG "-Wno-unused-parameter" "-Wno-ignored-qualifiers" "-Wno-pointer-sign" "-Wno-unused-variable" "-Wno-sign-compare" "-Wno-bad-return-value-type" "-Wno-maybe-uninitialized" )
CHECK_C_COMPILER_FLAG ( ${ TEST_C_FLAG } C_COMPILER_SUPPORTS_FLAG_ ${ TEST_C_FLAG } )
if ( C_COMPILER_SUPPORTS_FLAG_ ${ TEST_C_FLAG } )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEST_C_FLAG}" )
endif ( )
endforeach ( )
foreach ( TEST_CXX_FLAG "-Wno-invalid-offsetof" "-Wno-maybe-uninitialized" )
CHECK_CXX_COMPILER_FLAG ( ${ TEST_CXX_FLAG } CXX_COMPILER_SUPPORTS_FLAG_ ${ TEST_CXX_FLAG } )
if ( CXX_COMPILER_SUPPORTS_FLAG_ ${ TEST_CXX_FLAG } )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TEST_CXX_FLAG}" )
endif ( )
endforeach ( )
endif ( )
2015-05-21 15:24:17 -07:00
option ( BUILD_TESTS "Build test directory (includes test sources and possibly a platform test executable)" FALSE )
mark_as_advanced ( BUILD_TESTS )
2014-01-24 18:44:34 -08:00
if ( NOT INSTALLER_RUN )
2017-12-25 13:06:41 -08:00
option ( ENABLE_UI "Enables the OBS user interfaces" ON )
if ( DISABLE_UI OR NOT ENABLE_UI )
set ( UI_ENABLED FALSE )
else ( )
set ( UI_ENABLED TRUE )
2018-09-18 09:47:18 -07:00
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( _lib_suffix 64 )
else ( )
set ( _lib_suffix 32 )
endif ( )
if ( DEFINED QTDIR ${ _lib_suffix } )
list ( APPEND CMAKE_PREFIX_PATH "${QTDIR${_lib_suffix}}" )
elseif ( DEFINED QTDIR )
list ( APPEND CMAKE_PREFIX_PATH "${QTDIR}" )
elseif ( DEFINED ENV{QTDIR ${ _lib_suffix } } )
list ( APPEND CMAKE_PREFIX_PATH "$ENV{QTDIR${_lib_suffix}}" )
elseif ( DEFINED ENV{QTDIR} )
list ( APPEND CMAKE_PREFIX_PATH "$ENV{QTDIR}" )
endif ( )
find_package ( Qt5Widgets ${ FIND_MODE } )
2017-12-25 13:06:41 -08:00
endif ( )
2014-04-01 13:11:44 -07:00
2017-12-25 13:06:41 -08:00
add_subdirectory ( deps )
2014-01-20 07:58:58 -08:00
2014-01-24 18:44:34 -08:00
if ( WIN32 )
add_subdirectory ( libobs-d3d11 )
2019-11-27 16:38:10 -08:00
add_subdirectory ( libobs-winrt )
2014-01-24 18:44:34 -08:00
endif ( )
2014-01-20 07:58:58 -08:00
2014-01-24 18:44:34 -08:00
add_subdirectory ( libobs-opengl )
2015-01-09 11:19:22 -08:00
add_subdirectory ( libobs )
2014-01-24 18:44:34 -08:00
add_subdirectory ( plugins )
2018-09-18 08:54:30 -07:00
add_subdirectory ( UI )
2020-04-19 10:35:43 -07:00
if ( ENABLE_UNIT_TESTS )
enable_testing ( )
endif ( )
if ( BUILD_TESTS OR ENABLE_UNIT_TESTS )
2015-05-12 09:40:09 -07:00
add_subdirectory ( test )
endif ( )
2014-04-13 11:05:46 -07:00
add_subdirectory ( cmake/helper_subdir )
2014-01-24 18:44:34 -08:00
else ( )
obs_generate_multiarch_installer ( )
endif ( )
2014-07-18 15:15:49 -07:00
include ( CopyMSVCBins )