CMakeLists.txt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. cmake_minimum_required(VERSION 2.8.12)
  2. project(obs-studio)
  3. option(BUILD_CAPTIONS "Build captions" FALSE)
  4. if(WIN32)
  5. if (QTDIR OR DEFINED ENV{QTDIR} OR DEFINED ENV{QTDIR32} OR DEFINED ENV{QTDIR64})
  6. # Qt path set by user or env var
  7. else()
  8. set(QTDIR "" CACHE PATH "Path to Qt (e.g. C:/Qt/5.7/msvc2015_64)")
  9. message(WARNING "QTDIR variable is missing. Please set this variable to specify path to Qt (e.g. C:/Qt/5.7/msvc2015_64)")
  10. endif()
  11. if (DepsPath OR DEFINED ENV{DepsPath} OR DEFINED ENV{DepsPath32} OR DEFINED ENV{DepsPath64})
  12. # Dependencies path set by user or env var
  13. else()
  14. set(DepsPath "" CACHE PATH "Path to compiled dependencies (e.g. D:/dependencies/win64)")
  15. message(WARNING "DepsPath variable is missing. Please set this variable to specify path to compiled dependencies (e.g. D:/dependencies/win64)")
  16. endif()
  17. endif()
  18. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
  19. set(ENABLE_SCRIPTING TRUE CACHE BOOL "Enables scripting")
  20. set(SCRIPTING_ENABLED OFF CACHE BOOL "Interal global cmake variable" FORCE)
  21. include(ObsHelpers)
  22. include(ObsCpack)
  23. include(GNUInstallDirs)
  24. if(MSVC AND NOT EXISTS "${CMAKE_BINARY_DIR}/ALL_BUILD.vcxproj.user")
  25. file(GENERATE
  26. OUTPUT "${CMAKE_BINARY_DIR}/ALL_BUILD.vcxproj.user"
  27. INPUT "${CMAKE_SOURCE_DIR}/cmake/ALL_BUILD.vcxproj.user.in")
  28. endif()
  29. if(NOT CMAKE_BUILD_TYPE)
  30. set(CMAKE_BUILD_TYPE RelWithDebInfo)
  31. endif()
  32. find_package(CXX11 REQUIRED)
  33. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_FLAGS}")
  34. if(${CMAKE_C_COMPILER_ID} MATCHES "Clang" OR ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
  35. set(CMAKE_COMPILER_IS_CLANG TRUE)
  36. endif()
  37. if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
  38. set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-function -Werror-implicit-function-declaration -Wno-missing-field-initializers ${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
  39. set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-function -Werror-implicit-function-declaration -Wno-missing-braces -Wno-missing-field-initializers ${CMAKE_C_FLAGS} -std=gnu99 -fno-strict-aliasing")
  40. option(USE_LIBC++ "Use libc++ instead of libstdc++" ${APPLE})
  41. if(USE_LIBC++)
  42. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  43. endif()
  44. elseif(MSVC)
  45. if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
  46. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  47. else()
  48. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
  49. endif()
  50. # Disable pointless constant condition warnings
  51. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4127 /wd4201 /wd4456 /wd4457 /wd4458 /wd4459 /wd4595")
  52. endif()
  53. if(WIN32)
  54. add_definitions(-DUNICODE -D_UNICODE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
  55. endif()
  56. if(MSVC)
  57. set(CMAKE_C_FLAGS_DEBUG "/DDEBUG=1 /D_DEBUG=1 ${CMAKE_C_FLAGS_DEBUG}")
  58. set(CMAKE_CXX_FLAGS_DEBUG "/DDEBUG=1 /D_DEBUG=1 ${CMAKE_C_FLAGS_DEBUG}")
  59. if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
  60. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
  61. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
  62. set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
  63. endif()
  64. else()
  65. if(MINGW)
  66. set(CMAKE_WIDL "widl" CACHE STRING "wine IDL header file generation program")
  67. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_WIN32_WINNT=0x0600 -DWINVER=0x0600")
  68. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=0x0600 -DWINVER=0x0600")
  69. endif()
  70. set(CMAKE_C_FLAGS_DEBUG "-DDEBUG=1 -D_DEBUG=1 ${CMAKE_C_FLAGS_DEBUG}")
  71. set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG=1 -D_DEBUG=1 ${CMAKE_C_FLAGS_DEBUG}")
  72. endif()
  73. if(APPLE)
  74. set(CMAKE_MACOSX_RPATH TRUE)
  75. set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  76. list(APPEND CMAKE_INSTALL_RPATH "@loader_path/" "@executable_path/")
  77. elseif(UNIX)
  78. option(USE_XDG "Utilize XDG Base Directory Specification" ON)
  79. if(USE_XDG)
  80. add_definitions(-DUSE_XDG)
  81. endif()
  82. if(NOT UNIX_STRUCTURE)
  83. list(APPEND CMAKE_INSTALL_RPATH "$ORIGIN")
  84. endif()
  85. endif()
  86. option(BUILD_TESTS "Build test directory (includes test sources and possibly a platform test executable)" FALSE)
  87. mark_as_advanced(BUILD_TESTS)
  88. if(NOT INSTALLER_RUN)
  89. option(ENABLE_UI "Enables the OBS user interfaces" ON)
  90. if(DISABLE_UI OR NOT ENABLE_UI)
  91. set(UI_ENABLED FALSE)
  92. else()
  93. set(UI_ENABLED TRUE)
  94. endif()
  95. add_subdirectory(deps)
  96. if(WIN32)
  97. add_subdirectory(libobs-d3d11)
  98. endif()
  99. add_subdirectory(libobs-opengl)
  100. add_subdirectory(libobs)
  101. add_subdirectory(UI)
  102. add_subdirectory(plugins)
  103. if (BUILD_TESTS)
  104. add_subdirectory(test)
  105. endif()
  106. add_subdirectory(cmake/helper_subdir)
  107. else()
  108. obs_generate_multiarch_installer()
  109. endif()
  110. include(CopyMSVCBins)