diff options
Diffstat (limited to 'cmake/Modules')
-rw-r--r-- | cmake/Modules/CodeCoverage.cmake | 36 | ||||
-rw-r--r-- | cmake/Modules/HandleLibCXXABI.cmake | 103 | ||||
-rw-r--r-- | cmake/Modules/MacroEnsureOutOfSourceBuild.cmake | 18 |
3 files changed, 157 insertions, 0 deletions
diff --git a/cmake/Modules/CodeCoverage.cmake b/cmake/Modules/CodeCoverage.cmake new file mode 100644 index 000000000000..addd10abdfe1 --- /dev/null +++ b/cmake/Modules/CodeCoverage.cmake @@ -0,0 +1,36 @@ +find_program(CODE_COVERAGE_LCOV lcov) +if (NOT CODE_COVERAGE_LCOV) + message(FATAL_ERROR "Cannot find lcov...") +endif() + +find_program(CODE_COVERAGE_GENHTML genhtml) +if (NOT CODE_COVERAGE_GENHTML) + message(FATAL_ERROR "Cannot find genhtml...") +endif() + +set(CMAKE_CXX_FLAGS_COVERAGE "-g -O0 --coverage") + +function(setup_lcov_test_target_coverage target_name output_dir capture_dirs source_dirs) + file(MAKE_DIRECTORY ${output_dir}) + + set(CAPTURE_DIRS "") + foreach(cdir ${capture_dirs}) + list(APPEND CAPTURE_DIRS "-d;${cdir}") + endforeach() + + set(EXTRACT_DIRS "") + foreach(sdir ${source_dirs}) + list(APPEND EXTRACT_DIRS "'${sdir}/*'") + endforeach() + + message(STATUS "Capture Directories: ${CAPTURE_DIRS}") + message(STATUS "Extract Directories: ${EXTRACT_DIRS}") + + add_custom_target(generate-lib${target_name}-coverage + COMMAND ${CODE_COVERAGE_LCOV} --capture ${CAPTURE_DIRS} -o test_coverage.info + COMMAND ${CODE_COVERAGE_LCOV} --extract test_coverage.info ${EXTRACT_DIRS} -o test_coverage.info + COMMAND ${CODE_COVERAGE_GENHTML} --demangle-cpp test_coverage.info -o test_coverage + COMMAND ${CMAKE_COMMAND} -E remove test_coverage.info + WORKING_DIRECTORY ${output_dir} + COMMENT "Generating coverage results") +endfunction() diff --git a/cmake/Modules/HandleLibCXXABI.cmake b/cmake/Modules/HandleLibCXXABI.cmake new file mode 100644 index 000000000000..73723e3559b1 --- /dev/null +++ b/cmake/Modules/HandleLibCXXABI.cmake @@ -0,0 +1,103 @@ + +#=============================================================================== +# Add an ABI library if appropriate +#=============================================================================== + +# +# _setup_abi: Set up the build to use an ABI library +# +# Parameters: +# abidefines: A list of defines needed to compile libc++ with the ABI library +# abilib : The ABI library to link against. +# abifiles : A list of files (which may be relative paths) to copy into the +# libc++ build tree for the build. These files will also be +# installed alongside the libc++ headers. +# abidirs : A list of relative paths to create under an include directory +# in the libc++ build directory. +# +macro(setup_abi_lib abidefines abilib abifiles abidirs) + list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines}) + set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_CXX_ABI_INCLUDE_PATHS}" + CACHE PATH + "Paths to C++ ABI header directories separated by ';'." FORCE + ) + + set(LIBCXX_CXX_ABI_LIBRARY ${abilib}) + + set(LIBCXX_ABILIB_FILES ${abifiles}) + + file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include") + foreach(_d ${abidirs}) + file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/${_d}") + endforeach() + + foreach(fpath ${LIBCXX_ABILIB_FILES}) + set(found FALSE) + foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS}) + if (EXISTS "${incpath}/${fpath}") + set(found TRUE) + get_filename_component(dstdir ${fpath} PATH) + get_filename_component(ifile ${fpath} NAME) + file(COPY "${incpath}/${fpath}" + DESTINATION "${CMAKE_BINARY_DIR}/include/${dstdir}" + ) + install(FILES "${CMAKE_BINARY_DIR}/include/${fpath}" + DESTINATION include/c++/v1/${dstdir} + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) + list(APPEND abilib_headers "${CMAKE_BINARY_DIR}/include/${fpath}") + endif() + endforeach() + if (NOT found) + message(WARNING "Failed to find ${fpath}") + endif() + endforeach() + + add_custom_target(LIBCXX_CXX_ABI_DEPS DEPENDS ${abilib_headers}) + include_directories("${CMAKE_BINARY_DIR}/include") + +endmacro() + +if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR + "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++") + set(_LIBSUPCXX_INCLUDE_FILES + cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h + bits/cxxabi_tweaks.h bits/cxxabi_forced.h + ) + if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++") + set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX") + set(_LIBSUPCXX_LIBNAME stdc++) + else() + set(_LIBSUPCXX_DEFINES "") + set(_LIBSUPCXX_LIBNAME supc++) + endif() + setup_abi_lib( + "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}" + "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits" + ) +elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi") + if (LIBCXX_CXX_ABI_INTREE) + # Link against just-built "cxxabi" target. + if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) + set(CXXABI_LIBNAME cxxabi_static) + else() + set(CXXABI_LIBNAME cxxabi_shared) + endif() + set(LIBCXX_LIBCPPABI_VERSION "2" PARENT_SCOPE) + else() + # Assume c++abi is installed in the system, rely on -lc++abi link flag. + set(CXXABI_LIBNAME "c++abi") + endif() + setup_abi_lib("-DLIBCXX_BUILDING_LIBCXXABI" + ${CXXABI_LIBNAME} "cxxabi.h;__cxxabi_config.h" "" + ) +elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt") + setup_abi_lib("-DLIBCXXRT" + "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" "" + ) +elseif (NOT "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none") + message(FATAL_ERROR + "Currently libstdc++, libsupc++, libcxxabi, libcxxrt and none are " + "supported for c++ abi." + ) +endif () diff --git a/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake b/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake new file mode 100644 index 000000000000..a0669365bf99 --- /dev/null +++ b/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake @@ -0,0 +1,18 @@ +# MACRO_ENSURE_OUT_OF_SOURCE_BUILD(<errorMessage>) + +macro( MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage ) + +string( COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" _insource ) +if( _insource ) + message( SEND_ERROR "${_errorMessage}" ) + message( FATAL_ERROR + "In-source builds are not allowed. + CMake would overwrite the makefiles distributed with Compiler-RT. + Please create a directory and run cmake from there, passing the path + to this source directory as the last argument. + This process created the file `CMakeCache.txt' and the directory `CMakeFiles'. + Please delete them." + ) +endif( _insource ) + +endmacro( MACRO_ENSURE_OUT_OF_SOURCE_BUILD ) |