Skip to content

Commit 7914498

Browse files
committed
cmake: add CMake scripts to to build sel_ldr and nacl_helper_bootstrap
1 parent e50f644 commit 7914498

File tree

20 files changed

+1462
-0
lines changed

20 files changed

+1462
-0
lines changed

CMakeLists.txt

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

0 commit comments

Comments
 (0)