Merge pull request #23122 from joseluismarti/bionic
[xbmc.git] / CMakeLists.txt
blob1c678b169588d9aea2454bd9aedb596ad1b5ec6d
1 cmake_minimum_required(VERSION 3.12)
2 if(WIN32)
3   # Version 3.20 is required for multi-config generator expressions to work
4   cmake_minimum_required(VERSION 3.20)
5 endif()
6 project(kodi LANGUAGES CXX C ASM)
8 if(POLICY CMP0069)
9   set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
10   cmake_policy(SET CMP0069 NEW)
11 endif()
13 if(POLICY CMP0135)
14   set(CMAKE_POLICY_DEFAULT_CMP0135 NEW)
15   cmake_policy(SET CMP0135 NEW)
16 endif()
18 list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
19 list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules/buildtools)
20 if(DEPENDS_DIR)
21   list(APPEND CMAKE_PREFIX_PATH ${DEPENDS_DIR})
22 endif()
24 # Set CORE_BUILD_DIR
25 set(CORE_BUILD_DIR build)
26 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
28 message(STATUS "Source directory: ${CMAKE_SOURCE_DIR}")
29 message(STATUS "Build directory: ${CMAKE_BINARY_DIR}")
30 if(CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
31   message(WARNING "In-source build detected. It is recommended to build out-of-source.")
32 endif()
34 # Hide messages from Check*.cmake (e.g. CheckCSourceCompiles)
35 if(NOT VERBOSE)
36   set(CMAKE_REQUIRED_QUIET ON)
37 endif()
39 # Includes
40 include(cmake/modules/extra/ECMEnableSanitizers.cmake)
41 include(cmake/scripts/common/GeneratorSetup.cmake)
42 include(cmake/scripts/common/AddOptions.cmake)
43 include(cmake/scripts/common/Platform.cmake)
44 include(cmake/scripts/common/ArchSetup.cmake)
45 include(cmake/scripts/common/Macros.cmake)
46 include(cmake/scripts/common/ProjectMacros.cmake)
47 core_find_versions()
48 include(cmake/scripts/common/PathSetup.cmake)
49 include(cmake/scripts/common/CompilerSettings.cmake)
50 include(ExternalProject)
51 include(CMakeDependentOption)
52 include(cmake/scripts/common/DependencyOptions.cmake)
54 # general
55 option(VERBOSE            "Enable verbose output?" OFF)
56 option(ENABLE_CLANGTIDY   "Enable clang-tidy support?" OFF)
57 option(ENABLE_CPPCHECK    "Enable cppcheck support?" OFF)
58 option(ENABLE_DVDCSS      "Enable libdvdcss support?" ON)
59 option(ENABLE_INCLUDEWHATYOUUSE "Enable include-what-you-use support?" OFF)
60 option(ENABLE_UPNP        "Enable UPnP support?" ON)
61 option(ENABLE_AIRTUNES    "Enable AirTunes support?" ON)
62 option(ENABLE_OPTICAL     "Enable optical support?" ON)
63 option(ENABLE_PYTHON      "Enable python support?" ON)
64 option(ENABLE_TESTING     "Enable testing support?" ON)
66 # Internal Depends - supported on all platforms
68 # These are required enabled for all CI platforms, and recommended for all builds
69 option(ENABLE_INTERNAL_CROSSGUID "Enable internal crossguid?" ON)
70 option(ENABLE_INTERNAL_RapidJSON "Enable internal rapidjson?" ON)
72 # use ffmpeg from depends or system
73 option(ENABLE_INTERNAL_FFMPEG "Enable internal ffmpeg?" OFF)
75 # These are built for all platforms not using system libs or disabled by user
76 dependent_option(ENABLE_INTERNAL_FLATBUFFERS "Enable internal flatbuffers?")
77 dependent_option(ENABLE_INTERNAL_FMT "Enable internal fmt?")
78 dependent_option(ENABLE_INTERNAL_NFS "Enable internal libnfs?")
79 dependent_option(ENABLE_INTERNAL_PCRE "Enable internal pcre?")
80 dependent_option(ENABLE_INTERNAL_SPDLOG "Enable internal spdlog?")
81 dependent_option(ENABLE_INTERNAL_TAGLIB "Enable internal taglib?")
83 # Internal Depends - supported on UNIX platforms
84 if(UNIX)
85   option(FFMPEG_PATH        "Path to external ffmpeg?" "")
86   option(ENABLE_INTERNAL_FSTRCMP "Enable internal fstrcmp?" OFF)
87   option(ENABLE_INTERNAL_DAV1D "Enable internal dav1d?" OFF)
88   option(ENABLE_INTERNAL_GTEST "Enable internal gtest?" OFF)
89   option(ENABLE_INTERNAL_UDFREAD "Enable internal udfread?" OFF)
90 endif()
91 # prefer kissfft from xbmc/contrib but let use system one on unices
92 cmake_dependent_option(ENABLE_INTERNAL_KISSFFT "Enable internal kissfft?" ON "UNIX" ON)
93 # System options
94 if(NOT WIN32)
95   option(WITH_ARCH              "build with given arch" OFF)
96   option(WITH_CPU               "build with given cpu" OFF)
97 endif()
98 if(CORE_SYSTEM_NAME STREQUAL linux)
99   option(ENABLE_EVENTCLIENTS    "Enable event clients support?" OFF)
100   option(ADDONS_CONFIGURE_AT_STARTUP "Configure binary addons at startup?" ON)
101 endif()
103 # set scope of INTERNAL_DEPS
104 set_property(GLOBAL PROPERTY INTERNAL_DEPS_PROP)
106 # Build static libraries per directory
107 if(NOT CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT CMAKE_GENERATOR STREQUAL Xcode)
108   set(ENABLE_STATIC_LIBS TRUE)
109 else()
110   set(ENABLE_STATIC_LIBS FALSE)
111 endif()
113 core_find_git_rev(APP_SCMID FULL)
115 # Dynamically loaded libraries built with the project
116 add_custom_target(${APP_NAME_LC}-libraries)
117 set(LIBRARY_FILES "" CACHE STRING "" FORCE)
118 mark_as_advanced(LIBRARY_FILES)
120 set(INCLUDES ${CMAKE_SOURCE_DIR}
121              ${CMAKE_SOURCE_DIR}/lib
122              ${CMAKE_SOURCE_DIR}/xbmc
123              ${CMAKE_SOURCE_DIR}/xbmc/${PLATFORM_DIR}
124              ${CMAKE_SOURCE_DIR}/xbmc/cores/VideoPlayer
125              ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}
126              ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/include)
128 if (NOT PLATFORMDEFS_DIR STREQUAL "")
129   list(APPEND INCLUDES ${CMAKE_SOURCE_DIR}/xbmc/${PLATFORMDEFS_DIR})
130 endif()
132 find_package(PkgConfig)
133 set(THREADS_PREFER_PTHREAD_FLAG ON)
134 find_package(Threads REQUIRED QUIET)
135 list(APPEND DEPLIBS ${CMAKE_THREAD_LIBS_INIT})
138 foreach(depspec ${PLATFORM_REQUIRED_DEPS})
139   # We need to specify ENABLE_${PLATFORM_REQUIRED_DEPS} in order for the
140   # optional subdirectory for the specified platform to get built.
141   split_dependency_specification(${depspec} dep version)
142   string(TOUPPER ${dep} depup)
143   if(NOT ${ENABLE_${depup}} STREQUAL AUTO AND NOT ${ENABLE_${depup}})
144     message(WARNING "Your request to disable the dependency ${dep} required on platform ${CORE_PLATFORM_NAME} was ignored. Please choose another platform or add \"-DENABLE_${depup}=ON\" to your CMake command line to resolve this warning.")
145   endif()
146   set(ENABLE_${depup} "ON" CACHE BOOL "Force enabling required ${depup} support" FORCE)
147 endforeach()
149 # Required tools. Keep in alphabetical order please
150 set(required_buildtools FlatC
151                         JsonSchemaBuilder
152                         TexturePacker
155 # Optional build tools
156 set(optional_buildtools CCache
157                         ClangFormat
158                         ClangTidy
159                         Cppcheck
160                         IncludeWhatYouUse)
162 # Find build tools - Optional and required
163 core_optional_dep(${optional_buildtools})
164 core_require_dep(${required_buildtools})
166 # Required dependencies. Keep in alphabetical order please
167 set(required_deps ASS
168                   Cdio
169                   CrossGUID
170                   Curl
171                   FFMPEG
172                   FlatBuffers
173                   Fmt
174                   FreeType
175                   FriBidi
176                   Fstrcmp
177                   HarfBuzz
178                   Iconv
179                   KissFFT
180                   LibDvd
181                   Lzo2
182                   OpenSSL>=1.1.0
183                   PCRE
184                   RapidJSON
185                   Spdlog
186                   Sqlite3
187                   TagLib
188                   TinyXML
189                   ZLIB
190                   ${PLATFORM_REQUIRED_DEPS})
192 # Optional dependencies. Keep in alphabetical order please
193 set(optional_deps Alsa
194                   Avahi
195                   Bluetooth
196                   Bluray
197                   CAP
198                   CEC
199                   Dav1d
200                   DBus
201                   Iso9660pp
202                   LCMS2
203                   LircClient
204                   MDNS
205                   MicroHttpd
206                   NFS
207                   Pipewire>=0.3.50
208                   Plist
209                   PulseAudio
210                   Python
211                   SmbClient
212                   Sndio
213                   UDEV
214                   Udfread
215                   XSLT
216                   ${PLATFORM_OPTIONAL_DEPS})
218 # Check optional deps first, since their availability can influence required ones, e.g. ffmpeg
219 core_optional_dep(${optional_deps})
220 core_require_dep(${required_deps})
222 if(ENABLE_MARIADBCLIENT AND NOT ENABLE_MARIADBCLIENT STREQUAL AUTO AND ENABLE_MYSQLCLIENT AND NOT ENABLE_MYSQLCLIENT STREQUAL AUTO)
223   MESSAGE(FATAL_ERROR "You can not use MySql and MariaDB at the same time. Disable one by adding -DENABLE_MYSQLCLIENT=OFF or -DENABLE_MARIADBCLIENT=OFF.")
224 elseif(ENABLE_MYSQLCLIENT AND NOT ENABLE_MYSQLCLIENT STREQUAL AUTO)
225   set(ENABLE_MARIADBCLIENT OFF CACHE BOOL "")
226 endif()
228 core_optional_dep(MariaDBClient)
229 if(NOT MARIADBCLIENT_FOUND)
230   core_optional_dep(MySqlClient)
231 endif()
233 if(NOT UDEV_FOUND)
234   core_optional_dep(LibUSB)
235 endif()
237 if(ENABLE_UPNP)
238   list(APPEND DEP_DEFINES "-DHAS_UPNP=1")
239 endif()
241 if(ENABLE_OPTICAL)
242   list(APPEND DEP_DEFINES -DHAS_DVD_DRIVE -DHAS_CDDA_RIPPER)
243 endif()
245 if(ENABLE_AIRTUNES)
246   find_package(Shairplay)
247   if(SHAIRPLAY_FOUND)
248     core_require_dep(Shairplay)
249   endif()
250 endif()
252 # find all folders containing addon.xml.in
253 # used to define ADDON_XML_OUTPUTS, ADDON_XML_DEPENDS and ADDON_INSTALL_DATA
254 # Function defined in ./cmake/scripts/common/Macros.cmake
255 set(outputFilterRegex "addons/xbmc.json")
256 find_addon_xml_in_files(${outputFilterRegex})
258 # Compile Info
259 add_custom_command(OUTPUT ${CORE_BUILD_DIR}/xbmc/CompileInfo.cpp
260                           ${ADDON_XML_OUTPUTS}
261                    COMMAND ${CMAKE_COMMAND} -DCORE_SOURCE_DIR=${CMAKE_SOURCE_DIR}
262                                             -DCORE_SYSTEM_NAME=${CORE_SYSTEM_NAME}
263                                             -DCORE_PLATFORM_NAME_LC="${CORE_PLATFORM_NAME_LC}"
264                                             -DCORE_BUILD_DIR=${CORE_BUILD_DIR}
265                                             -DCMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}
266                                             -DARCH_DEFINES="${ARCH_DEFINES}"
267                                             -DAPP_SCMID=${APP_SCMID}
268                                             -DAPP_COPYRIGHT_YEARS=${APP_COPYRIGHT_YEARS}
269                                             -DAPP_BUILD_DATE=${APP_BUILD_DATE}
270                                             -DAPP_SHARED_LIBRARY_SUFFIX="${APP_SHARED_LIBRARY_SUFFIX}"
271                                             -DPYTHON_VERSION=${PYTHON_VERSION}
272                                             -Dprefix=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}
273                                             -DKODI_WEBSERVER_EXTRA_WHITELIST="${KODI_WEBSERVER_EXTRA_WHITELIST}"
274                                             -P ${CMAKE_SOURCE_DIR}/cmake/scripts/common/GenerateVersionedFiles.cmake
275                    DEPENDS ${CMAKE_SOURCE_DIR}/version.txt
276                            export-files
277                            ${ADDON_XML_DEPENDS}
278                            ${CMAKE_SOURCE_DIR}/xbmc/CompileInfo.cpp.in)
279 list(APPEND install_data ${ADDON_INSTALL_DATA})
280 add_library(compileinfo OBJECT ${CORE_BUILD_DIR}/xbmc/CompileInfo.cpp)
281 set_target_properties(compileinfo PROPERTIES FOLDER "Build Utilities")
282 target_compile_options(compileinfo PRIVATE ${SYSTEM_DEFINES} ${ARCH_DEFINES})
283 add_dependencies(compileinfo fmt::fmt)
285 if(NOT MSVC)
286   target_compile_options(compileinfo PUBLIC ${CORE_COMPILE_OPTIONS})
287 endif()
289 # RC File
290 if(WIN32)
291   configure_file(${CMAKE_SOURCE_DIR}/xbmc/platform/win32/XBMC_PC.rc.in
292                  ${CORE_BUILD_DIR}/xbmc/platform/win32/XBMC_PC.rc @ONLY)
293   add_library(resources OBJECT ${CORE_BUILD_DIR}/xbmc/platform/win32/XBMC_PC.rc)
294   set_target_properties(resources PROPERTIES FOLDER "Build Utilities")
295   target_include_directories(resources PRIVATE ${CMAKE_SOURCE_DIR}/tools/windows/packaging/media)
296   set(RESOURCES $<TARGET_OBJECTS:resources>)
297 endif()
299 # Generate messages
300 core_add_subdirs_from_filelist(${CMAKE_SOURCE_DIR}/cmake/messages/flatbuffers/*.txt)
302 include_directories(${INCLUDES} SYSTEM ${SYSTEM_INCLUDES})
303 add_compile_options(${ARCH_DEFINES} "${SYSTEM_DEFINES}" ${DEP_DEFINES} ${PATH_DEFINES})
305 set(core_DEPENDS "" CACHE STRING "" FORCE)
306 set(test_archives "" CACHE STRING "" FORCE)
307 set(test_sources "" CACHE STRING "" FORCE)
308 mark_as_advanced(core_DEPENDS)
309 mark_as_advanced(test_archives)
310 mark_as_advanced(test_sources)
312 # copy files to build tree
313 copy_files_from_filelist_to_buildtree(${CMAKE_SOURCE_DIR}/cmake/installdata/common/*.txt
314                                       ${CMAKE_SOURCE_DIR}/cmake/installdata/${CORE_SYSTEM_NAME}/*.txt)
316 list(APPEND SKINS "${CMAKE_SOURCE_DIR}/addons/skin.estuary\;${CMAKE_SOURCE_DIR}")
317 list(APPEND SKINS "${CMAKE_SOURCE_DIR}/addons/skin.estouchy\;${CMAKE_SOURCE_DIR}")
319 # These are skins that are copied into place from the source tree
320 foreach(skin ${SKINS})
321   list(GET skin 0 dir)
322   list(GET skin 1 relative)
323   copy_skin_to_buildtree(${dir} ${relative})
324 endforeach()
326 add_custom_target(pack-skins ALL
327                   DEPENDS TexturePacker::TexturePacker::Executable export-files ${XBT_FILES})
328 set_target_properties(pack-skins PROPERTIES FOLDER "Build Utilities")
330 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/system/players/VideoPlayer)
332 set(LIBCEC_SONAME "${CEC_SONAME}")
333 if(NOT CORE_SYSTEM_NAME STREQUAL windows AND NOT CORE_SYSTEM_NAME STREQUAL android AND NOT CORE_SYSTEM_NAME STREQUAL windowsstore)
334   configure_file(${CMAKE_SOURCE_DIR}/xbmc/DllPaths_generated.h.in
335                  ${CORE_BUILD_DIR}/DllPaths_generated.h @ONLY)
336 elseif(CORE_SYSTEM_NAME STREQUAL android)
337   configure_file(${CMAKE_SOURCE_DIR}/xbmc/DllPaths_generated_android.h.in
338                  ${CORE_BUILD_DIR}/DllPaths_generated_android.h @ONLY)
339 endif()
341 get_property(INTERNAL_DEPS GLOBAL PROPERTY INTERNAL_DEPS_PROP)
342 set(GLOBAL_TARGET_DEPS ${INTERNAL_DEPS} ${PLATFORM_GLOBAL_TARGET_DEPS})
344 # main library (used for main binary and tests)
345 if(CMAKE_GENERATOR STREQUAL Xcode)
346   add_library(compileinfo_obj OBJECT IMPORTED)
347   set_property(TARGET compileinfo_obj PROPERTY IMPORTED_OBJECTS
348     "${CMAKE_BINARY_DIR}/$(PROJECT_NAME).build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/compileinfo.build/$(OBJECT_FILE_DIR_normal:base)/$(CURRENT_ARCH)/CompileInfo.o"
349   )
350   add_library(lib${APP_NAME_LC} STATIC)
351   add_dependencies(lib${APP_NAME_LC} compileinfo)
352   target_link_libraries(lib${APP_NAME_LC} PUBLIC compileinfo_obj)
353 else()
354   add_library(lib${APP_NAME_LC} STATIC $<TARGET_OBJECTS:compileinfo>)
355 endif()
356 add_dependencies(lib${APP_NAME_LC} ${GLOBAL_TARGET_DEPS})
357 set_target_properties(lib${APP_NAME_LC} PROPERTIES PREFIX "")
359 # Other files (IDE)
360 set(OTHER_FILES cmake/README.md)
362 # Subdirs
363 foreach(CORE_PLATFORM_LC ${CORE_PLATFORM_NAME_LC})
364   core_add_subdirs_from_filelist(${CMAKE_SOURCE_DIR}/cmake/treedata/common/${CORE_PLATFORM_LC}/*.txt
365                                  ${CMAKE_SOURCE_DIR}/cmake/treedata/${CORE_SYSTEM_NAME}/${CORE_PLATFORM_LC}/*.txt)
366 endforeach()
368 core_add_subdirs_from_filelist(${CMAKE_SOURCE_DIR}/cmake/treedata/common/*.txt
369                                ${CMAKE_SOURCE_DIR}/cmake/treedata/${CORE_SYSTEM_NAME}/*.txt)
370 core_add_optional_subdirs_from_filelist(${CMAKE_SOURCE_DIR}/cmake/treedata/optional/common/*.txt
371                                         ${CMAKE_SOURCE_DIR}/cmake/treedata/optional/${CORE_SYSTEM_NAME}/*.txt)
373 target_link_libraries(lib${APP_NAME_LC} PUBLIC ${core_DEPENDS} ${SYSTEM_LDFLAGS} ${DEPLIBS} ${CMAKE_DL_LIBS})
374 set_target_properties(lib${APP_NAME_LC} PROPERTIES PROJECT_LABEL "xbmc")
375 source_group_by_folder(lib${APP_NAME_LC} RELATIVE ${CMAKE_SOURCE_DIR}/xbmc)
376 if(WIN32)
377   add_precompiled_header(lib${APP_NAME_LC} pch.h ${CMAKE_SOURCE_DIR}/xbmc/platform/win32/pch.cpp)
378   set_language_cxx(lib${APP_NAME_LC})
379 endif()
381 # main binary
382 if(NOT CORE_SYSTEM_NAME STREQUAL android)
383   if(CORE_SYSTEM_NAME STREQUAL windowsstore)
384     winstore_add_target_properties(${APP_NAME_LC})
385   endif()
386   add_executable(${APP_NAME_LC} ${CORE_MAIN_SOURCE} "${RESOURCES}" ${OTHER_FILES})
387   set_target_properties(${APP_NAME_LC} PROPERTIES ENABLE_EXPORTS ON)
388 else()
389   set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
390   add_library(${APP_NAME_LC} SHARED ${CORE_MAIN_SOURCE} "${RESOURCES}" ${OTHER_FILES})
392   # Statically resolve global references to shared library (ie. ffmpeg) definitions.
393   # Related to https://stackoverflow.com/questions/46307266/including-objects-to-a-shared-library-from-a-c-archive-a
394   set_target_properties(${APP_NAME_LC} PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic")
395 endif()
396 add_dependencies(${APP_NAME_LC} ${APP_NAME_LC}-libraries export-files pack-skins)
397 whole_archive(_MAIN_LIBRARIES ${FSTRCMP_LIBRARY} ${core_DEPENDS})
398 target_link_libraries(${APP_NAME_LC} ${_MAIN_LIBRARIES} lib${APP_NAME_LC} ${DEPLIBS})
399 unset(_MAIN_LIBRARIES)
401 if(WIN32)
402   set_target_properties(${APP_NAME_LC} PROPERTIES WIN32_EXECUTABLE ON)
403   set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${APP_NAME_LC})
404   if(NOT CORE_SYSTEM_NAME STREQUAL windowsstore)
405     target_sources(${APP_NAME_LC} PRIVATE ${CMAKE_SOURCE_DIR}/xbmc/platform/win32/app.manifest)
406   else()
407     set_target_properties(${APP_NAME_LC} PROPERTIES VS_USER_PROPS ${VCPROJECT_PROPS_FILE}
408                           VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION ${VS_MINIMUM_SDK_VERSION})
409   endif()
410 elseif(CORE_SYSTEM_NAME STREQUAL android)
411   # Nothing
412 elseif(CORE_SYSTEM_NAME STREQUAL darwin_embedded)
413   set_target_properties(${APP_NAME_LC} PROPERTIES OUTPUT_NAME ${APP_NAME}
414                                                   MACOSX_BUNDLE_INFO_PLIST ${PLATFORM_BUNDLE_INFO_PLIST})
415 else()
416   set_target_properties(${APP_NAME_LC} PROPERTIES SUFFIX ${APP_BINARY_SUFFIX})
417 endif()
419 # testing
420 if(HOST_CAN_EXECUTE_TARGET AND ENABLE_TESTING)
421   find_package(Gtest)
423   copy_files_from_filelist_to_buildtree(${CMAKE_SOURCE_DIR}/cmake/installdata/test-reference-data.txt NO_INSTALL)
424   add_executable(${APP_NAME_LC}-test EXCLUDE_FROM_ALL ${CMAKE_SOURCE_DIR}/xbmc/test/xbmc-test.cpp ${test_sources})
426   set_target_properties(PROPERTIES ENABLE_EXPORTS ON)
428   whole_archive(_TEST_LIBRARIES ${core_DEPENDS} ${GTEST_LIBRARY})
429   target_link_libraries(${APP_NAME_LC}-test PRIVATE ${SYSTEM_LDFLAGS} ${_TEST_LIBRARIES} lib${APP_NAME_LC} ${DEPLIBS} ${CMAKE_DL_LIBS})
430   unset(_TEST_LIBRARIES)
432   if (ENABLE_INTERNAL_GTEST)
433     add_dependencies(${APP_NAME_LC}-test ${APP_NAME_LC}-libraries export-files gtest)
434   endif()
436   # Enable unit-test related targets
437   enable_testing()
438   gtest_add_tests(${APP_NAME_LC}-test "" ${test_sources})
439   add_custom_target(check ${CMAKE_CTEST_COMMAND} WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
440   add_dependencies(check ${APP_NAME_LC}-test)
442   # Valgrind (memcheck)
443   find_program(VALGRIND_EXECUTABLE NAMES valgrind)
444   if(VALGRIND_EXECUTABLE)
445     set(CTEST_MEMORYCHECK_COMMAND ${VALGRIND_EXECUTABLE})
446     set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "-q --trace-children=yes --leak-check=yes --track-origins=yes")
447     include(CTest)
448     add_custom_target(check-valgrind ${CMAKE_CTEST_COMMAND} -D ExperimentalMemCheck \${ARGS} WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
449     add_dependencies(check-valgrind ${APP_NAME_LC}-test)
450   endif()
452   # For testing commit series
453   add_custom_target(check-commits ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/scripts/common/CheckCommits.cmake
454                                                    -DCMAKE_BINARY_DIR=${CMAKE_BINARY_DIR})
455   set_target_properties(check-commits PROPERTIES FOLDER "Build Utilities")
457   include(${CMAKE_SOURCE_DIR}/cmake/scripts/common/StaticAnalysis.cmake)
459   # code coverage
460   if(CMAKE_BUILD_TYPE STREQUAL Coverage)
461     if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/scripts/${CORE_SYSTEM_NAME}/CodeCoverage.cmake)
462       include(${CMAKE_SOURCE_DIR}/cmake/scripts/${CORE_SYSTEM_NAME}/CodeCoverage.cmake)
463     else()
464       message(FATAL_ERROR "Code coverage not (yet) implemented for platform ${CORE_SYSTEM_NAME}")
465     endif()
466   endif()
467 endif()
469 # Documentation
470 find_package(Doxygen)
471 if(DOXYGEN_FOUND)
472   add_custom_target(doc
473                     COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/docs/doxygen/Doxyfile.doxy
474                     COMMAND ${CMAKE_COMMAND} -E echo "Documentation built to: file://${CMAKE_SOURCE_DIR}/docs/html/index.html"
475                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/doxygen
476                     COMMENT "Generating Doxygen documentation" VERBATIM)
477 endif()
479 # link wrapper
480 if(FFMPEG_LINK_EXECUTABLE)
481   set(CMAKE_CXX_LINK_EXECUTABLE "${FFMPEG_LINK_EXECUTABLE}")
482 endif()
483 if(FFMPEG_CREATE_SHARED_LIBRARY)
484   set(CMAKE_CXX_CREATE_SHARED_LIBRARY "${FFMPEG_CREATE_SHARED_LIBRARY}")
485 endif()
487 # Platform specific additional extra targets
488 if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/scripts/${CORE_SYSTEM_NAME}/ExtraTargets.cmake)
489   include(${CMAKE_SOURCE_DIR}/cmake/scripts/${CORE_SYSTEM_NAME}/ExtraTargets.cmake)
490 endif()
492 include(cmake/scripts/${CORE_SYSTEM_NAME}/Install.cmake)
494 # Add uninstall target
495 if(CMAKE_GENERATOR MATCHES Makefile)
496   add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/scripts/common/Uninstall.cmake)
497   set_target_properties(uninstall PROPERTIES FOLDER "Build Utilities")
498 endif()
500 # Create target that allows to build binary-addons.
501 # Use make binary-addons ADDONS="visualization.spectrum" to select the addons to build.
502 if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
503   if(CMAKE_CROSSCOMPILING)
504     set(_cross_args CROSS_COMPILING=yes)
505   endif()
506   if(NOT CORE_SYSTEM_NAME STREQUAL android)
507     set(_prefix ${CMAKE_BINARY_DIR}/addons)
508     set(_extra "CMAKE_EXTRA=-DPACKAGE_ZIP=ON")
509   else()
510     set(_prefix ${CMAKE_INSTALL_PREFIX})
511   endif()
512   add_custom_target(binary-addons
513     COMMAND $(MAKE) -C ${CMAKE_SOURCE_DIR}/tools/depends/target/binary-addons clean
514     COMMAND $(MAKE) -C ${CMAKE_SOURCE_DIR}/tools/depends/target/binary-addons VERBOSE=1 V=99
515                     PREFIX=${_prefix} INSTALL_PREFIX=${_prefix} ${_cross_args} ${_extra})
516   unset(_cross_args)
517   unset(_prefix)
518 endif()
520 # Prepare add-on build env
521 include(${CORE_SOURCE_DIR}/xbmc/addons/AddonBindings.cmake)
522 file(COPY ${CORE_ADDON_BINDINGS_FILES} ${CORE_ADDON_BINDINGS_DIRS}/
523      DESTINATION ${CORE_BUILD_DIR}/include/${APP_NAME_LC}
524      REGEX ".txt" EXCLUDE)
526 set(APP_LIB_DIR ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/lib/${APP_NAME_LC})
527 set(APP_INCLUDE_DIR ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/include/${APP_NAME_LC})
528 configure_file(${CMAKE_SOURCE_DIR}/cmake/KodiConfig.cmake.in
529                ${CORE_BUILD_DIR}/lib/${APP_NAME_LC}/${APP_NAME}Config.cmake @ONLY)
530 configure_file(${CMAKE_SOURCE_DIR}/cmake/scripts/common/AddonHelpers.cmake
531                ${CORE_BUILD_DIR}/lib/${APP_NAME_LC}/AddonHelpers.cmake COPYONLY)
532 configure_file(${CMAKE_SOURCE_DIR}/cmake/scripts/common/AddOptions.cmake
533                ${CORE_BUILD_DIR}/lib/${APP_NAME_LC}/AddOptions.cmake COPYONLY)
535 # Status
536 message(STATUS "#---- CONFIGURATION ----#")
537 foreach(msg ${final_message})
538   message(STATUS ${msg})
539 endforeach()
541 if(VERBOSE)
542   message(STATUS "\n#--------------- Internal Variables -------------#")
543   message(STATUS "DEPLIBS: ${DEPLIBS}")
544   message(STATUS "core_DEPENDS: ${core_DEPENDS}")
545   message(STATUS "#---------------------------------------------#")
546   message(STATUS "SYSTEM_LDFLAGS        : ${SYSTEM_LDFLAGS}")
547   message(STATUS "CMAKE_DL_LIBS         : ${CMAKE_DL_LIBS}")
548   message(STATUS "CMAKE_C_FLAGS         : ${CMAKE_C_FLAGS}")
549   message(STATUS "CMAKE_CXX_FLAGS       : ${CMAKE_CXX_FLAGS}")
550   message(STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
551   message(STATUS "LTO_OPTIMIZATION      : ${CMAKE_INTERPROCEDURAL_OPTIMIZATION}")
552   if(CMAKE_INTERPROCEDURAL_OPTIMIZATION)
553     message(STATUS "CMAKE_CXX_COMPILE_OPTIONS_IPO: ${CMAKE_CXX_COMPILE_OPTIONS_IPO}")
554     message(STATUS "CMAKE_C_COMPILE_OPTIONS_IPO  : ${CMAKE_C_COMPILE_OPTIONS_IPO}")
555     message(STATUS "CMAKE_AR                     : ${CMAKE_AR}")
556     message(STATUS "CMAKE_NM                     : ${CMAKE_NM}")
557     message(STATUS "CMAKE_LINKER                 : ${CMAKE_LINKER}")
558   endif()
559   message(STATUS "#---------------------------------------------#")
560   message(STATUS "bindir     : ${bindir}")
561   message(STATUS "includedir : ${includedir}")
562   message(STATUS "libdir     : ${libdir}")
563   message(STATUS "datarootdir: ${datarootdir}")
564   message(STATUS "#---------------------------------------------#")
565   message(STATUS "BINARY: ${APP_NAME_LC}${APP_BINARY_SUFFIX}")
566   message(STATUS "#---------------------------------------------#")
567   message(STATUS "GIT_REV: ${APP_SCMID}")
568   message(STATUS "Build date: ${APP_BUILD_DATE}")
569   message(STATUS "#---------------------------------------------#")
570   message(STATUS "CPACK_GENERATOR       : ${CPACK_GENERATOR}")
571   message(STATUS "CPACK_SOURCE_GENERATOR: ${CPACK_SOURCE_GENERATOR}")
572   message(STATUS "#---------------------------------------------#")
573 endif()