|
| 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 | +option(BUILD_NACL_LOADER "Build the sel_ldr program." ON) |
| 13 | + |
| 14 | +if (LINUX) |
| 15 | + option(BUILD_NACL_HELPER_BOOTSTRAP "Build the nacl_helper_bootstrap program on platforms requiring it." ON) |
| 16 | +endif() |
| 17 | + |
| 18 | +# TODO(arbenson): remove this once binutils bug is fixed (see |
| 19 | +# src/trusted/service_runtime/arch/x86_64/sel_addrspace_posix_x86_64.c) |
| 20 | +if (BUILD_NACL_LOADER AND NOT WIN32) |
| 21 | + option(USE_AMD64_ZERO_BASED_SANDBOX "Allow the zero-based sandbox model to run insecurely." OFF) |
| 22 | +endif() |
| 23 | + |
| 24 | +if (BUILD_NACL_LOADER AND WIN32) |
| 25 | + option(FORCE_NO_TRUSTED_BUILD "Prevent use of trusted toolchain." OFF) |
| 26 | +endif() |
| 27 | + |
| 28 | +if (BUILD_NACL_LOADER AND WIN32) |
| 29 | + set(REQUIRE_MASM ON) |
| 30 | +endif() |
| 31 | + |
| 32 | +if (BUILD_NACL_LOADER AND APPLE) |
| 33 | + set(REQUIRE_PYTHON ON) |
| 34 | +endif() |
| 35 | + |
| 36 | +if (BUILD_NACL_HELPER_BOOTSTRAP) |
| 37 | + set(REQUIRE_PYTHON ON) |
| 38 | +endif() |
| 39 | + |
| 40 | +if (REQUIRE_PYTHON) |
| 41 | + if (NOT PYTHON) |
| 42 | + find_program(PYTHON NAMES "python3" DOC "Path to the python3 executable." REQUIRED) |
| 43 | + endif() |
| 44 | +endif() |
| 45 | + |
| 46 | +if (REQUIRE_MASM) |
| 47 | + if (NOT MSVC AND NOT CMAKE_ASM_MASM_COMPILER) |
| 48 | + include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include-hax/fake_masm") |
| 49 | + |
| 50 | + find_program(JWASM NAMES "jwasm" DOC "Path to the JWasm executable." REQUIRED) |
| 51 | + |
| 52 | + set(CMAKE_ASM_MASM_COMPILER "${JWASM}") |
| 53 | + |
| 54 | + if (ARCH_i686) |
| 55 | + list(APPEND CMAKE_ASM_MASM_FLAGS "-coff") |
| 56 | + elseif(ARCH_amd64) |
| 57 | + list(APPEND CMAKE_ASM_MASM_FLAGS "-win64") |
| 58 | + endif() |
| 59 | + endif() |
| 60 | + |
| 61 | + enable_language(ASM_MASM) |
| 62 | +endif() |
| 63 | + |
| 64 | +include_directories("include-hax") |
| 65 | + |
| 66 | +if (ARCH_i686) |
| 67 | + set(ARCH_SUFFIX "_x86_32") |
| 68 | +elseif (ARCH_amd64) |
| 69 | + set(ARCH_SUFFIX "_X86_64") |
| 70 | +elseif (ARCH_armhf OR ARCH_armel) |
| 71 | + set(ARCH_SUFFIX "_arm") |
| 72 | +elseif (ARCH_mipsel) |
| 73 | + set(ARCH_SUFFIX "_mips32") |
| 74 | +endif() |
| 75 | + |
| 76 | +# FIXME: In src/shared/imc/build.scons it is only done on Linux but not on Android. |
| 77 | +find_library(LIBRT rt) |
| 78 | + |
| 79 | +if (BUILD_NACL_LOADER) |
| 80 | + add_subdirectory(src/shared/gio) |
| 81 | + add_subdirectory(src/shared/imc) |
| 82 | + add_subdirectory(src/shared/platform) |
| 83 | + add_subdirectory(src/trusted/cpu_features) |
| 84 | + add_subdirectory(src/trusted/debug_stub) |
| 85 | + add_subdirectory(src/trusted/desc) |
| 86 | + add_subdirectory(src/trusted/fault_injection) |
| 87 | + add_subdirectory(src/trusted/interval_multiset) |
| 88 | + add_subdirectory(src/trusted/nacl_base) |
| 89 | + add_subdirectory(src/trusted/perf_counter) |
| 90 | + add_subdirectory(src/trusted/platform_qualify) |
| 91 | + add_subdirectory(src/trusted/validator) |
| 92 | + |
| 93 | + if (ARCH_i686 OR ARCH_amd64) |
| 94 | + add_subdirectory(src/trusted/validator_x86) |
| 95 | + add_subdirectory(src/trusted/validator_ragel) |
| 96 | + elseif (ARCH_armhf OR ARCH_armel) |
| 97 | + add_subdirectory(src/trusted/validator_arm) |
| 98 | + elseif (ARCH_mipsel) |
| 99 | + add_subdirectory(src/trusted/validator_mips) |
| 100 | + endif() |
| 101 | +endif() |
| 102 | + |
| 103 | +if (BUILD_NACL_LOADER) |
| 104 | + add_subdirectory(src/trusted/service_runtime) |
| 105 | +endif() |
| 106 | + |
| 107 | +if (BUILD_NACL_HELPER_BOOTSTRAP) |
| 108 | + if (DAEMON_CXX_COMPILER_Clang_COMPATIBILITY) |
| 109 | + add_subdirectory(src/trusted/service_runtime/linux) |
| 110 | + else() |
| 111 | + if (CMAKE_GENERATOR MATCHES "Visual Studio") |
| 112 | + set(BOOTSTRAP_GENERATOR "NMake Makefiles") |
| 113 | + else() |
| 114 | + set(BOOTSTRAP_GENERATOR "${CMAKE_GENERATOR}") |
| 115 | + endif() |
| 116 | + |
| 117 | + find_program(CLANG_C_COMPILER NAMES "clang" DOC "Path to the Clang C compiler." REQUIRED) |
| 118 | + find_program(CLANG_CXX_COMPILER NAMES "clang++" DOC "Path to the Clang C++ compiler." REQUIRED) |
| 119 | + |
| 120 | + if (NOT CLANG_TARGET) |
| 121 | + execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -dumpmachine |
| 122 | + OUTPUT_VARIABLE CLANG_TARGET |
| 123 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 124 | + COMMAND_ERROR_IS_FATAL ANY |
| 125 | + ) |
| 126 | + endif() |
| 127 | + |
| 128 | + include(ExternalProject) |
| 129 | + |
| 130 | + ExternalProject_Add(nacl_helper_bootstrap |
| 131 | + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" |
| 132 | + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/nacl_helper_bootstrap-build" |
| 133 | + CMAKE_GENERATOR "${BOOTSTRAP_GENERATOR}" |
| 134 | + CMAKE_ARGS |
| 135 | + "-DCMAKE_C_COMPILER=${CLANG_C_COMPILER}" |
| 136 | + "-DCMAKE_CXX_COMPILER=${CLANG_CXX_COMPILER}" |
| 137 | + "-DCMAKE_C_FLAGS=--target=${CLANG_TARGET}" |
| 138 | + "-DCMAKE_CXX_FLAGS=--target=${CLANG_TARGET}" |
| 139 | + "-DUSE_AMD64_ZERO_BASED_SANDBOX=${USE_AMD64_ZERO_BASED_SANDBOX}" |
| 140 | + -DBUILD_NACL_LOADER=OFF |
| 141 | + -DBUILD_NACL_HELPER_BOOTSTRAP=ON |
| 142 | + INSTALL_COMMAND "${CMAKE_COMMAND}" -E copy nacl_helper_bootstrap |
| 143 | + "${CMAKE_CURRENT_BINARY_DIR}/nacl_helper_bootstrap" |
| 144 | + ) |
| 145 | + endif() |
| 146 | +endif() |
0 commit comments