CMakeLists.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. include(ObsHelpers)
  20. include(ObsCpack)
  21. include(GNUInstallDirs)
  22. if(MSVC AND NOT EXISTS "${CMAKE_BINARY_DIR}/ALL_BUILD.vcxproj.user")
  23. file(GENERATE
  24. OUTPUT "${CMAKE_BINARY_DIR}/ALL_BUILD.vcxproj.user"
  25. INPUT "${CMAKE_SOURCE_DIR}/cmake/ALL_BUILD.vcxproj.user.in")
  26. endif()
  27. if(NOT CMAKE_BUILD_TYPE)
  28. set(CMAKE_BUILD_TYPE RelWithDebInfo)
  29. endif()
  30. find_package(CXX11 REQUIRED)
  31. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_FLAGS}")
  32. if(${CMAKE_C_COMPILER_ID} MATCHES "Clang" OR ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
  33. set(CMAKE_COMPILER_IS_CLANG TRUE)
  34. endif()
  35. if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
  36. set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-function -Werror-implicit-function-declaration -Wno-missing-field-initializers ${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
  37. 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")
  38. option(USE_LIBC++ "Use libc++ instead of libstdc++" ${APPLE})
  39. if(USE_LIBC++)
  40. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  41. endif()
  42. elseif(MSVC)
  43. if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
  44. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  45. else()
  46. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
  47. endif()
  48. # Disable pointless constant condition warnings
  49. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4127 /wd4201")
  50. endif()
  51. if(WIN32)
  52. add_definitions(-DUNICODE -D_UNICODE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
  53. endif()
  54. if(MSVC)
  55. set(CMAKE_C_FLAGS_DEBUG "/DDEBUG=1 /D_DEBUG=1 ${CMAKE_C_FLAGS_DEBUG}")
  56. set(CMAKE_CXX_FLAGS_DEBUG "/DDEBUG=1 /D_DEBUG=1 ${CMAKE_C_FLAGS_DEBUG}")
  57. if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
  58. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
  59. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
  60. set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
  61. endif()
  62. else()
  63. if(MINGW)
  64. set(CMAKE_WIDL "widl" CACHE STRING "wine IDL header file generation program")
  65. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_WIN32_WINNT=0x0600 -DWINVER=0x0600")
  66. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=0x0600 -DWINVER=0x0600")
  67. endif()
  68. set(CMAKE_C_FLAGS_DEBUG "-DDEBUG=1 -D_DEBUG=1 ${CMAKE_C_FLAGS_DEBUG}")
  69. set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG=1 -D_DEBUG=1 ${CMAKE_C_FLAGS_DEBUG}")
  70. endif()
  71. if(APPLE)
  72. set(CMAKE_MACOSX_RPATH TRUE)
  73. set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  74. list(APPEND CMAKE_INSTALL_RPATH "@loader_path/" "@executable_path/")
  75. elseif(UNIX)
  76. option(USE_XDG "Utilize XDG Base Directory Specification" ON)
  77. if(USE_XDG)
  78. add_definitions(-DUSE_XDG)
  79. endif()
  80. if(NOT UNIX_STRUCTURE)
  81. list(APPEND CMAKE_INSTALL_RPATH "$ORIGIN")
  82. endif()
  83. endif()
  84. option(BUILD_TESTS "Build test directory (includes test sources and possibly a platform test executable)" FALSE)
  85. mark_as_advanced(BUILD_TESTS)
  86. if(NOT INSTALLER_RUN)
  87. add_subdirectory(deps)
  88. if(WIN32)
  89. add_subdirectory(libobs-d3d11)
  90. endif()
  91. add_subdirectory(libobs-opengl)
  92. add_subdirectory(libobs)
  93. add_subdirectory(UI)
  94. add_subdirectory(plugins)
  95. if (BUILD_TESTS)
  96. add_subdirectory(test)
  97. endif()
  98. add_subdirectory(cmake/helper_subdir)
  99. else()
  100. obs_generate_multiarch_installer()
  101. endif()
  102. include(CopyMSVCBins)