-
Notifications
You must be signed in to change notification settings - Fork 18.6k
/
Copy pathWindowsCreateLinkHeader.cmake
75 lines (67 loc) · 2.89 KB
/
WindowsCreateLinkHeader.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
set(_windows_create_link_header "${CMAKE_CURRENT_LIST_FILE}")
# function to add a post build command to create a link header
function(windows_create_link_header target outputfile)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND}
#-DCMAKE_GENERATOR=${CMAKE_GENERATOR}
-DMSVC_VERSION=${MSVC_VERSION}
-DTARGET_FILE=$<TARGET_FILE:${target}>
#-DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR}
#-DCMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
#-DCONFIGURATION=$<CONFIGURATION>
-DOUTPUT_FILE=${outputfile}
-P ${_windows_create_link_header}
BYPRODUCTS ${outputfile}
)
endfunction()
function(find_dumpbin var)
# MSVC_VERSION =
# 1200 = VS 6.0
# 1300 = VS 7.0
# 1310 = VS 7.1
# 1400 = VS 8.0
# 1500 = VS 9.0
# 1600 = VS 10.0
# 1700 = VS 11.0
# 1800 = VS 12.0
# 1900 = VS 14.0
set(MSVC_PRODUCT_VERSION_1200 6.0)
set(MSVC_PRODUCT_VERSION_1300 7.0)
set(MSVC_PRODUCT_VERSION_1310 7.1)
set(MSVC_PRODUCT_VERSION_1400 8.0)
set(MSVC_PRODUCT_VERSION_1500 9.0)
set(MSVC_PRODUCT_VERSION_1600 10.0)
set(MSVC_PRODUCT_VERSION_1700 11.0)
set(MSVC_PRODUCT_VERSION_1800 12.0)
#Visual Studio 2015, 2017 and 2019 all use the same '14.0' key in the registry
if(${MSVC_VERSION} MATCHES "19[0-2][0-9]")
set(MSVC_PRODUCT_VERSION_${MSVC_VERSION} 14.0)
endif()
get_filename_component(MSVC_VC_DIR [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\${MSVC_PRODUCT_VERSION_${MSVC_VERSION}}\\Setup\\VC;ProductDir] REALPATH CACHE)
find_program(DUMPBIN_EXECUTABLE dumpbin ${MSVC_VC_DIR}/bin)
if(NOT DUMPBIN_EXECUTABLE)
message(FATAL_ERROR "Could not find DUMPBIN_EXECUTABLE please define this variable")
endif()
set(${var} ${DUMPBIN_EXECUTABLE} PARENT_SCOPE)
endfunction()
macro(print_date)
execute_process(COMMAND powershell -NoProfile -Command "get-date")
endmacro()
if(CMAKE_SCRIPT_MODE_FILE)
cmake_policy(SET CMP0007 NEW)
# find the dumpbin exe
find_dumpbin(dumpbin)
# execute dumpbin to generate a list of symbols
execute_process(COMMAND ${dumpbin} /SYMBOLS ${TARGET_FILE}
RESULT_VARIABLE _result
OUTPUT_VARIABLE _output
ERROR_VARIABLE _error
)
# match all layers and solvers instantiation guard
string(REGEX MATCHALL "\\?gInstantiationGuard[^\\(\\) ]*" __symbols ${_output})
# define a string to generate a list of pragmas
foreach(__symbol ${__symbols})
set(__pragma "${__pragma}#pragma comment(linker, \"/include:${__symbol}\")\n")
endforeach()
file(WRITE ${OUTPUT_FILE} ${__pragma})
endif()