Home | History | Annotate | Download | only in runtime
      1 # TODO: Set the install directory.
      2 
      3 include(ExternalProject)
      4 
      5 set(known_subdirs
      6   "libcxx"
      7   )
      8 
      9 foreach (dir ${known_subdirs})
     10   if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt)
     11     add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${dir})
     12   endif()
     13 endforeach()
     14 
     15 function(get_ext_project_build_command out_var target)
     16   if (CMAKE_GENERATOR MATCHES "Make")
     17     # Use special command for Makefiles to support parallelism.
     18     set(${out_var} "$(MAKE)" "${target}" PARENT_SCOPE)
     19   else()
     20     set(${out_var} ${CMAKE_COMMAND} --build . --target ${target}
     21                                     --config $<CONFIGURATION> PARENT_SCOPE)
     22   endif()
     23 endfunction()
     24 
     25 set(COMPILER_RT_SRC_ROOT ${LLVM_MAIN_SRC_DIR}/projects/compiler-rt)
     26 # Fallback to the external path, if the other one isn't available.
     27 # This is the same behavior (try "internal", then check the LLVM_EXTERNAL_...
     28 # variable) as in add_llvm_external_project
     29 if(NOT EXISTS ${COMPILER_RT_SRC_ROOT})
     30   # We don't want to set it if LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR is ""
     31   if(${LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR})
     32     set(COMPILER_RT_SRC_ROOT ${LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR})
     33   endif()
     34 endif()
     35 
     36 if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
     37 
     38   # Add compiler-rt as an external project.
     39   set(COMPILER_RT_PREFIX ${CMAKE_BINARY_DIR}/projects/compiler-rt)
     40 
     41   set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/compiler-rt-stamps/)
     42   set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/compiler-rt-bins/)
     43 
     44   add_custom_target(compiler-rt-clear
     45     COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR}
     46     COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR}
     47     COMMENT "Clobberring compiler-rt build and stamp directories"
     48     )
     49 
     50   # Find all variables that start with COMPILER_RT and populate a variable with
     51   # them.
     52   get_cmake_property(variableNames VARIABLES)
     53   foreach(variableName ${variableNames})
     54     if(variableName MATCHES "^COMPILER_RT")
     55       string(REPLACE ";" "\;" value "${${variableName}}")
     56       list(APPEND COMPILER_RT_PASSTHROUGH_VARIABLES
     57         -D${variableName}=${value})
     58     endif()
     59   endforeach()
     60 
     61   ExternalProject_Add(compiler-rt
     62     DEPENDS llvm-config clang
     63     PREFIX ${COMPILER_RT_PREFIX}
     64     SOURCE_DIR ${COMPILER_RT_SRC_ROOT}
     65     STAMP_DIR ${STAMP_DIR}
     66     BINARY_DIR ${BINARY_DIR}
     67     CMAKE_ARGS ${CLANG_COMPILER_RT_CMAKE_ARGS}
     68                -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
     69                -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
     70                -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
     71                -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
     72                -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config
     73                -DLLVM_LIT_ARGS=${LLVM_LIT_ARGS}
     74                -DCOMPILER_RT_OUTPUT_DIR=${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}
     75                -DCOMPILER_RT_EXEC_OUTPUT_DIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
     76                -DCOMPILER_RT_INSTALL_PATH:STRING=lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}
     77                -DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
     78                -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
     79                -DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
     80                ${COMPILER_RT_PASSTHROUGH_VARIABLES}
     81     INSTALL_COMMAND ""
     82     STEP_TARGETS configure build
     83     USES_TERMINAL_CONFIGURE 1
     84     USES_TERMINAL_BUILD 1
     85     USES_TERMINAL_INSTALL 1
     86     )
     87 
     88   get_ext_project_build_command(run_clean_compiler_rt clean)
     89   ExternalProject_Add_Step(compiler-rt clean
     90     COMMAND ${run_clean_compiler_rt}
     91     COMMENT "Cleaning compiler-rt..."
     92     DEPENDEES configure
     93     DEPENDERS build
     94     DEPENDS clang
     95     WORKING_DIRECTORY ${BINARY_DIR}
     96     )
     97 
     98   install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${BINARY_DIR}/cmake_install.cmake \)"
     99     COMPONENT compiler-rt)
    100 
    101   add_custom_target(install-compiler-rt
    102                     DEPENDS compiler-rt
    103                     COMMAND "${CMAKE_COMMAND}"
    104                              -DCMAKE_INSTALL_COMPONENT=compiler-rt
    105                              -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
    106                     USES_TERMINAL)
    107 
    108   # Add top-level targets that build specific compiler-rt runtimes.
    109   set(COMPILER_RT_RUNTIMES asan builtins dfsan lsan msan profile tsan ubsan)
    110   foreach(runtime ${COMPILER_RT_RUNTIMES})
    111     get_ext_project_build_command(build_runtime_cmd ${runtime})
    112     add_custom_target(${runtime}
    113       COMMAND ${build_runtime_cmd}
    114       DEPENDS compiler-rt-configure
    115       WORKING_DIRECTORY ${BINARY_DIR}
    116       VERBATIM USES_TERMINAL)
    117   endforeach()
    118 
    119   if(LLVM_INCLUDE_TESTS)
    120     # Add binaries that compiler-rt tests depend on.
    121     set(COMPILER_RT_TEST_DEPENDENCIES
    122       FileCheck count not llvm-nm llvm-objdump llvm-symbolizer)
    123 
    124     # Add top-level targets for various compiler-rt test suites.
    125     set(COMPILER_RT_TEST_SUITES check-asan check-asan-dynamic check-dfsan
    126       check-lsan check-msan check-sanitizer check-tsan check-ubsan
    127       check-profile check-cfi check-cfi-and-supported check-safestack)
    128     foreach(test_suite ${COMPILER_RT_TEST_SUITES})
    129       get_ext_project_build_command(run_test_suite ${test_suite})
    130       add_custom_target(${test_suite}
    131         COMMAND ${run_test_suite}
    132         DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
    133         WORKING_DIRECTORY ${BINARY_DIR}
    134         VERBATIM
    135         USES_TERMINAL
    136         )
    137     endforeach()
    138 
    139     # Add special target to run all compiler-rt test suites.
    140     get_ext_project_build_command(run_check_compiler_rt check-all)
    141     add_custom_target(check-compiler-rt
    142       COMMAND ${run_check_compiler_rt}
    143       DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
    144       WORKING_DIRECTORY ${BINARY_DIR}
    145       VERBATIM USES_TERMINAL)
    146     set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS check-compiler-rt)
    147   endif()
    148 endif()
    149