forked from commontk/AppLauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsvc-static-configure.cmake
120 lines (108 loc) · 4.54 KB
/
msvc-static-configure.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#
# This script was designed to be executed from the build directory:
#
# cd build
# $env:APPLAUNCHER_CMAKE_GENERATOR="Visual Studio 15 2017" # or "Ninja"
# cmake -DQt5_DIR:PATH=$Qt5_DIR -DCTKAppLauncher_SOURCE_DIR:PATH=$pwd.Path + "\.." -P ..\msvc-static-configure.cmake
#
# Static build of Qt5 may be download from
#
# https://github.com/jcfr/qt-static-build/releases/tag/applauncher-5.11.2-vs2017
#
if(NOT EXISTS "${Qt5_DIR}")
message(FATAL_ERROR "Qt5_DIR is set to a non-existent directory [${Qt5_DIR}]")
endif()
if(NOT EXISTS "${CTKAppLauncher_SOURCE_DIR}")
message(FATAL_ERROR "CTKAppLauncher_SOURCE_DIR is set to a non-existent directory [${CTKAppLauncher_SOURCE_DIR}]")
endif()
if(NOT "$ENV{APPLAUNCHER_CMAKE_GENERATOR}" MATCHES "^Ninja|Visual Studio 15 2017$")
message(FATAL_ERROR "Env. variable APPLAUNCHER_CMAKE_GENERATOR is expected to match 'Ninja' or 'Visual Studio 15 2017' [$ENV{APPLAUNCHER_CMAKE_GENERATOR}]")
endif()
set(APPLAUNCHER_CMAKE_GENERATOR "$ENV{APPLAUNCHER_CMAKE_GENERATOR}")
message(STATUS "Selected CMake Generator is '${APPLAUNCHER_CMAKE_GENERATOR}'")
if(APPLAUNCHER_CMAKE_GENERATOR STREQUAL "Ninja")
# Download FindVcvars.cmake
set(dest_file "${CMAKE_CURRENT_BINARY_DIR}/FindVcvars.cmake")
set(expected_hash "b36aa3fb2ce86132e55a8d59f4513cf7d1e0b46bad214adccca8643fadec66d0")
set(url "https://raw.githubusercontent.com/scikit-build/cmake-FindVcvars/v1.2/FindVcvars.cmake")
if(NOT EXISTS ${dest_file})
file(DOWNLOAD ${url} ${dest_file} EXPECTED_HASH SHA256=${expected_hash})
else()
file(SHA256 ${dest_file} current_hash)
if(NOT ${current_hash} STREQUAL ${expected_hash})
file(DOWNLOAD ${url} ${dest_file} EXPECTED_HASH SHA256=${expected_hash})
endif()
endif()
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_BINARY_DIR}")
# Lookup vcvars script
set(Vcvars_MSVC_ARCH 32)
set(Vcvars_MSVC_VERSION 1915)
find_package(Vcvars REQUIRED)
# Download ninja archive
set(archive_basename "ninja-1.8.2.g81279.kitware.dyndep-1.jobserver-1_i686-pc-windows-msvc")
set(dest_file "${CMAKE_CURRENT_BINARY_DIR}/${archive_basename}.zip")
set(expected_hash "eaa2a0f1b0d273a19a0a00365208e9ec8e3f6181771c7fb0adae93aaf24c32c6")
set(url "https://github.com/Kitware/ninja/releases/download/v1.8.2.g81279.kitware.dyndep-1.jobserver-1/${archive_basename}.zip")
if(NOT EXISTS ${dest_file})
file(DOWNLOAD ${url} ${dest_file} EXPECTED_HASH SHA256=${expected_hash})
else()
file(SHA256 ${dest_file} current_hash)
if(NOT ${current_hash} STREQUAL ${expected_hash})
file(DOWNLOAD ${url} ${dest_file} EXPECTED_HASH SHA256=${expected_hash})
endif()
endif()
# Then, extract archive
execute_process(COMMAND ${CMAKE_COMMAND} -E tar x ${dest_file})
# Finally, update PATH
set(ENV{PATH} "${CMAKE_CURRENT_BINARY_DIR}/${archive_basename};$ENV{PATH}")
endif()
set(QT_PREFIX_DIR "${Qt5_DIR}/../../../")
get_filename_component(QT_PREFIX_DIR ${QT_PREFIX_DIR} ABSOLUTE)
message(STATUS "Setting QT_PREFIX_DIR: ${QT_PREFIX_DIR}")
# Dependencies of QPA plugin needed for running GUI based application
# and avoid runtime error: qt.qpa.plugin: Could not find the Qt platform plugin "windows" in ""
set(qt_qpa_plugin_static_libraries
${QT_PREFIX_DIR}/lib/Qt5EventDispatcherSupport.lib
${QT_PREFIX_DIR}/lib/Qt5FontDatabaseSupport.lib
${QT_PREFIX_DIR}/lib/Qt5ThemeSupport.lib
${QT_PREFIX_DIR}/lib/Qt5WindowsUIAutomationSupport.lib
Dwmapi.lib
Imm32.lib
)
set(qt_static_libraries
# Qt
${QT_PREFIX_DIR}/lib/qtharfbuzz.lib
${QT_PREFIX_DIR}/lib/qtlibpng.lib
${QT_PREFIX_DIR}/lib/qtpcre2.lib
${QT_PREFIX_DIR}/plugins/platforms/qwindows.lib
${qt_qpa_plugin_static_libraries}
# Windows API
Netapi32.lib
OLDNAMES.LIB
Userenv.lib
version.lib
Winmm.lib
Ws2_32.lib
# C runtime - https://msdn.microsoft.com/en-us/library/abx4dbyh.aspx#Anchor_0
libcmt.lib
libvcruntime.lib
libucrt.lib
# C++ runtime - See https://msdn.microsoft.com/en-us/library/abx4dbyh.aspx#Anchor_1
LIBCPMT.lib
)
set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG")
set(INITIAL_CACHE "
ADDITIONAL_EXE_LINKER_FLAGS_RELEASE:STRING=/nodefaultlib
BUILD_TESTING:BOOL=1
CMAKE_CXX_FLAGS_RELEASE:STRING=${CMAKE_CXX_FLAGS_RELEASE}
CTKAppLauncher_QT_STATIC_LIBRARIES:STRING=${qt_static_libraries}
Qt5_DIR:PATH=${Qt5_DIR}"
)
if(APPLAUNCHER_CMAKE_GENERATOR STREQUAL "Ninja")
set(INITIAL_CACHE "${INITIAL_CACHE}
CMAKE_BUILD_TYPE:STRING=Release"
)
endif()
file(WRITE CMakeCache.txt "${INITIAL_CACHE}")
set(ENV{LDFLAGS} "/INCREMENTAL:NO /LTCG")
execute_process(COMMAND ${Vcvars_LAUNCHER} ${CMAKE_COMMAND} -G ${APPLAUNCHER_CMAKE_GENERATOR} ${CTKAppLauncher_SOURCE_DIR})