-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
133 lines (109 loc) · 4.98 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 2.8.4)
# Use new and simpler escape sequences
cmake_policy(SET CMP0053 NEW)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
# This is to correctly detect the compiler under cygwin!
if ((CMAKE_HOST_UNIX) AND (${CMAKE_HOST_SYSTEM_NAME} MATCHES "CYGWIN*"))
set(CYGWIN 1)
set(WIN 1)
# specify the cross compiler
set(CMAKE_TOOLCHAIN_PREFIX x86_64-w64-mingw32)
SET(CMAKE_C_COMPILER ${CMAKE_TOOLCHAIN_PREFIX}-clang)
SET(CMAKE_CXX_COMPILER ${CMAKE_TOOLCHAIN_PREFIX}-clang++)
SET(CMAKE_RC_COMPILER ${CMAKE_TOOLCHAIN_PREFIX}-windres)
SET(CMAKE_SYSTEM_PROCESSOR x86_64)
endif()
#Creating a new project
project(EmbeddedExample)
# Setting the output of the product
set(EXECUTABLE_OUTPUT_PATH "build/output")
#We set some compiller flags: just to include debugging symbols.
set(CMAKE_C_FLAGS "-g")
set(CMAKE_CXX_FLAGS "-g")
#Adding the generation of the resource file with the correct paths.
configure_file(src/resources.rc.in
${CMAKE_CURRENT_BINARY_DIR}/build/src/resources.rc)
# 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 ${CMAKE_CURRENT_SOURCE_DIR} --mixed
OUTPUT_VARIABLE CMAKE_CURRENT_SOURCE_DIR_TO_OUT
OUTPUT_STRIP_TRAILING_WHITESPACE)
#
# This section is to generate the image.
# We will have a serie of targets to download the image, download a vm and to load the code.
#
make_directory(${CMAKE_CURRENT_BINARY_DIR}/build/vm)
make_directory(${CMAKE_CURRENT_BINARY_DIR}/build/resources)
# Adding a task to download the vm
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/build/vm/pharo
COMMAND wget -O - https://get.pharo.org/64/vm110 | bash
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/vm
COMMENT "Downloading Pharo 110 VM (headless)")
# Adding a task to download the image
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/build/resources/Pharo.image
COMMAND wget -O - https://get.pharo.org/64/110 | bash
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/resources
COMMENT "Downloading Pharo 110 Image")
# Loading the code
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/build/resources/codeLoaded.txt
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/build/vm/pharo Pharo.image --save --quit ${CMAKE_CURRENT_SOURCE_DIR_TO_OUT}/scripts/installSmalltalkCode.st ${CMAKE_CURRENT_SOURCE_DIR_TO_OUT}
COMMAND touch codeLoaded.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/resources
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/build/resources/Pharo.image
${CMAKE_CURRENT_BINARY_DIR}/build/vm/pharo
COMMENT "Load Code")
#
# This section download the header files and to extract the libs from the VM.
#
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/build/include/pharovm/pharo.h
COMMAND wget http://files.pharo.org/vm/pharo-spur64-headless/Windows-x86_64/include/latest10.zip
COMMAND unzip latest10.zip
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build
COMMENT "Downloading Pharo 110 VM Headers")
#
# This section download the header files and to extract the libs from the VM.
#
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/build/lib/libPharoVMCore.a
${CMAKE_CURRENT_BINARY_DIR}/build/output/PharoVMCore.dll
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/build/lib
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/build/output
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/build/vm/pharo-vm/*.dll ${CMAKE_CURRENT_BINARY_DIR}/build/lib
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/build/vm/pharo-vm/*.dll ${CMAKE_CURRENT_BINARY_DIR}/build/output
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/build/vm/pharo-vm/*.a ${CMAKE_CURRENT_BINARY_DIR}/build/lib
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/build/vm/pharo
${CMAKE_CURRENT_BINARY_DIR}/build/include/pharovm/pharo.h
COMMENT "Extracting Libs")
#Setting the include directories
# - The includes in this project
# - The includes from the VM code
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/build/include/
${CMAKE_CURRENT_BINARY_DIR}/build/include/pharovm)
# This are the files to compile in our small project.
set(CLIENT_DEPS
${CMAKE_CURRENT_BINARY_DIR}/build/lib/libPharoVMCore.a
${CMAKE_CURRENT_BINARY_DIR}/build/output/PharoVMCore.dll
${CMAKE_CURRENT_BINARY_DIR}/build/resources/codeLoaded.txt
)
set(CLIENT_SOURCES
src/embeddedImage.c
${CMAKE_CURRENT_BINARY_DIR}/build/src/resources.rc
src/main.c)
# We declare the executable.
add_executable(EmbeddedPharo WIN32 ${CLIENT_DEPS} ${CLIENT_SOURCES})
# We link the executable with the VM library.
target_link_directories(EmbeddedPharo PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/build/lib/)
target_link_libraries(EmbeddedPharo PharoVMCore)