-
Notifications
You must be signed in to change notification settings - Fork 71
/
Windows.cmake
181 lines (144 loc) · 6.5 KB
/
Windows.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
set(WIN 1)
set(VM_EXECUTABLE_CONSOLE_NAME "${VM_EXECUTABLE_NAME}Console")
set(VM_VERSION_FILEVERSION "${APPNAME}VM-${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${GIT_COMMIT_HASH}")
set(Win32ResourcesFolder "${CMAKE_CURRENT_SOURCE_DIR}/resources/windows")
if(${CYGWIN})
# transform the path into a windows path with unix backslashes C:/bla/blu
# this is the path required to send as argument to libraries outside of the control of cygwin (like pharo itself)
execute_process(
COMMAND cygpath ${Win32ResourcesFolder} --mixed
OUTPUT_VARIABLE Win32ResourcesFolder_OUT
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
set(Win32ResourcesFolder_OUT ${Win32ResourcesFolder})
endif()
if(NOT Win32VMExecutableIcon)
set(Win32VMExecutableIcon "${Win32ResourcesFolder_OUT}/Pharo.ico")
endif()
include_directories(PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/resources/windows)
set(Win32Resource "${CMAKE_CURRENT_BINARY_DIR}/${VM_EXECUTABLE_NAME}.rc")
set(Win32ConsoleResource "${CMAKE_CURRENT_BINARY_DIR}/${VM_EXECUTABLE_CONSOLE_NAME}.rc")
set(Win32DLLResource "${CMAKE_CURRENT_BINARY_DIR}/${VM_EXECUTABLE_NAME}DLL.rc")
set(Win32Manifest "${CMAKE_CURRENT_BINARY_DIR}/${VM_EXECUTABLE_NAME}.exe.manifest")
set(Win32ConsoleManifest "${CMAKE_CURRENT_BINARY_DIR}/${VM_EXECUTABLE_CONSOLE_NAME}.exe.manifest")
function(add_platform_headers)
target_include_directories(${VM_LIBRARY_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/extracted/vm/include/win
${CMAKE_CURRENT_SOURCE_DIR}/extracted/vm/include/common
)
endfunction()
set(EXTRACTED_SOURCES
#Common sources
${CMAKE_CURRENT_SOURCE_DIR}/extracted/vm/src/common/sqHeapMap.c
${CMAKE_CURRENT_SOURCE_DIR}/extracted/vm/src/common/sqVirtualMachine.c
${CMAKE_CURRENT_SOURCE_DIR}/extracted/vm/src/common/sqNamedPrims.c
${CMAKE_CURRENT_SOURCE_DIR}/extracted/vm/src/common/sqExternalSemaphores.c
${CMAKE_CURRENT_SOURCE_DIR}/extracted/vm/src/common/sqTicker.c
#Platform sources
${CMAKE_CURRENT_SOURCE_DIR}/extracted/vm/src/win/sqWin32SpurAlloc.c
${CMAKE_CURRENT_SOURCE_DIR}/extracted/vm/src/win/aioWin.c
${CMAKE_CURRENT_SOURCE_DIR}/src/win/winDebug.c
${CMAKE_CURRENT_SOURCE_DIR}/src/win/winDebugMenu.c
${CMAKE_CURRENT_SOURCE_DIR}/src/win/winDebugWindow.c
# Support sources
${CMAKE_CURRENT_SOURCE_DIR}/src/fileDialogWin32.c
# Resource with DLL version info.
${Win32DLLResource}
)
set(VM_FRONTEND_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/win32Main.c
${Win32Resource})
set(VM_CONSOLE_FRONTEND_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/win32Main.c
${Win32ConsoleResource})
set(VM_FRONTEND_APPLICATION_TYPE WIN32)
configure_file("${Win32ResourcesFolder}/${VM_EXECUTABLE_NAME}.rc.in" "${Win32Resource}" @ONLY IMMEDIATE)
configure_file("${Win32ResourcesFolder}/${VM_EXECUTABLE_NAME}DLL.rc.in" "${Win32DLLResource}" @ONLY IMMEDIATE)
configure_file("${Win32ResourcesFolder}/${VM_EXECUTABLE_NAME}.exe.manifest.in" "${Win32Manifest}" @ONLY IMMEDIATE)
configure_file("${Win32ResourcesFolder}/${VM_EXECUTABLE_CONSOLE_NAME}.rc.in" "${Win32ConsoleResource}" @ONLY IMMEDIATE)
configure_file("${Win32ResourcesFolder}/${VM_EXECUTABLE_CONSOLE_NAME}.exe.manifest.in" "${Win32ConsoleManifest}" @ONLY IMMEDIATE)
macro(add_third_party_dependencies_per_platform)
if (BUILD_BUNDLE AND CYGWIN)
add_third_party_dependency("gcc-runtime-3.4")
endif()
if(${FEATURE_LIB_GIT2})
include(cmake/importLibGit2.cmake)
endif()
if(${FEATURE_LIB_FREETYPE2})
include(cmake/importFreetype2.cmake)
endif()
if(${FEATURE_LIB_CAIRO})
include(cmake/importCairo.cmake)
endif()
if(${FEATURE_LIB_SDL2})
include(cmake/importSDL2.cmake)
endif()
endmacro()
macro(configure_installables INSTALL_COMPONENT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/build/dist")
install(
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build/vm/"
DESTINATION "./"
COMPONENT ${INSTALL_COMPONENT}
FILES_MATCHING PATTERN *.dll
PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(
FILES "${Win32Manifest}" "${Win32ConsoleManifest}"
DESTINATION "./"
COMPONENT ${INSTALL_COMPONENT})
install(
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build/vm/"
USE_SOURCE_PERMISSIONS
DESTINATION "./"
USE_SOURCE_PERMISSIONS
COMPONENT ${INSTALL_COMPONENT}
FILES_MATCHING
PATTERN *
PATTERN *.dll EXCLUDE)
install(
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build/libffi/install/bin/"
DESTINATION "./"
COMPONENT ${INSTALL_COMPONENT}
FILES_MATCHING PATTERN *.dll
PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/extracted/vm/include/win/"
DESTINATION include/pharovm
COMPONENT include
FILES_MATCHING PATTERN *.h)
endmacro()
macro(add_required_libs_per_platform)
# Compile Windows Using Unicode support
target_compile_definitions(${VM_LIBRARY_NAME}
PRIVATE -D_UNICODE -DUNICODE)
add_executable(${VM_EXECUTABLE_CONSOLE_NAME} ${VM_CONSOLE_FRONTEND_SOURCES})
target_link_libraries(${VM_EXECUTABLE_CONSOLE_NAME} ${VM_LIBRARY_NAME})
target_link_libraries(${VM_LIBRARY_NAME} winmm)
target_link_libraries(${VM_LIBRARY_NAME} Ws2_32)
target_link_libraries(${VM_LIBRARY_NAME} DbgHelp)
target_link_libraries(${VM_LIBRARY_NAME} Ole32)
target_link_libraries(${VM_LIBRARY_NAME} comctl32)
target_link_libraries(${VM_LIBRARY_NAME} uuid)
# Disable Safe Structured Exception Handling
#target_link_libraries(${VM_LIBRARY_NAME} "$<$<CXX_COMPILER_ID:MSVC>:-SAFESEH:NO>")
# pthread is required by tffi and the vm itself. We should always link to it.
if (${FEATURE_LIB_PTHREADW32})
find_package(PTHREADW32)
if(PTHREADW32_FOUND)
target_link_libraries(${VM_LIBRARY_NAME} PTHREADW32::lib)
else()
message(FATAL_ERROR "PTHREADW32 not found. Provide the path in PTHREADW32_DIR env.variable")
endif()
else()
target_link_libraries(${VM_LIBRARY_NAME} pthread)
endif()
target_link_libraries(${VM_EXECUTABLE_NAME} Ole32)
target_link_libraries(${VM_EXECUTABLE_NAME} comctl32)
target_link_libraries(${VM_EXECUTABLE_NAME} uuid)
target_link_libraries(${VM_EXECUTABLE_CONSOLE_NAME} Ole32)
target_link_libraries(${VM_EXECUTABLE_CONSOLE_NAME} comctl32)
target_link_libraries(${VM_EXECUTABLE_CONSOLE_NAME} uuid)
set_target_properties(${VM_EXECUTABLE_NAME} PROPERTIES LINK_FLAGS "-mwindows")
set_target_properties(${VM_EXECUTABLE_CONSOLE_NAME} PROPERTIES LINK_FLAGS "-mconsole")
endmacro()