From 9fc8b732737f139d3e466510d75668ab45578960 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 8 Mar 2016 21:02:53 +0100 Subject: sync with upstream --- project/cmake/scripts/windows/archsetup.cmake | 91 ++++++++++++++++ project/cmake/scripts/windows/install.cmake | 0 project/cmake/scripts/windows/macros.cmake | 143 ++++++++++++++++++++++++++ project/cmake/scripts/windows/pathsetup.cmake | 34 ++++++ 4 files changed, 268 insertions(+) create mode 100644 project/cmake/scripts/windows/archsetup.cmake create mode 100644 project/cmake/scripts/windows/install.cmake create mode 100644 project/cmake/scripts/windows/macros.cmake create mode 100644 project/cmake/scripts/windows/pathsetup.cmake (limited to 'project/cmake/scripts/windows') diff --git a/project/cmake/scripts/windows/archsetup.cmake b/project/cmake/scripts/windows/archsetup.cmake new file mode 100644 index 0000000..baa3624 --- /dev/null +++ b/project/cmake/scripts/windows/archsetup.cmake @@ -0,0 +1,91 @@ +# -------- Architecture settings --------- + +set(ARCH win32) + + +# -------- Paths (mainly for find_package) --------- + +set(PLATFORM_DIR win32) + +# 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) +list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${PROJECT_SOURCE_DIR}/../../lib/win32) +list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${PROJECT_SOURCE_DIR}/../../lib/win32/ffmpeg) +list(APPEND CMAKE_SYSTEM_LIBRARY_PATH ${PROJECT_SOURCE_DIR}/../../lib/win32/ffmpeg/bin) +list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${PROJECT_SOURCE_DIR}/../BuildDependencies) +set(CONFIGURATION_LIBDIR lib/${CORE_BUILD_CONFIG}-vc120) +set(CONFIGURATION_LIBDIR_RELEASE lib/Release-vc120) +set(CONFIGURATION_LIBDIR_DEBUG lib/Debug-vc120) + +set(JPEG_NAMES ${JPEG_NAMES} jpeg-static) +set(PYTHON_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/../BuildDependencies/include/python) + + +# -------- Compiler options --------- + +add_options(CXX ALL_BUILDS "/wd\"4996\"") +set(ARCH_DEFINES -D_WINDOWS -DTARGET_WINDOWS) +set(SYSTEM_DEFINES -DNOMINMAX -D_USE_32BIT_TIME_T -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" + -DBUILDING_WITH_CMAKE + $<$:-DD3D_DEBUG_INFO -D_SECURE_SCL=0 -D_HAS_ITERATOR_DEBUGGING=0>) + +# Compile with /MT (to be compatible with the dependent libraries) +foreach(CompilerFlag CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) + string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") +endforeach() + +# Make sure /FS is set for Visual Studio in order to prevent simultanious access to pdb files. +if(CMAKE_GENERATOR MATCHES "Visual Studio") + set(CMAKE_CXX_FLAGS "/MP /FS ${CMAKE_CXX_FLAGS}") +endif() + + +# -------- 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(${PROJECT_SOURCE_DIR}/../../lib/win32/ffmpeg/bin + ${PROJECT_SOURCE_DIR}/../BuildDependencies/lib + ${PROJECT_SOURCE_DIR}/../BuildDependencies/${CONFIGURATION_LIBDIR}) + +# Additional libraries +list(APPEND DEPLIBS d3d11.lib DInput8.lib DSound.lib winmm.lib Mpr.lib Iphlpapi.lib + PowrProf.lib setupapi.lib dwmapi.lib yajl.lib dxguid.lib DelayImp.lib) + +# NODEFAULTLIB option +set(_nodefaultlibs_RELEASE libc msvcrt libci msvcprt) +set(_nodefaultlibs_DEBUG libcpmt libc msvcrt libcmt msvcrtd msvcprtd) +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 libxslt.dll dnssd.dll dwmapi.dll ssh.dll sqlite3.dll + avcodec-56.dll avfilter-5.dll avformat-56.dll avutil-54.dll + postproc-53.dll swresample-1.dll swscale-3.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) +endif() diff --git a/project/cmake/scripts/windows/install.cmake b/project/cmake/scripts/windows/install.cmake new file mode 100644 index 0000000..e69de29 diff --git a/project/cmake/scripts/windows/macros.cmake b/project/cmake/scripts/windows/macros.cmake new file mode 100644 index 0000000..6aabf7d --- /dev/null +++ b/project/cmake/scripts/windows/macros.cmake @@ -0,0 +1,143 @@ +function(core_link_library lib wraplib) +# set(export -Wl,--unresolved-symbols=ignore-all +# `cat ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/cores/dll-loader/exports/wrapper.def` +# ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/cores/dll-loader/exports/CMakeFiles/wrapper.dir/wrapper.c.o) +# set(check_arg "") +# if(TARGET ${lib}) +# set(target ${lib}) +# set(link_lib ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${lib}/${lib}.a) +# set(check_arg ${ARGV2}) +# set(data_arg ${ARGV3}) +# else() +# set(target ${ARGV2}) +# set(link_lib ${lib}) +# set(check_arg ${ARGV3}) +# set(data_arg ${ARGV4}) +# endif() +# if(check_arg STREQUAL "export") +# set(export ${export} +# -Wl,--version-script=${ARGV3}) +# elseif(check_arg STREQUAL "nowrap") +# set(export ${data_arg}) +# elseif(check_arg STREQUAL "extras") +# foreach(arg ${data_arg}) +# list(APPEND export ${arg}) +# endforeach() +# endif() +# get_filename_component(dir ${wraplib} PATH) +# add_custom_command(OUTPUT ${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX} +# COMMAND cmake -E make_directory ${dir} +# COMMAND ${CMAKE_C_COMPILER} +# ARGS -Wl,--whole-archive +# ${link_lib} +# -Wl,--no-whole-archive -lm +# -shared -o ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX} +# ${export} +# DEPENDS ${target} wrapper.def wrapper) +# list(APPEND WRAP_FILES ${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX}) +# set(WRAP_FILES ${WRAP_FILES} PARENT_SCOPE) +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_OUTPUT_DIRECTORY ${PRECOMPILEDHEADER_DIR}) + 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_OUTPUT_DIRECTORY ${PRECOMPILEDHEADER_DIR}) + else() + # As part of the target + target_sources(${target} PRIVATE ${pch_source}) + endif() +endfunction() + +# Adds an FX-compiled shader to a target +# Creates a custom command that FX-compiles the given shader and adds the +# generated header file to the given target. +# Arguments: +# target Target to add the FX-compiled shader to +# hlsl HLSL shader input file +# profile HLSL profile that specifies the shader model +# entrypoint Shader entry point +# On return: +# FXC_FILE is set to the name of the generated header file. +function(add_shader_dx target hlsl profile entrypoint) + get_filename_component(file ${hlsl} NAME_WE) + add_custom_command(OUTPUT ${file}.h + COMMAND ${FXC} /Fh ${file}.h + /E ${entrypoint} + /T ${profile} + /Vn ${file} + /Qstrip_reflect + ${hlsl} + DEPENDS ${hlsl} + COMMENT "FX compile ${hlsl}" + VERBATIM) + target_sources(${target} PRIVATE ${file}.h) + target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +endfunction() + +# Copies the main dlls to the root of the buildtree +# On return: +# files added to ${install_data}, mirror in build tree +function(copy_main_dlls_to_buildtree) + set(dir ${PROJECT_SOURCE_DIR}/../Win32BuildSetup/dependencies) + file(GLOB_RECURSE files ${dir}/*) + foreach(file ${files}) + copy_file_to_buildtree(${file} ${dir}) + endforeach() + + if(D3DCOMPILER_DLL) + get_filename_component(d3dcompiler_dir ${D3DCOMPILER_DLL} DIRECTORY) + copy_file_to_buildtree(${D3DCOMPILER_DLL} ${d3dcompiler_dir}) + endif() + + set(install_data ${install_data} PARENT_SCOPE) +endfunction() diff --git a/project/cmake/scripts/windows/pathsetup.cmake b/project/cmake/scripts/windows/pathsetup.cmake new file mode 100644 index 0000000..940fb62 --- /dev/null +++ b/project/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}/xbmc\" + -DINSTALL_PATH=\"${datarootdir}/xbmc\") -- cgit v1.2.3