diff options
Diffstat (limited to 'cmake/scripts/windows')
-rw-r--r-- | cmake/scripts/windows/ArchSetup.cmake | 128 | ||||
-rw-r--r-- | cmake/scripts/windows/CFlagOverrides.cmake | 10 | ||||
-rw-r--r-- | cmake/scripts/windows/CXXFlagOverrides.cmake | 10 | ||||
-rw-r--r-- | cmake/scripts/windows/Install.cmake | 0 | ||||
-rw-r--r-- | cmake/scripts/windows/Macros.cmake | 66 | ||||
-rw-r--r-- | cmake/scripts/windows/PathSetup.cmake | 34 | ||||
-rw-r--r-- | cmake/scripts/windows/tools/patch.cmake | 50 |
7 files changed, 298 insertions, 0 deletions
diff --git a/cmake/scripts/windows/ArchSetup.cmake b/cmake/scripts/windows/ArchSetup.cmake new file mode 100644 index 0000000..f0f8a08 --- /dev/null +++ b/cmake/scripts/windows/ArchSetup.cmake @@ -0,0 +1,128 @@ +# Minimum SDK version we support +set(VS_MINIMUM_SDK_VERSION 10.0.14393.0) + +if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION VERSION_LESS VS_MINIMUM_SDK_VERSION) + message(FATAL_ERROR "Detected Windows SDK version is ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}.\n" + "Windows SDK ${VS_MINIMUM_SDK_VERSION} or higher is required.\n" + "INFO: Windows SDKs can be installed from the Visual Studio installer.") +endif() + +# -------- Host Settings --------- + +set(_gentoolset ${CMAKE_GENERATOR_TOOLSET}) +string(REPLACE "host=" "" HOSTTOOLSET "${_gentoolset}") +unset(_gentoolset) + +# -------- Architecture settings --------- + +if(CMAKE_SIZEOF_VOID_P EQUAL 4) + set(ARCH win32) + set(SDK_TARGET_ARCH x86) +elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(ARCH x64) + set(SDK_TARGET_ARCH x64) +endif() + + +# -------- Paths (mainly for find_package) --------- + +set(PLATFORM_DIR platform/win32) +set(APP_RENDER_SYSTEM dx11) + +set(CORE_MAIN_SOURCE ${CMAKE_SOURCE_DIR}/xbmc/platform/win32/WinMain.cpp) + +# Precompiled headers fail with per target output directory. (needs CMake 3.1) +set(PRECOMPILEDHEADER_DIR ${PROJECT_BINARY_DIR}/${CORE_BUILD_CONFIG}/objs) +set(CMAKE_SYSTEM_NAME Windows) +set(DEPS_FOLDER_RELATIVE project/BuildDependencies) +set(NATIVEPREFIX ${CMAKE_SOURCE_DIR}/${DEPS_FOLDER_RELATIVE}/tools) +set(DEPENDS_PATH ${CMAKE_SOURCE_DIR}/${DEPS_FOLDER_RELATIVE}/${ARCH}) +set(MINGW_LIBS_DIR ${CMAKE_SOURCE_DIR}/${DEPS_FOLDER_RELATIVE}/mingwlibs/${ARCH}) + +# mingw libs +list(APPEND CMAKE_PREFIX_PATH ${MINGW_LIBS_DIR}) +list(APPEND CMAKE_LIBRARY_PATH ${MINGW_LIBS_DIR}/bin) + +if(NOT TARBALL_DIR) + set(TARBALL_DIR "${CMAKE_SOURCE_DIR}/project/BuildDependencies/downloads") +endif() + +# -------- Compiler options --------- + +add_options(CXX ALL_BUILDS "/wd\"4996\"") +set(ARCH_DEFINES -D_WINDOWS -DTARGET_WINDOWS -DTARGET_WINDOWS_DESKTOP -D__SSE__ -D__SSE2__) +set(SYSTEM_DEFINES -DWIN32_LEAN_AND_MEAN -DNOMINMAX -DHAS_DX -D__STDC_CONSTANT_MACROS + -DTAGLIB_STATIC -DNPT_CONFIG_ENABLE_LOGGING + -DPLT_HTTP_DEFAULT_USER_AGENT="UPnP/1.0 DLNADOC/1.50 Kodi" + -DPLT_HTTP_DEFAULT_SERVER="UPnP/1.0 DLNADOC/1.50 Kodi" + -DUNICODE -D_UNICODE + -DFRIBIDI_STATIC + $<$<CONFIG:Debug>:-DD3D_DEBUG_INFO>) + +# Additional SYSTEM_DEFINES +list(APPEND SYSTEM_DEFINES -DHAS_WIN32_NETWORK -DHAS_FILESYSTEM_SMB) + +# The /MP option enables /FS by default. +if(CMAKE_GENERATOR MATCHES "Visual Studio") + if(DEFINED ENV{MAXTHREADS}) + set(MP_FLAG "/MP$ENV{MAXTHREADS}") + else() + set(MP_FLAG "/MP") + endif() + + set(CMAKE_CXX_FLAGS "/permissive- ${MP_FLAG} ${CMAKE_CXX_FLAGS}") +endif() + +# Google Test needs to use shared version of runtime libraries +set(gtest_force_shared_crt ON CACHE STRING "" FORCE) + + +# -------- Linker options --------- + +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO") + +# For #pragma comment(lib X) +# TODO: It would certainly be better to handle these libraries via CMake modules. +link_directories(${DEPENDS_PATH}/lib) + +# Additional libraries +list(APPEND DEPLIBS bcrypt.lib d3d11.lib DInput8.lib DSound.lib winmm.lib Mpr.lib Iphlpapi.lib WS2_32.lib + PowrProf.lib setupapi.lib Shlwapi.lib dwmapi.lib dxguid.lib DelayImp.lib version.lib + crypt32.lib) + +# NODEFAULTLIB option +set(_nodefaultlibs_RELEASE libcmt) +set(_nodefaultlibs_DEBUG libcmt msvcrt) +foreach(_lib ${_nodefaultlibs_RELEASE}) + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:\"${_lib}\"") +endforeach() +foreach(_lib ${_nodefaultlibs_DEBUG}) + set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:\"${_lib}\"") +endforeach() + +# DELAYLOAD option +set(_delayloadlibs zlib.dll libmariadb.dll libxslt.dll dnssd.dll dwmapi.dll sqlite3.dll + d3dcompiler_47.dll) +foreach(_lib ${_delayloadlibs}) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DELAYLOAD:\"${_lib}\"") +endforeach() + +# Make the Release version create a PDB +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi") +# Minimize the size or the resulting DLLs +set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF") + + +# -------- Visual Studio options --------- + +if(CMAKE_GENERATOR MATCHES "Visual Studio") + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + + # Generate a batch file that opens Visual Studio with the necessary env variables set. + file(WRITE ${CMAKE_BINARY_DIR}/kodi-sln.bat + "@echo off\n" + "set KODI_HOME=%~dp0\n" + "set PATH=%~dp0\\system\n" + "set PreferredToolArchitecture=x64\n" + "start %~dp0\\${PROJECT_NAME}.sln") +endif() diff --git a/cmake/scripts/windows/CFlagOverrides.cmake b/cmake/scripts/windows/CFlagOverrides.cmake new file mode 100644 index 0000000..cd96689 --- /dev/null +++ b/cmake/scripts/windows/CFlagOverrides.cmake @@ -0,0 +1,10 @@ +if(MSVC) + if(DEFINED ENV{MAXTHREADS}) + set(MP_FLAG "/MP$ENV{MAXTHREADS}") + else() + set(MP_FLAG "/MP") + endif() + set(CMAKE_C_FLAGS "/D_UNICODE /DUNICODE /DRPC_USE_NATIVE_WCHAR ${MP_FLAG} /DWIN32 /D_WINDOWS /W3 /Zi /arch:SSE2") + set(CMAKE_C_FLAGS_DEBUG "/D_DEBUG /MDd /Ob0 /Od /RTC1 /D_ITERATOR_DEBUG_LEVEL=0") + set(CMAKE_C_FLAGS_RELEASE "/MD /Ox /Ob2 /Oi /Ot /Oy /GL /DNDEBUG") +endif() diff --git a/cmake/scripts/windows/CXXFlagOverrides.cmake b/cmake/scripts/windows/CXXFlagOverrides.cmake new file mode 100644 index 0000000..72df9de --- /dev/null +++ b/cmake/scripts/windows/CXXFlagOverrides.cmake @@ -0,0 +1,10 @@ +if(MSVC) + if(DEFINED ENV{MAXTHREADS}) + set(MP_FLAG "/MP$ENV{MAXTHREADS}") + else() + set(MP_FLAG "/MP") + endif() + set(CMAKE_CXX_FLAGS "/D_UNICODE /DUNICODE /DRPC_USE_NATIVE_WCHAR ${MP_FLAG} /DWIN32 /D_WINDOWS /W3 /GR /Zi /EHsc /arch:SSE2") + set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /MDd /Ob0 /Od /RTC1 /D_ITERATOR_DEBUG_LEVEL=0") + set(CMAKE_CXX_FLAGS_RELEASE "/MD /Ox /Ob2 /Oi /Ot /Oy /GL /DNDEBUG") +endif() diff --git a/cmake/scripts/windows/Install.cmake b/cmake/scripts/windows/Install.cmake new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/cmake/scripts/windows/Install.cmake diff --git a/cmake/scripts/windows/Macros.cmake b/cmake/scripts/windows/Macros.cmake new file mode 100644 index 0000000..2d3500d --- /dev/null +++ b/cmake/scripts/windows/Macros.cmake @@ -0,0 +1,66 @@ +function(core_link_library lib wraplib) + message(AUTHOR_WARNING "core_link_library is not compatible with windows.") +endfunction() + +function(find_soname lib) + # Windows uses hardcoded dlls in xbmc/DllPaths_win32.h. + # Therefore the output of this function is unused. +endfunction() + +# Add precompiled header to target +# Arguments: +# target existing target that will be set up to compile with a precompiled header +# pch_header the precompiled header file +# pch_source the precompiled header source file +# Optional Arguments: +# PCH_TARGET build precompiled header as separate target with the given name +# so that the same precompiled header can be used for multiple libraries +# EXCLUDE_SOURCES if not all target sources shall use the precompiled header, +# the relevant files can be listed here +# On return: +# Compiles the pch_source into a precompiled header and adds the header to +# the given target +function(add_precompiled_header target pch_header pch_source) + cmake_parse_arguments(PCH "" "PCH_TARGET" "EXCLUDE_SOURCES" ${ARGN}) + + if(PCH_PCH_TARGET) + set(pch_binary ${PRECOMPILEDHEADER_DIR}/${PCH_PCH_TARGET}.pch) + else() + set(pch_binary ${PRECOMPILEDHEADER_DIR}/${target}.pch) + endif() + + # Set compile options and dependency for sources + get_target_property(sources ${target} SOURCES) + list(REMOVE_ITEM sources ${pch_source}) + foreach(exclude_source IN LISTS PCH_EXCLUDE_SOURCES) + list(REMOVE_ITEM sources ${exclude_source}) + endforeach() + set_source_files_properties(${sources} + PROPERTIES COMPILE_FLAGS "/Yu\"${pch_header}\" /Fp\"${pch_binary}\" /FI\"${pch_header}\"" + OBJECT_DEPENDS "${pch_binary}") + + # Set compile options for precompiled header + if(NOT PCH_PCH_TARGET OR NOT TARGET ${PCH_PCH_TARGET}_pch) + set_source_files_properties(${pch_source} + PROPERTIES COMPILE_FLAGS "/Yc\"${pch_header}\" /Fp\"${pch_binary}\"" + OBJECT_OUTPUTS "${pch_binary}") + endif() + + # Compile precompiled header + if(PCH_PCH_TARGET) + # As own target for usage in multiple libraries + if(NOT TARGET ${PCH_PCH_TARGET}_pch) + add_library(${PCH_PCH_TARGET}_pch STATIC ${pch_source}) + set_target_properties(${PCH_PCH_TARGET}_pch PROPERTIES COMPILE_PDB_NAME vc140 + COMPILE_PDB_OUTPUT_DIRECTORY ${PRECOMPILEDHEADER_DIR} + FOLDER "Build Utilities") + endif() + # From VS2012 onwards, precompiled headers have to be linked against (LNK2011). + target_link_libraries(${target} PUBLIC ${PCH_PCH_TARGET}_pch) + set_target_properties(${target} PROPERTIES COMPILE_PDB_NAME vc140 + COMPILE_PDB_OUTPUT_DIRECTORY ${PRECOMPILEDHEADER_DIR}) + else() + # As part of the target + target_sources(${target} PRIVATE ${pch_source}) + endif() +endfunction() diff --git a/cmake/scripts/windows/PathSetup.cmake b/cmake/scripts/windows/PathSetup.cmake new file mode 100644 index 0000000..f6defde --- /dev/null +++ b/cmake/scripts/windows/PathSetup.cmake @@ -0,0 +1,34 @@ +if(NOT prefix) + set(prefix ${CMAKE_INSTALL_PREFIX}) +else() + set(CMAKE_INSTALL_PREFIX ${prefix}) +endif() +if(NOT exec_prefix) + set(exec_prefix ${prefix}) +endif() +if(NOT libdir) + set(libdir ${prefix}/lib) +endif() +if(NOT bindir) + set(bindir ${prefix}/bin) +endif() +if(NOT includedir) + set(includedir ${prefix}/include) +endif() +if(NOT datarootdir) + set(datarootdir ${prefix}/share) +endif() +if(NOT datadir) + set(datadir ${datarootdir}) +endif() + +list(APPEND final_message "-- PATH config --") +list(APPEND final_message "Prefix: ${prefix}") +list(APPEND final_message "Libdir: ${libdir}") +list(APPEND final_message "Bindir: ${bindir}") +list(APPEND final_message "Includedir: ${includedir}") +list(APPEND final_message "Datarootdir: ${datarootdir}") +list(APPEND final_message "Datadir: ${datadir}") + +set(PATH_DEFINES -DBIN_INSTALL_PATH=\"${libdir}/${APP_NAME_LC}\" + -DINSTALL_PATH=\"${datarootdir}/${APP_NAME_LC}\") diff --git a/cmake/scripts/windows/tools/patch.cmake b/cmake/scripts/windows/tools/patch.cmake new file mode 100644 index 0000000..451fc66 --- /dev/null +++ b/cmake/scripts/windows/tools/patch.cmake @@ -0,0 +1,50 @@ +# prioritize Git patch.exe +find_package(Git) +if(Git_FOUND) + get_filename_component(GIT_DIR ${GIT_EXECUTABLE} DIRECTORY) + get_filename_component(GIT_DIR ${GIT_DIR} DIRECTORY) +endif() + +find_program(PATCH_FOUND NAMES patch.exe HINTS ${GIT_DIR} PATH_SUFFIXES usr/bin) + +if(PATCH_FOUND) + message(STATUS "patch utility found at ${PATCH_FOUND}") +else() + set(PATCH_ARCHIVE_NAME "patch-2.7.6-bin") + set(PATCH_ARCHIVE "${PATCH_ARCHIVE_NAME}.zip") + set(PATCH_URL "${KODI_MIRROR}/build-deps/win32/${PATCH_ARCHIVE}") + set(PATCH_DOWNLOAD ${BUILD_DIR}/download/${PATCH_ARCHIVE}) + + # download the archive containing patch.exe + message(STATUS "Downloading patch utility from ${PATCH_URL}...") + file(DOWNLOAD "${PATCH_URL}" "${PATCH_DOWNLOAD}" STATUS PATCH_DL_STATUS LOG PATCH_LOG SHOW_PROGRESS) + list(GET PATCH_DL_STATUS 0 PATCH_RETCODE) + if(NOT PATCH_RETCODE EQUAL 0) + message(FATAL_ERROR "ERROR downloading ${PATCH_URL} - status: ${PATCH_DL_STATUS} log: ${PATCH_LOG}") + endif() + + # extract the archive containing patch.exe + execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzvf ${PATCH_DOWNLOAD} + WORKING_DIRECTORY ${BUILD_DIR}) + + # make sure the extraction worked and that patch.exe is there + set(PATCH_PATH ${BUILD_DIR}/${PATCH_ARCHIVE_NAME}) + set(PATCH_BINARY_PATH ${PATCH_PATH}/bin/patch.exe) + if(NOT EXISTS ${PATCH_PATH} OR NOT EXISTS ${PATCH_BINARY_PATH}) + message(FATAL_ERROR "ERROR extracting patch utility from ${PATCH_PATH}") + endif() + + # copy patch.exe into the output directory + file(INSTALL ${PATCH_BINARY_PATH} DESTINATION ${ADDON_DEPENDS_PATH}/bin) + # copy patch depends + file(GLOB PATCH_BINARIES ${PATCH_PATH}/bin/*.dll) + if(NOT "${PATCH_BINARIES}" STREQUAL "") + file(INSTALL ${PATCH_BINARIES} DESTINATION ${ADDON_DEPENDS_PATH}/bin) + endif() + + # make sure that cmake can find the copied patch.exe + find_program(PATCH_FOUND NAMES patch patch.exe) + if(NOT PATCH_FOUND) + message(FATAL_ERROR "ERROR installing patch utility from ${PATCH_BINARY_PATH} to ${ADDON_DEPENDS_PATH}/bin") + endif() +endif() |