CMakeLists.txt 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
  17. list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../../../../hadoop-common-project/hadoop-common)
  18. include(HadoopCommon)
  19. # Set gtest path
  20. set(GTEST_SRC_DIR ${CMAKE_SOURCE_DIR}/../../../../../hadoop-common-project/hadoop-common/src/main/native/gtest)
  21. # determine if container-executor.conf.dir is an absolute
  22. # path in case the OS we're compiling on doesn't have
  23. # a hook in get_executable. We'll use this define
  24. # later in the code to potentially throw a compile error
  25. string(REGEX MATCH . HCD_ONE "${HADOOP_CONF_DIR}")
  26. string(COMPARE EQUAL ${HCD_ONE} / HADOOP_CONF_DIR_IS_ABS)
  27. set (CMAKE_C_STANDARD 99)
  28. include(CheckIncludeFiles)
  29. check_include_files("sys/types.h;sys/sysctl.h" HAVE_SYS_SYSCTL_H)
  30. include(CheckFunctionExists)
  31. check_function_exists(canonicalize_file_name HAVE_CANONICALIZE_FILE_NAME)
  32. check_function_exists(fcloseall HAVE_FCLOSEALL)
  33. check_function_exists(fchmodat HAVE_FCHMODAT)
  34. check_function_exists(fdopendir HAVE_FDOPENDIR)
  35. check_function_exists(fstatat HAVE_FSTATAT)
  36. check_function_exists(openat HAVE_OPENAT)
  37. check_function_exists(unlinkat HAVE_UNLINKAT)
  38. include(CheckSymbolExists)
  39. check_symbol_exists(sysctl "sys/types.h;sys/sysctl.h" HAVE_SYSCTL)
  40. if(APPLE)
  41. include_directories( /System/Library/Frameworks )
  42. find_library(COCOA_LIBRARY Cocoa)
  43. mark_as_advanced(COCOA_LIBRARY)
  44. set(EXTRA_LIBS ${COCOA_LIBRARY})
  45. endif(APPLE)
  46. include(CheckCCompilerFlag)
  47. # Building setuid = attempt to enable stack protection.
  48. # assumption here is that the C compiler and the C++
  49. # compiler match. need both so that gtest gets same
  50. # stack treatment that the real c-e does
  51. IF(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  52. CHECK_C_COMPILER_FLAG("-fstack-check" STACKRESULT)
  53. IF(STACKRESULT)
  54. SET (CMAKE_C_FLAGS "-fstack-check ${CMAKE_C_FLAGS}")
  55. SET (CMAKE_CXX_FLAGS "-fstack-check ${CMAKE_CXX_FLAGS}")
  56. ENDIF()
  57. ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR
  58. CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
  59. # clang is a bit difficult here:
  60. # - some versions don't support the flag
  61. # - some versions support the flag, despite not having
  62. # the library that is actually required (!)
  63. # Notably, Xcode is a problem here.
  64. # In the end, this is needlessly complex. :(
  65. SET(PRE_SANITIZE ${CMAKE_REQUIRED_FLAGS})
  66. SET(CMAKE_REQUIRED_FLAGS "-fsanitize=safe-stack ${CMAKE_REQUIRED_FLAGS}")
  67. CHECK_C_COMPILER_FLAG("" STACKRESULT)
  68. SET(CMAKE_REQUIRED_FLAGS ${PRE_SANITIZE})
  69. IF(STACKRESULT)
  70. SET(CMAKE_C_FLAGS "-fsanitize=safe-stack ${CMAKE_C_FLAGS}")
  71. SET(CMAKE_CXX_FLAGS "-fsanitize=safe-stack ${CMAKE_CXX_FLAGS}")
  72. ENDIF()
  73. ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
  74. # this appears to only be supported on SPARC, for some reason
  75. CHECK_C_COMPILER_FLAG("-xcheck=stkovf" STACKRESULT)
  76. IF(STACKRESULT)
  77. SET (CMAKE_C_FLAGS "-xcheck=stkovf ${CMAKE_C_FLAGS}")
  78. SET (CMAKE_CXX_FLAGS "-xcheck=stkovf ${CMAKE_CXX_FLAGS}")
  79. ENDIF()
  80. ENDIF()
  81. IF(NOT STACKRESULT)
  82. MESSAGE(WARNING "Stack Clash security protection is not suported.")
  83. ENDIF()
  84. function(output_directory TGT DIR)
  85. set_target_properties(${TGT} PROPERTIES
  86. RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  87. set_target_properties(${TGT} PROPERTIES
  88. ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  89. set_target_properties(${TGT} PROPERTIES
  90. LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  91. endfunction()
  92. include_directories(
  93. ${CMAKE_CURRENT_SOURCE_DIR}
  94. ${CMAKE_BINARY_DIR}
  95. ${GTEST_SRC_DIR}/include
  96. main/native/container-executor
  97. main/native/container-executor/impl
  98. )
  99. # add gtest as system library to suppress gcc warnings
  100. include_directories(SYSTEM ${GTEST_SRC_DIR}/include)
  101. configure_file(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
  102. add_library(gtest ${GTEST_SRC_DIR}/gtest-all.cc)
  103. set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-w")
  104. add_library(container
  105. main/native/container-executor/impl/util.c
  106. main/native/container-executor/impl/configuration.c
  107. main/native/container-executor/impl/container-executor.c
  108. main/native/container-executor/impl/get_executable.c
  109. main/native/container-executor/impl/utils/string-utils.c
  110. main/native/container-executor/impl/utils/path-utils.c
  111. main/native/container-executor/impl/modules/cgroups/cgroups-operations.c
  112. main/native/container-executor/impl/modules/common/module-configs.c
  113. main/native/container-executor/impl/modules/gpu/gpu-module.c
  114. main/native/container-executor/impl/modules/fpga/fpga-module.c
  115. main/native/container-executor/impl/utils/docker-util.c
  116. )
  117. add_executable(container-executor
  118. main/native/container-executor/impl/main.c
  119. )
  120. target_link_libraries(container-executor
  121. container
  122. )
  123. output_directory(container-executor target/usr/local/bin)
  124. # Test cases
  125. add_executable(test-container-executor
  126. main/native/container-executor/test/test-container-executor.c
  127. )
  128. target_link_libraries(test-container-executor
  129. container ${EXTRA_LIBS}
  130. )
  131. output_directory(test-container-executor target/usr/local/bin)
  132. # unit tests for container executor
  133. add_executable(cetest
  134. main/native/container-executor/impl/get_executable.c
  135. main/native/container-executor/impl/util.c
  136. main/native/container-executor/test/test_configuration.cc
  137. main/native/container-executor/test/test_main.cc
  138. main/native/container-executor/test/utils/test-string-utils.cc
  139. main/native/container-executor/test/utils/test-path-utils.cc
  140. main/native/container-executor/test/modules/cgroups/test-cgroups-module.cc
  141. main/native/container-executor/test/modules/gpu/test-gpu-module.cc
  142. main/native/container-executor/test/modules/fpga/test-fpga-module.cc
  143. main/native/container-executor/test/test_util.cc
  144. main/native/container-executor/test/utils/test_docker_util.cc)
  145. target_link_libraries(cetest gtest container)
  146. output_directory(cetest test)