CMakeLists.txt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. set (CMAKE_CXX_STANDARD 11)
  29. include(CheckIncludeFiles)
  30. check_include_files("sys/types.h;sys/sysctl.h" HAVE_SYS_SYSCTL_H)
  31. include(CheckFunctionExists)
  32. check_function_exists(canonicalize_file_name HAVE_CANONICALIZE_FILE_NAME)
  33. check_function_exists(fcloseall HAVE_FCLOSEALL)
  34. check_function_exists(fchmodat HAVE_FCHMODAT)
  35. check_function_exists(fdopendir HAVE_FDOPENDIR)
  36. check_function_exists(fstatat HAVE_FSTATAT)
  37. check_function_exists(openat HAVE_OPENAT)
  38. check_function_exists(unlinkat HAVE_UNLINKAT)
  39. include(CheckSymbolExists)
  40. check_symbol_exists(sysctl "sys/types.h;sys/sysctl.h" HAVE_SYSCTL)
  41. if(APPLE)
  42. include_directories( /System/Library/Frameworks )
  43. find_library(COCOA_LIBRARY Cocoa)
  44. mark_as_advanced(COCOA_LIBRARY)
  45. set(EXTRA_LIBS ${COCOA_LIBRARY})
  46. endif(APPLE)
  47. include(CheckCCompilerFlag)
  48. # Building setuid = attempt to enable stack protection.
  49. # assumption here is that the C compiler and the C++
  50. # compiler match. need both so that gtest gets same
  51. # stack treatment that the real c-e does
  52. IF(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  53. CHECK_C_COMPILER_FLAG("-fstack-check" STACKRESULT)
  54. IF(STACKRESULT)
  55. SET (CMAKE_C_FLAGS "-fstack-check ${CMAKE_C_FLAGS}")
  56. SET (CMAKE_CXX_FLAGS "-fstack-check ${CMAKE_CXX_FLAGS}")
  57. ENDIF()
  58. ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR
  59. CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
  60. # clang is a bit difficult here:
  61. # - some versions don't support the flag
  62. # - some versions support the flag, despite not having
  63. # the library that is actually required (!)
  64. # Notably, Xcode is a problem here.
  65. # In the end, this is needlessly complex. :(
  66. SET(PRE_SANITIZE ${CMAKE_REQUIRED_FLAGS})
  67. SET(CMAKE_REQUIRED_FLAGS "-fsanitize=safe-stack ${CMAKE_REQUIRED_FLAGS}")
  68. CHECK_C_COMPILER_FLAG("" STACKRESULT)
  69. SET(CMAKE_REQUIRED_FLAGS ${PRE_SANITIZE})
  70. IF(STACKRESULT)
  71. SET(CMAKE_C_FLAGS "-fsanitize=safe-stack ${CMAKE_C_FLAGS}")
  72. SET(CMAKE_CXX_FLAGS "-fsanitize=safe-stack ${CMAKE_CXX_FLAGS}")
  73. ENDIF()
  74. ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
  75. # this appears to only be supported on SPARC, for some reason
  76. CHECK_C_COMPILER_FLAG("-xcheck=stkovf" STACKRESULT)
  77. IF(STACKRESULT)
  78. SET (CMAKE_C_FLAGS "-xcheck=stkovf ${CMAKE_C_FLAGS}")
  79. SET (CMAKE_CXX_FLAGS "-xcheck=stkovf ${CMAKE_CXX_FLAGS}")
  80. ENDIF()
  81. ENDIF()
  82. IF(NOT STACKRESULT)
  83. MESSAGE(WARNING "Stack Clash security protection is not suported.")
  84. ENDIF()
  85. function(output_directory TGT DIR)
  86. set_target_properties(${TGT} PROPERTIES
  87. RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  88. set_target_properties(${TGT} PROPERTIES
  89. ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  90. set_target_properties(${TGT} PROPERTIES
  91. LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  92. endfunction()
  93. include_directories(
  94. ${CMAKE_CURRENT_SOURCE_DIR}
  95. ${CMAKE_BINARY_DIR}
  96. ${GTEST_SRC_DIR}/include
  97. main/native/container-executor
  98. main/native/container-executor/impl
  99. main/native/oom-listener/impl
  100. )
  101. # add gtest as system library to suppress gcc warnings
  102. include_directories(SYSTEM ${GTEST_SRC_DIR}/include)
  103. configure_file(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
  104. add_library(gtest ${GTEST_SRC_DIR}/gtest-all.cc)
  105. set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-w")
  106. add_library(container
  107. main/native/container-executor/impl/util.c
  108. main/native/container-executor/impl/configuration.c
  109. main/native/container-executor/impl/container-executor.c
  110. main/native/container-executor/impl/get_executable.c
  111. main/native/container-executor/impl/utils/string-utils.c
  112. main/native/container-executor/impl/utils/path-utils.c
  113. main/native/container-executor/impl/modules/cgroups/cgroups-operations.c
  114. main/native/container-executor/impl/modules/common/module-configs.c
  115. main/native/container-executor/impl/modules/gpu/gpu-module.c
  116. main/native/container-executor/impl/modules/fpga/fpga-module.c
  117. main/native/container-executor/impl/modules/devices/devices-module.c
  118. main/native/container-executor/impl/utils/docker-util.c
  119. )
  120. add_executable(container-executor
  121. main/native/container-executor/impl/main.c
  122. )
  123. target_link_libraries(container-executor
  124. container
  125. )
  126. output_directory(container-executor target/usr/local/bin)
  127. # Test cases
  128. add_executable(test-container-executor
  129. main/native/container-executor/test/test-container-executor.c
  130. )
  131. target_link_libraries(test-container-executor
  132. container ${EXTRA_LIBS}
  133. )
  134. output_directory(test-container-executor target/usr/local/bin)
  135. # unit tests for container executor
  136. add_executable(cetest
  137. main/native/container-executor/impl/get_executable.c
  138. main/native/container-executor/impl/util.c
  139. main/native/container-executor/test/test_configuration.cc
  140. main/native/container-executor/test/test_main.cc
  141. main/native/container-executor/test/utils/test-string-utils.cc
  142. main/native/container-executor/test/utils/test-path-utils.cc
  143. main/native/container-executor/test/modules/cgroups/test-cgroups-module.cc
  144. main/native/container-executor/test/modules/gpu/test-gpu-module.cc
  145. main/native/container-executor/test/modules/fpga/test-fpga-module.cc
  146. main/native/container-executor/test/modules/devices/test-devices-module.cc
  147. main/native/container-executor/test/test_util.cc
  148. main/native/container-executor/test/utils/test_docker_util.cc)
  149. target_link_libraries(cetest gtest container)
  150. output_directory(cetest test)
  151. # CGroup OOM listener
  152. add_executable(oom-listener
  153. main/native/oom-listener/impl/oom_listener.c
  154. main/native/oom-listener/impl/oom_listener.h
  155. main/native/oom-listener/impl/oom_listener_main.c
  156. )
  157. output_directory(oom-listener target/usr/local/bin)
  158. # CGroup OOM listener test with GTest
  159. add_executable(test-oom-listener
  160. main/native/oom-listener/impl/oom_listener.c
  161. main/native/oom-listener/impl/oom_listener.h
  162. main/native/oom-listener/test/oom_listener_test_main.cc
  163. )
  164. target_link_libraries(test-oom-listener gtest rt)
  165. output_directory(test-oom-listener test)