2012-06-11 18:34:40 +00:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
# or more contributor license agreements. See the NOTICE file
|
|
|
|
# distributed with this work for additional information
|
|
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
|
|
# to you under the Apache License, Version 2.0 (the
|
|
|
|
# "License"); you may not use this file except in compliance
|
|
|
|
# with the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2017-07-20 00:51:14 +00:00
|
|
|
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
|
2012-06-11 18:34:40 +00:00
|
|
|
|
2015-06-30 23:24:19 +00:00
|
|
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../../../../hadoop-common-project/hadoop-common)
|
|
|
|
include(HadoopCommon)
|
2012-06-11 18:34:40 +00:00
|
|
|
|
2017-08-09 17:51:29 +00:00
|
|
|
# Set gtest path
|
|
|
|
set(GTEST_SRC_DIR ${CMAKE_SOURCE_DIR}/../../../../../hadoop-common-project/hadoop-common/src/main/native/gtest)
|
|
|
|
|
2016-08-03 05:24:34 +00:00
|
|
|
# determine if container-executor.conf.dir is an absolute
|
|
|
|
# path in case the OS we're compiling on doesn't have
|
|
|
|
# a hook in get_executable. We'll use this define
|
|
|
|
# later in the code to potentially throw a compile error
|
|
|
|
string(REGEX MATCH . HCD_ONE "${HADOOP_CONF_DIR}")
|
|
|
|
string(COMPARE EQUAL ${HCD_ONE} / HADOOP_CONF_DIR_IS_ABS)
|
|
|
|
|
2017-07-20 00:51:14 +00:00
|
|
|
set (CMAKE_C_STANDARD 99)
|
2012-06-11 18:34:40 +00:00
|
|
|
|
2016-08-03 05:24:34 +00:00
|
|
|
include(CheckIncludeFiles)
|
|
|
|
check_include_files("sys/types.h;sys/sysctl.h" HAVE_SYS_SYSCTL_H)
|
|
|
|
|
2014-09-24 15:47:55 +00:00
|
|
|
include(CheckFunctionExists)
|
2016-07-30 15:26:00 +00:00
|
|
|
check_function_exists(canonicalize_file_name HAVE_CANONICALIZE_FILE_NAME)
|
2015-06-30 23:24:19 +00:00
|
|
|
check_function_exists(fcloseall HAVE_FCLOSEALL)
|
2016-07-30 15:26:00 +00:00
|
|
|
check_function_exists(fchmodat HAVE_FCHMODAT)
|
|
|
|
check_function_exists(fdopendir HAVE_FDOPENDIR)
|
|
|
|
check_function_exists(fstatat HAVE_FSTATAT)
|
|
|
|
check_function_exists(openat HAVE_OPENAT)
|
|
|
|
check_function_exists(unlinkat HAVE_UNLINKAT)
|
|
|
|
|
2016-08-03 05:24:34 +00:00
|
|
|
include(CheckSymbolExists)
|
|
|
|
check_symbol_exists(sysctl "sys/types.h;sys/sysctl.h" HAVE_SYSCTL)
|
|
|
|
|
2016-07-30 15:26:00 +00:00
|
|
|
if(APPLE)
|
|
|
|
include_directories( /System/Library/Frameworks )
|
|
|
|
find_library(COCOA_LIBRARY Cocoa)
|
|
|
|
mark_as_advanced(COCOA_LIBRARY)
|
|
|
|
set(EXTRA_LIBS ${COCOA_LIBRARY})
|
|
|
|
endif(APPLE)
|
2014-09-24 15:47:55 +00:00
|
|
|
|
2017-06-23 18:39:37 +00:00
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
|
|
|
|
# Building setuid = attempt to enable stack protection.
|
|
|
|
# assumption here is that the C compiler and the C++
|
|
|
|
# compiler match. need both so that gtest gets same
|
|
|
|
# stack treatment that the real c-e does
|
|
|
|
IF(CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
|
|
|
CHECK_C_COMPILER_FLAG("-fstack-check" STACKRESULT)
|
|
|
|
IF(STACKRESULT)
|
|
|
|
SET (CMAKE_C_FLAGS "-fstack-check ${CMAKE_C_FLAGS}")
|
|
|
|
SET (CMAKE_CXX_FLAGS "-fstack-check ${CMAKE_CXX_FLAGS}")
|
|
|
|
ENDIF()
|
|
|
|
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR
|
|
|
|
CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
|
|
|
|
|
|
|
|
# clang is a bit difficult here:
|
|
|
|
# - some versions don't support the flag
|
|
|
|
# - some versions support the flag, despite not having
|
|
|
|
# the library that is actually required (!)
|
|
|
|
# Notably, Xcode is a problem here.
|
|
|
|
# In the end, this is needlessly complex. :(
|
|
|
|
|
|
|
|
SET(PRE_SANITIZE ${CMAKE_REQUIRED_FLAGS})
|
|
|
|
SET(CMAKE_REQUIRED_FLAGS "-fsanitize=safe-stack ${CMAKE_REQUIRED_FLAGS}")
|
|
|
|
CHECK_C_COMPILER_FLAG("" STACKRESULT)
|
|
|
|
SET(CMAKE_REQUIRED_FLAGS ${PRE_SANITIZE})
|
|
|
|
IF(STACKRESULT)
|
|
|
|
SET(CMAKE_C_FLAGS "-fsanitize=safe-stack ${CMAKE_C_FLAGS}")
|
|
|
|
SET(CMAKE_CXX_FLAGS "-fsanitize=safe-stack ${CMAKE_CXX_FLAGS}")
|
|
|
|
ENDIF()
|
|
|
|
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
|
|
|
|
|
|
|
|
# this appears to only be supported on SPARC, for some reason
|
|
|
|
|
|
|
|
CHECK_C_COMPILER_FLAG("-xcheck=stkovf" STACKRESULT)
|
|
|
|
IF(STACKRESULT)
|
|
|
|
SET (CMAKE_C_FLAGS "-xcheck=stkovf ${CMAKE_C_FLAGS}")
|
|
|
|
SET (CMAKE_CXX_FLAGS "-xcheck=stkovf ${CMAKE_CXX_FLAGS}")
|
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
IF(NOT STACKRESULT)
|
|
|
|
MESSAGE(WARNING "Stack Clash security protection is not suported.")
|
|
|
|
ENDIF()
|
|
|
|
|
2012-06-11 18:34:40 +00:00
|
|
|
function(output_directory TGT DIR)
|
2015-06-30 23:24:19 +00:00
|
|
|
set_target_properties(${TGT} PROPERTIES
|
2012-06-11 18:34:40 +00:00
|
|
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
|
2015-06-30 23:24:19 +00:00
|
|
|
set_target_properties(${TGT} PROPERTIES
|
2012-06-11 18:34:40 +00:00
|
|
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
|
2015-06-30 23:24:19 +00:00
|
|
|
set_target_properties(${TGT} PROPERTIES
|
2012-06-11 18:34:40 +00:00
|
|
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
|
2015-06-30 23:24:19 +00:00
|
|
|
endfunction()
|
2012-06-11 18:34:40 +00:00
|
|
|
|
|
|
|
include_directories(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
${CMAKE_BINARY_DIR}
|
2017-08-09 17:51:29 +00:00
|
|
|
${GTEST_SRC_DIR}/include
|
2012-06-11 18:34:40 +00:00
|
|
|
main/native/container-executor
|
|
|
|
main/native/container-executor/impl
|
|
|
|
)
|
2017-08-09 17:51:29 +00:00
|
|
|
# add gtest as system library to suppress gcc warnings
|
|
|
|
include_directories(SYSTEM ${GTEST_SRC_DIR}/include)
|
|
|
|
|
2015-06-30 23:24:19 +00:00
|
|
|
configure_file(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
|
2012-06-11 18:34:40 +00:00
|
|
|
|
2017-08-09 17:51:29 +00:00
|
|
|
add_library(gtest ${GTEST_SRC_DIR}/gtest-all.cc)
|
|
|
|
set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-w")
|
|
|
|
|
2012-06-11 18:34:40 +00:00
|
|
|
add_library(container
|
2017-08-09 17:51:29 +00:00
|
|
|
main/native/container-executor/impl/util.c
|
2012-06-11 18:34:40 +00:00
|
|
|
main/native/container-executor/impl/configuration.c
|
|
|
|
main/native/container-executor/impl/container-executor.c
|
2016-07-30 15:26:00 +00:00
|
|
|
main/native/container-executor/impl/get_executable.c
|
2017-08-08 19:56:29 +00:00
|
|
|
main/native/container-executor/impl/utils/string-utils.c
|
2017-08-19 01:26:36 +00:00
|
|
|
main/native/container-executor/impl/utils/path-utils.c
|
|
|
|
main/native/container-executor/impl/modules/cgroups/cgroups-operations.c
|
|
|
|
main/native/container-executor/impl/modules/common/module-configs.c
|
|
|
|
main/native/container-executor/impl/modules/gpu/gpu-module.c
|
2012-06-11 18:34:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
add_executable(container-executor
|
|
|
|
main/native/container-executor/impl/main.c
|
|
|
|
)
|
2017-08-09 17:51:29 +00:00
|
|
|
|
2012-06-11 18:34:40 +00:00
|
|
|
target_link_libraries(container-executor
|
|
|
|
container
|
|
|
|
)
|
2017-08-09 17:51:29 +00:00
|
|
|
|
2012-06-11 18:34:40 +00:00
|
|
|
output_directory(container-executor target/usr/local/bin)
|
|
|
|
|
2017-08-19 01:26:36 +00:00
|
|
|
# Test cases
|
2012-06-11 18:34:40 +00:00
|
|
|
add_executable(test-container-executor
|
|
|
|
main/native/container-executor/test/test-container-executor.c
|
|
|
|
)
|
|
|
|
target_link_libraries(test-container-executor
|
2016-07-30 15:26:00 +00:00
|
|
|
container ${EXTRA_LIBS}
|
2012-06-11 18:34:40 +00:00
|
|
|
)
|
2017-08-19 01:26:36 +00:00
|
|
|
|
2012-06-11 18:34:40 +00:00
|
|
|
output_directory(test-container-executor target/usr/local/bin)
|
2017-08-09 17:51:29 +00:00
|
|
|
|
|
|
|
# unit tests for container executor
|
|
|
|
add_executable(cetest
|
|
|
|
main/native/container-executor/impl/util.c
|
|
|
|
main/native/container-executor/test/test_configuration.cc
|
|
|
|
main/native/container-executor/test/test_main.cc
|
2017-08-19 01:26:36 +00:00
|
|
|
main/native/container-executor/test/utils/test-string-utils.cc
|
|
|
|
main/native/container-executor/test/utils/test-path-utils.cc
|
|
|
|
main/native/container-executor/test/modules/cgroups/test-cgroups-module.cc
|
|
|
|
main/native/container-executor/test/modules/gpu/test-gpu-module.cc
|
2017-08-09 17:51:29 +00:00
|
|
|
main/native/container-executor/test/test_util.cc)
|
2017-08-19 01:26:36 +00:00
|
|
|
target_link_libraries(cetest gtest container)
|
2017-08-09 17:51:29 +00:00
|
|
|
output_directory(cetest test)
|