Skip to content

Commit 2fafd30

Browse files
committed
cmake: add CMake scripts to to build sel_ldr and nacl_helper_bootstrap
1 parent 4d52999 commit 2fafd30

File tree

20 files changed

+1462
-0
lines changed

20 files changed

+1462
-0
lines changed

CMakeLists.txt

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
if (COMPILER_TARGET)
4+
set(CMAKE_C_COMPILER_TARGET "${COMPILER_TARGET}")
5+
set(CMAKE_CXX_COMPILER_TARGET "${COMPILER_TARGET}")
6+
set(CMAKE_ASM_COMPILER_TARGET "${COMPILER_TARGET}")
7+
endif()
8+
9+
project(native_client C CXX ASM)
10+
11+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
12+
13+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
14+
15+
include(DaemonPlatform/Platform)
16+
include(NaClFlags)
17+
18+
if (NOT CMAKE_BUILD_TYPE)
19+
set(CMAKE_BUILD_TYPE RelWithDebInfo)
20+
endif()
21+
22+
option(BUILD_NACL_LOADER "Build the sel_ldr program." ON)
23+
24+
if (LINUX)
25+
option(BUILD_NACL_HELPER_BOOTSTRAP "Build the nacl_helper_bootstrap program on platforms requiring it." ON)
26+
endif()
27+
28+
# TODO(arbenson): remove this once binutils bug is fixed (see
29+
# src/trusted/service_runtime/arch/x86_64/sel_addrspace_posix_x86_64.c)
30+
if (BUILD_NACL_LOADER AND ARCH_amd64 AND NOT WIN32)
31+
option(USE_AMD64_ZERO_BASED_SANDBOX "Allow the zero-based sandbox model to run insecurely." OFF)
32+
list(APPEND INHERITED_OPTIONS "USE_AMD64_ZERO_BASED_SANDBOX")
33+
endif()
34+
35+
if (BUILD_NACL_LOADER AND WIN32)
36+
option(FORCE_NO_TRUSTED_BUILD "Prevent use of trusted toolchain." OFF)
37+
endif()
38+
39+
if (BUILD_NACL_LOADER AND WIN32)
40+
set(REQUIRE_MASM ON)
41+
endif()
42+
43+
if (BUILD_NACL_LOADER AND APPLE)
44+
set(REQUIRE_PYTHON ON)
45+
endif()
46+
47+
if (BUILD_NACL_HELPER_BOOTSTRAP)
48+
set(REQUIRE_PYTHON ON)
49+
endif()
50+
51+
if (REQUIRE_PYTHON)
52+
if (NOT PYTHON)
53+
find_program(PYTHON NAMES "python3" DOC "Path to the python3 executable." REQUIRED)
54+
endif()
55+
endif()
56+
57+
if (REQUIRE_MASM)
58+
if (NOT MSVC AND NOT CMAKE_ASM_MASM_COMPILER)
59+
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include-hax/fake_masm")
60+
61+
find_program(JWASM NAMES "jwasm" DOC "Path to the JWasm executable." REQUIRED)
62+
63+
set(CMAKE_ASM_MASM_COMPILER "${JWASM}")
64+
65+
if (ARCH_i686)
66+
list(APPEND CMAKE_ASM_MASM_FLAGS "-coff")
67+
elseif(ARCH_amd64)
68+
list(APPEND CMAKE_ASM_MASM_FLAGS "-win64")
69+
endif()
70+
endif()
71+
72+
enable_language(ASM_MASM)
73+
endif()
74+
75+
include_directories("include-hax")
76+
77+
if (ARCH_i686)
78+
set(ARCH_SUFFIX "_x86_32")
79+
elseif (ARCH_amd64)
80+
set(ARCH_SUFFIX "_X86_64")
81+
elseif (ARCH_armhf OR ARCH_armel)
82+
set(ARCH_SUFFIX "_arm")
83+
elseif (ARCH_mipsel)
84+
set(ARCH_SUFFIX "_mips32")
85+
endif()
86+
87+
if (BUILD_NACL_LOADER)
88+
add_subdirectory(src/shared/gio)
89+
add_subdirectory(src/shared/imc)
90+
add_subdirectory(src/shared/platform)
91+
add_subdirectory(src/trusted/cpu_features)
92+
add_subdirectory(src/trusted/debug_stub)
93+
add_subdirectory(src/trusted/desc)
94+
add_subdirectory(src/trusted/fault_injection)
95+
add_subdirectory(src/trusted/interval_multiset)
96+
add_subdirectory(src/trusted/nacl_base)
97+
add_subdirectory(src/trusted/perf_counter)
98+
add_subdirectory(src/trusted/platform_qualify)
99+
add_subdirectory(src/trusted/validator)
100+
101+
if (ARCH_i686 OR ARCH_amd64)
102+
add_subdirectory(src/trusted/validator_x86)
103+
add_subdirectory(src/trusted/validator_ragel)
104+
elseif (ARCH_armhf OR ARCH_armel)
105+
add_subdirectory(src/trusted/validator_arm)
106+
elseif (ARCH_mipsel)
107+
add_subdirectory(src/trusted/validator_mips)
108+
endif()
109+
endif()
110+
111+
if (BUILD_NACL_LOADER)
112+
add_subdirectory(src/trusted/service_runtime)
113+
endif()
114+
115+
if (BUILD_NACL_HELPER_BOOTSTRAP)
116+
option(BUILD_NACL_HELPER_BOOTSTRAP_WITH_CLANG "Build the nacl_helper_bootstrap program with Clang." ON)
117+
endif()
118+
119+
if (BUILD_NACL_HELPER_BOOTSTRAP)
120+
if (DAEMON_C_COMPILER_Clang_COMPATIBILITY)
121+
set(BUILD_BOOTSTRAP_DIRECTLY ON)
122+
elseif (NOT BUILD_NACL_HELPER_BOOTSTRAP_WITH_CLANG)
123+
set(BUILD_BOOTSTRAP_DIRECTLY ON)
124+
endif()
125+
126+
if (BUILD_BOOTSTRAP_DIRECTLY)
127+
add_subdirectory(src/trusted/service_runtime/linux)
128+
else()
129+
if (CMAKE_GENERATOR MATCHES "Visual Studio")
130+
set(BOOTSTRAP_GENERATOR "NMake Makefiles")
131+
else()
132+
set(BOOTSTRAP_GENERATOR "${CMAKE_GENERATOR}")
133+
endif()
134+
135+
find_program(CLANG_C_COMPILER NAMES "clang" DOC "Path to the Clang C compiler." REQUIRED)
136+
find_program(CLANG_CXX_COMPILER NAMES "clang++" DOC "Path to the Clang C++ compiler." REQUIRED)
137+
find_program(CLANG_ASM_COMPILER NAMES "clang" DOC "Path to the Clang Asm compiler." REQUIRED)
138+
139+
if (NOT COMPILER_TARGET)
140+
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -dumpmachine
141+
OUTPUT_VARIABLE COMPILER_TARGET
142+
OUTPUT_STRIP_TRAILING_WHITESPACE
143+
# CMake 3.18.4 from Debian Buster doesn't support that option:
144+
# COMMAND_ERROR_IS_FATAL ANY
145+
)
146+
147+
if (NOT COMPILER_TARGET)
148+
message(FATAL_ERROR "Failed to read the compiler target.")
149+
endif()
150+
endif()
151+
152+
foreach(inherited_option ${INHERITED_OPTIONS})
153+
list(APPEND INHERITED_OPTION_ARGS "-D${inherited_option}=${${inherited_option}}")
154+
endforeach()
155+
156+
set(BOOTSTRAP_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/nacl_helper_bootstrap-build")
157+
158+
include(ExternalProject)
159+
160+
ExternalProject_Add(nacl_helper_bootstrap-project
161+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
162+
BINARY_DIR "${BOOTSTRAP_BUILD_DIR}"
163+
CMAKE_GENERATOR "${BOOTSTRAP_GENERATOR}"
164+
CMAKE_ARGS
165+
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
166+
"-DCMAKE_C_COMPILER=${CLANG_C_COMPILER}"
167+
"-DCMAKE_CXX_COMPILER=${CLANG_CXX_COMPILER}"
168+
"-DCMAKE_ASM_COMPILER=${CLANG_ASM_COMPILER}"
169+
"-DCMAKE_C_COMPILER_TARGET=${COMPILER_TARGET}"
170+
"-DCMAKE_CXX_COMPILER_TARGET=${COMPILER_TARGET}"
171+
"-DCMAKE_ASM_COMPILER_TARGET=${COMPILER_TARGET}"
172+
-DBUILD_NACL_LOADER=OFF
173+
-DBUILD_NACL_HELPER_BOOTSTRAP=ON
174+
${INHERITED_OPTION_ARGS}
175+
# CMake 3.18.4 from Debian Buster doesn't support that option:
176+
# INSTALL_BYPRODUCTS
177+
INSTALL_COMMAND echo
178+
)
179+
180+
add_custom_target(nacl_helper_bootstrap ALL
181+
COMMAND "${CMAKE_COMMAND}" -E copy "${BOOTSTRAP_BUILD_DIR}/nacl_helper_bootstrap"
182+
"${CMAKE_CURRENT_BINARY_DIR}/nacl_helper_bootstrap"
183+
BYPRODUCTS
184+
"${CMAKE_CURRENT_BINARY_DIR}/nacl_helper_bootstrap"
185+
DEPENDS nacl_helper_bootstrap-project
186+
)
187+
endif()
188+
endif()

0 commit comments

Comments
 (0)