Skip to content

Commit fb44d19

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

File tree

20 files changed

+1443
-0
lines changed

20 files changed

+1443
-0
lines changed

CMakeLists.txt

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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+
if (DAEMON_C_COMPILER_Clang_COMPATIBILITY)
111+
add_subdirectory(src/trusted/service_runtime/linux)
112+
else()
113+
if (CMAKE_GENERATOR MATCHES "Visual Studio")
114+
set(BOOTSTRAP_GENERATOR "NMake Makefiles")
115+
else()
116+
set(BOOTSTRAP_GENERATOR "${CMAKE_GENERATOR}")
117+
endif()
118+
119+
find_program(CLANG_C_COMPILER NAMES "clang" DOC "Path to the Clang C compiler." REQUIRED)
120+
find_program(CLANG_CXX_COMPILER NAMES "clang++" DOC "Path to the Clang C++ compiler." REQUIRED)
121+
122+
if (NOT CLANG_TARGET)
123+
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -dumpmachine
124+
OUTPUT_VARIABLE CLANG_TARGET
125+
OUTPUT_STRIP_TRAILING_WHITESPACE
126+
# CMake 3.18.4 from Debian Buster doesn't support that option:
127+
# COMMAND_ERROR_IS_FATAL ANY
128+
)
129+
130+
if (NOT CLANG_TARGET)
131+
message(FATAL_ERROR "Failed to read the compiler target.")
132+
endif()
133+
endif()
134+
135+
foreach(inherited_option ${INHERITED_OPTIONS})
136+
list(APPEND INHERITED_OPTION_ARGS "-D${inherited_option}=${${inherited_option}}")
137+
endforeach()
138+
139+
set(BOOTSTRAP_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/nacl_helper_bootstrap-build")
140+
141+
include(ExternalProject)
142+
143+
ExternalProject_Add(nacl_helper_bootstrap-project
144+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
145+
BINARY_DIR "${BOOTSTRAP_BUILD_DIR}"
146+
CMAKE_GENERATOR "${BOOTSTRAP_GENERATOR}"
147+
CMAKE_ARGS
148+
"-DCMAKE_BUILT_TYPE=${CMAKE_BUILD_TYPE}"
149+
"-DCMAKE_C_COMPILER=${CLANG_C_COMPILER}"
150+
"-DCMAKE_CXX_COMPILER=${CLANG_CXX_COMPILER}"
151+
"-DCMAKE_C_FLAGS=--target=${CLANG_TARGET}"
152+
"-DCMAKE_CXX_FLAGS=--target=${CLANG_TARGET}"
153+
-DBUILD_NACL_LOADER=OFF
154+
-DBUILD_NACL_HELPER_BOOTSTRAP=ON
155+
${INHERITED_OPTION_ARGS}
156+
# CMake 3.18.4 from Debian Buster doesn't support that option:
157+
# INSTALL_BYPRODUCTS
158+
INSTALL_COMMAND echo
159+
)
160+
161+
add_custom_target(nacl_helper_bootstrap ALL
162+
COMMAND "${CMAKE_COMMAND}" -E copy "${BOOTSTRAP_BUILD_DIR}/nacl_helper_bootstrap"
163+
"${CMAKE_CURRENT_BINARY_DIR}/nacl_helper_bootstrap"
164+
BYPRODUCTS
165+
"${CMAKE_CURRENT_BINARY_DIR}/nacl_helper_bootstrap"
166+
DEPENDS nacl_helper_bootstrap-project
167+
)
168+
endif()
169+
endif()

0 commit comments

Comments
 (0)