summaryrefslogtreecommitdiffstats
path: root/project/cmake/scripts/windows/macros.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'project/cmake/scripts/windows/macros.cmake')
-rw-r--r--project/cmake/scripts/windows/macros.cmake143
1 files changed, 143 insertions, 0 deletions
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 @@
1function(core_link_library lib wraplib)
2# set(export -Wl,--unresolved-symbols=ignore-all
3# `cat ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/cores/dll-loader/exports/wrapper.def`
4# ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/cores/dll-loader/exports/CMakeFiles/wrapper.dir/wrapper.c.o)
5# set(check_arg "")
6# if(TARGET ${lib})
7# set(target ${lib})
8# set(link_lib ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${lib}/${lib}.a)
9# set(check_arg ${ARGV2})
10# set(data_arg ${ARGV3})
11# else()
12# set(target ${ARGV2})
13# set(link_lib ${lib})
14# set(check_arg ${ARGV3})
15# set(data_arg ${ARGV4})
16# endif()
17# if(check_arg STREQUAL "export")
18# set(export ${export}
19# -Wl,--version-script=${ARGV3})
20# elseif(check_arg STREQUAL "nowrap")
21# set(export ${data_arg})
22# elseif(check_arg STREQUAL "extras")
23# foreach(arg ${data_arg})
24# list(APPEND export ${arg})
25# endforeach()
26# endif()
27# get_filename_component(dir ${wraplib} PATH)
28# add_custom_command(OUTPUT ${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX}
29# COMMAND cmake -E make_directory ${dir}
30# COMMAND ${CMAKE_C_COMPILER}
31# ARGS -Wl,--whole-archive
32# ${link_lib}
33# -Wl,--no-whole-archive -lm
34# -shared -o ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX}
35# ${export}
36# DEPENDS ${target} wrapper.def wrapper)
37# list(APPEND WRAP_FILES ${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX})
38# set(WRAP_FILES ${WRAP_FILES} PARENT_SCOPE)
39endfunction()
40
41function(find_soname lib)
42 # Windows uses hardcoded dlls in xbmc/DllPaths_win32.h.
43 # Therefore the output of this function is unused.
44endfunction()
45
46# Add precompiled header to target
47# Arguments:
48# target existing target that will be set up to compile with a precompiled header
49# pch_header the precompiled header file
50# pch_source the precompiled header source file
51# Optional Arguments:
52# PCH_TARGET build precompiled header as separate target with the given name
53# so that the same precompiled header can be used for multiple libraries
54# EXCLUDE_SOURCES if not all target sources shall use the precompiled header,
55# the relevant files can be listed here
56# On return:
57# Compiles the pch_source into a precompiled header and adds the header to
58# the given target
59function(add_precompiled_header target pch_header pch_source)
60 cmake_parse_arguments(PCH "" "PCH_TARGET" "EXCLUDE_SOURCES" ${ARGN})
61
62 if(PCH_PCH_TARGET)
63 set(pch_binary ${PRECOMPILEDHEADER_DIR}/${PCH_PCH_TARGET}.pch)
64 else()
65 set(pch_binary ${PRECOMPILEDHEADER_DIR}/${target}.pch)
66 endif()
67
68 # Set compile options and dependency for sources
69 get_target_property(sources ${target} SOURCES)
70 list(REMOVE_ITEM sources ${pch_source})
71 foreach(exclude_source IN LISTS PCH_EXCLUDE_SOURCES)
72 list(REMOVE_ITEM sources ${exclude_source})
73 endforeach()
74 set_source_files_properties(${sources}
75 PROPERTIES COMPILE_FLAGS "/Yu\"${pch_header}\" /Fp\"${pch_binary}\" /FI\"${pch_header}\""
76 OBJECT_DEPENDS "${pch_binary}")
77
78 # Set compile options for precompiled header
79 if(NOT PCH_PCH_TARGET OR NOT TARGET ${PCH_PCH_TARGET}_pch)
80 set_source_files_properties(${pch_source}
81 PROPERTIES COMPILE_FLAGS "/Yc\"${pch_header}\" /Fp\"${pch_binary}\""
82 OBJECT_OUTPUTS "${pch_binary}")
83 endif()
84
85 # Compile precompiled header
86 if(PCH_PCH_TARGET)
87 # As own target for usage in multiple libraries
88 if(NOT TARGET ${PCH_PCH_TARGET}_pch)
89 add_library(${PCH_PCH_TARGET}_pch STATIC ${pch_source})
90 set_target_properties(${PCH_PCH_TARGET}_pch PROPERTIES COMPILE_PDB_OUTPUT_DIRECTORY ${PRECOMPILEDHEADER_DIR})
91 endif()
92 # From VS2012 onwards, precompiled headers have to be linked against (LNK2011).
93 target_link_libraries(${target} PUBLIC ${PCH_PCH_TARGET}_pch)
94 set_target_properties(${target} PROPERTIES COMPILE_PDB_OUTPUT_DIRECTORY ${PRECOMPILEDHEADER_DIR})
95 else()
96 # As part of the target
97 target_sources(${target} PRIVATE ${pch_source})
98 endif()
99endfunction()
100
101# Adds an FX-compiled shader to a target
102# Creates a custom command that FX-compiles the given shader and adds the
103# generated header file to the given target.
104# Arguments:
105# target Target to add the FX-compiled shader to
106# hlsl HLSL shader input file
107# profile HLSL profile that specifies the shader model
108# entrypoint Shader entry point
109# On return:
110# FXC_FILE is set to the name of the generated header file.
111function(add_shader_dx target hlsl profile entrypoint)
112 get_filename_component(file ${hlsl} NAME_WE)
113 add_custom_command(OUTPUT ${file}.h
114 COMMAND ${FXC} /Fh ${file}.h
115 /E ${entrypoint}
116 /T ${profile}
117 /Vn ${file}
118 /Qstrip_reflect
119 ${hlsl}
120 DEPENDS ${hlsl}
121 COMMENT "FX compile ${hlsl}"
122 VERBATIM)
123 target_sources(${target} PRIVATE ${file}.h)
124 target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
125endfunction()
126
127# Copies the main dlls to the root of the buildtree
128# On return:
129# files added to ${install_data}, mirror in build tree
130function(copy_main_dlls_to_buildtree)
131 set(dir ${PROJECT_SOURCE_DIR}/../Win32BuildSetup/dependencies)
132 file(GLOB_RECURSE files ${dir}/*)
133 foreach(file ${files})
134 copy_file_to_buildtree(${file} ${dir})
135 endforeach()
136
137 if(D3DCOMPILER_DLL)
138 get_filename_component(d3dcompiler_dir ${D3DCOMPILER_DLL} DIRECTORY)
139 copy_file_to_buildtree(${D3DCOMPILER_DLL} ${d3dcompiler_dir})
140 endif()
141
142 set(install_data ${install_data} PARENT_SCOPE)
143endfunction()