diff options
Diffstat (limited to 'cmake/scripts/windows/Macros.cmake')
| -rw-r--r-- | cmake/scripts/windows/Macros.cmake | 66 |
1 files changed, 66 insertions, 0 deletions
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 @@ | |||
| 1 | function(core_link_library lib wraplib) | ||
| 2 | message(AUTHOR_WARNING "core_link_library is not compatible with windows.") | ||
| 3 | endfunction() | ||
| 4 | |||
| 5 | function(find_soname lib) | ||
| 6 | # Windows uses hardcoded dlls in xbmc/DllPaths_win32.h. | ||
| 7 | # Therefore the output of this function is unused. | ||
| 8 | endfunction() | ||
| 9 | |||
| 10 | # Add precompiled header to target | ||
| 11 | # Arguments: | ||
| 12 | # target existing target that will be set up to compile with a precompiled header | ||
| 13 | # pch_header the precompiled header file | ||
| 14 | # pch_source the precompiled header source file | ||
| 15 | # Optional Arguments: | ||
| 16 | # PCH_TARGET build precompiled header as separate target with the given name | ||
| 17 | # so that the same precompiled header can be used for multiple libraries | ||
| 18 | # EXCLUDE_SOURCES if not all target sources shall use the precompiled header, | ||
| 19 | # the relevant files can be listed here | ||
| 20 | # On return: | ||
| 21 | # Compiles the pch_source into a precompiled header and adds the header to | ||
| 22 | # the given target | ||
| 23 | function(add_precompiled_header target pch_header pch_source) | ||
| 24 | cmake_parse_arguments(PCH "" "PCH_TARGET" "EXCLUDE_SOURCES" ${ARGN}) | ||
| 25 | |||
| 26 | if(PCH_PCH_TARGET) | ||
| 27 | set(pch_binary ${PRECOMPILEDHEADER_DIR}/${PCH_PCH_TARGET}.pch) | ||
| 28 | else() | ||
| 29 | set(pch_binary ${PRECOMPILEDHEADER_DIR}/${target}.pch) | ||
| 30 | endif() | ||
| 31 | |||
| 32 | # Set compile options and dependency for sources | ||
| 33 | get_target_property(sources ${target} SOURCES) | ||
| 34 | list(REMOVE_ITEM sources ${pch_source}) | ||
| 35 | foreach(exclude_source IN LISTS PCH_EXCLUDE_SOURCES) | ||
| 36 | list(REMOVE_ITEM sources ${exclude_source}) | ||
| 37 | endforeach() | ||
| 38 | set_source_files_properties(${sources} | ||
| 39 | PROPERTIES COMPILE_FLAGS "/Yu\"${pch_header}\" /Fp\"${pch_binary}\" /FI\"${pch_header}\"" | ||
| 40 | OBJECT_DEPENDS "${pch_binary}") | ||
| 41 | |||
| 42 | # Set compile options for precompiled header | ||
| 43 | if(NOT PCH_PCH_TARGET OR NOT TARGET ${PCH_PCH_TARGET}_pch) | ||
| 44 | set_source_files_properties(${pch_source} | ||
| 45 | PROPERTIES COMPILE_FLAGS "/Yc\"${pch_header}\" /Fp\"${pch_binary}\"" | ||
| 46 | OBJECT_OUTPUTS "${pch_binary}") | ||
| 47 | endif() | ||
| 48 | |||
| 49 | # Compile precompiled header | ||
| 50 | if(PCH_PCH_TARGET) | ||
| 51 | # As own target for usage in multiple libraries | ||
| 52 | if(NOT TARGET ${PCH_PCH_TARGET}_pch) | ||
| 53 | add_library(${PCH_PCH_TARGET}_pch STATIC ${pch_source}) | ||
| 54 | set_target_properties(${PCH_PCH_TARGET}_pch PROPERTIES COMPILE_PDB_NAME vc140 | ||
| 55 | COMPILE_PDB_OUTPUT_DIRECTORY ${PRECOMPILEDHEADER_DIR} | ||
| 56 | FOLDER "Build Utilities") | ||
| 57 | endif() | ||
| 58 | # From VS2012 onwards, precompiled headers have to be linked against (LNK2011). | ||
| 59 | target_link_libraries(${target} PUBLIC ${PCH_PCH_TARGET}_pch) | ||
| 60 | set_target_properties(${target} PROPERTIES COMPILE_PDB_NAME vc140 | ||
| 61 | COMPILE_PDB_OUTPUT_DIRECTORY ${PRECOMPILEDHEADER_DIR}) | ||
| 62 | else() | ||
| 63 | # As part of the target | ||
| 64 | target_sources(${target} PRIVATE ${pch_source}) | ||
| 65 | endif() | ||
| 66 | endfunction() | ||
