DEPENDS ${export_file}
VERBATIM
COMMENT "Creating export file for ${target_name}")
- if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
+ if (${LLVM_LINKER_IS_SOLARISLD})
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-M,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
else()
endfunction(add_llvm_symbol_exports)
if(NOT WIN32 AND NOT APPLE)
+ # Detect what linker we have here
execute_process(
COMMAND ${CMAKE_C_COMPILER} -Wl,--version
OUTPUT_VARIABLE stdout
- ERROR_QUIET
+ ERROR_VARIABLE stderr
)
+ set(LLVM_LINKER_DETECTED ON)
if("${stdout}" MATCHES "GNU gold")
set(LLVM_LINKER_IS_GOLD ON)
+ message(STATUS "Linker detection: GNU Gold")
+ elseif("${stdout}" MATCHES "^LLD")
+ set(LLVM_LINKER_IS_LLD ON)
+ message(STATUS "Linker detection: LLD")
+ elseif("${stdout}" MATCHES "GNU ld")
+ set(LLVM_LINKER_IS_GNULD ON)
+ message(STATUS "Linker detection: GNU ld")
+ elseif("${stderr}" MATCHES "Solaris Link Editors")
+ set(LLVM_LINKER_IS_SOLARISLD ON)
+ message(STATUS "Linker detection: Solaris ld")
+ else()
+ set(LLVM_LINKER_DETECTED OFF)
+ message(STATUS "Linker detection: unknown")
endif()
endif()
endfunction(add_link_opts)
# Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}.
-# Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more,
-# or a certain builder, for eaxample, msbuild.exe, would be confused.
function(set_output_directory target)
cmake_parse_arguments(ARG "" "BINARY_DIR;LIBRARY_DIR" "" ${ARGN})
# it forces Xcode to properly link the static library.
list(APPEND ALL_FILES "${LLVM_MAIN_SRC_DIR}/cmake/dummy.cpp")
endif()
-
+
if( EXCLUDE_FROM_ALL )
add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
else()
set_target_properties(${name} PROPERTIES FOLDER "Utils")
if( LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS )
install (TARGETS ${name}
- RUNTIME DESTINATION bin
+ RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR}
COMPONENT ${name})
if (NOT CMAKE_CONFIGURATION_TYPES)
add_custom_target(install-${name}
endif()
endmacro(add_llvm_utility name)
+macro(add_llvm_fuzzer name)
+ cmake_parse_arguments(ARG "" "DUMMY_MAIN" "" ${ARGN})
+ if( LLVM_USE_SANITIZE_COVERAGE )
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer")
+ set(LLVM_OPTIONAL_SOURCES ${ARG_DUMMY_MAIN})
+ add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS})
+ set_target_properties(${name} PROPERTIES FOLDER "Fuzzers")
+ elseif( ARG_DUMMY_MAIN )
+ add_llvm_executable(${name} ${ARG_DUMMY_MAIN} ${ARG_UNPARSED_ARGUMENTS})
+ set_target_properties(${name} PROPERTIES FOLDER "Fuzzers")
+endif()
+endmacro()
macro(add_llvm_target target_name)
include_directories(BEFORE
# variables needed for the 'lit.site.cfg' files. This function bundles the
# common variables that any Lit instance is likely to need, and custom
# variables can be passed in.
-function(configure_lit_site_cfg input output)
+function(configure_lit_site_cfg site_in site_out)
+ cmake_parse_arguments(ARG "" "" "MAIN_CONFIG;OUTPUT_MAPPING" ${ARGN})
+
+ if ("${ARG_MAIN_CONFIG}" STREQUAL "")
+ get_filename_component(INPUT_DIR ${site_in} DIRECTORY)
+ set(ARG_MAIN_CONFIG "${INPUT_DIR}/lit.cfg")
+ endif()
+ if ("${ARG_OUTPUT_MAPPING}" STREQUAL "")
+ set(ARG_OUTPUT_MAPPING "${site_out}")
+ endif()
+
foreach(c ${LLVM_TARGETS_TO_BUILD})
set(TARGETS_BUILT "${TARGETS_BUILT} ${c}")
endforeach(c)
# They below might not be the build tree but provided binary tree.
set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR})
set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR})
- string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_TOOLS_DIR ${LLVM_TOOLS_BINARY_DIR})
- string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR ${LLVM_LIBRARY_DIR})
+ string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}")
+ string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR "${LLVM_LIBRARY_DIR}")
# SHLIBDIR points the build tree.
- string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}")
+ string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}")
set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
# FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for
set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}")
- set(LIT_SITE_CFG_IN_HEADER "## Autogenerated from ${input}\n## Do not edit!")
+ set(LIT_SITE_CFG_IN_HEADER "## Autogenerated from ${site_in}\n## Do not edit!")
# Override config_target_triple (and the env)
if(LLVM_TARGET_TRIPLE_ENV)
set(TARGET_TRIPLE "\"+config.target_triple+\"")
endif()
- configure_file(${input} ${output} @ONLY)
+ string(CONCAT LIT_SITE_CFG_IN_FOOTER
+ "import lit.llvm\n"
+ "lit.llvm.initialize(lit_config, config)\n")
+
+ configure_file(${site_in} ${site_out} @ONLY)
+ if (EXISTS "${ARG_MAIN_CONFIG}")
+ set(PYTHON_STATEMENT "map_config('${ARG_MAIN_CONFIG}', '${site_out}')")
+ get_property(LLVM_LIT_CONFIG_MAP GLOBAL PROPERTY LLVM_LIT_CONFIG_MAP)
+ set(LLVM_LIT_CONFIG_MAP "${LLVM_LIT_CONFIG_MAP}\n${PYTHON_STATEMENT}")
+ set_property(GLOBAL PROPERTY LLVM_LIT_CONFIG_MAP ${LLVM_LIT_CONFIG_MAP})
+ endif()
+endfunction()
+
+function(dump_all_cmake_variables)
+ get_cmake_property(_variableNames VARIABLES)
+ foreach (_variableName ${_variableNames})
+ message(STATUS "${_variableName}=${${_variableName}}")
+ endforeach()
+endfunction()
+
+function(get_llvm_lit_path base_dir file_name)
+ cmake_parse_arguments(ARG "ALLOW_EXTERNAL" "" "" ${ARGN})
+
+ if (ARG_ALLOW_EXTERNAL)
+ set(LLVM_DEFAULT_EXTERNAL_LIT "${LLVM_EXTERNAL_LIT}")
+ set (LLVM_EXTERNAL_LIT "" CACHE STRING "Command used to spawn lit")
+ if ("${LLVM_EXTERNAL_LIT}" STREQUAL "")
+ set(LLVM_EXTERNAL_LIT "${LLVM_DEFAULT_EXTERNAL_LIT}")
+ endif()
+
+ if (NOT "${LLVM_EXTERNAL_LIT}" STREQUAL "")
+ if (EXISTS ${LLVM_EXTERNAL_LIT})
+ get_filename_component(LIT_FILE_NAME ${LLVM_EXTERNAL_LIT} NAME)
+ get_filename_component(LIT_BASE_DIR ${LLVM_EXTERNAL_LIT} DIRECTORY)
+ set(${file_name} ${LIT_FILE_NAME} PARENT_SCOPE)
+ set(${base_dir} ${LIT_BASE_DIR} PARENT_SCOPE)
+ return()
+ else()
+ message(WARN "LLVM_EXTERNAL_LIT set to ${LLVM_EXTERNAL_LIT}, but the path does not exist.")
+ endif()
+ endif()
+ endif()
+
+ set(lit_file_name "llvm-lit")
+ if (WIN32 AND NOT CYGWIN)
+ # llvm-lit needs suffix.py for multiprocess to find a main module.
+ set(lit_file_name "${lit_file_name}.py")
+ endif ()
+ set(${file_name} ${lit_file_name} PARENT_SCOPE)
+
+ get_property(LLVM_LIT_BASE_DIR GLOBAL PROPERTY LLVM_LIT_BASE_DIR)
+ if (NOT "${LLVM_LIT_BASE_DIR}" STREQUAL "")
+ set(${base_dir} ${LLVM_LIT_BASE_DIR} PARENT_SCOPE)
+ endif()
+
+ # Allow individual projects to provide an override
+ if (NOT "${LLVM_LIT_OUTPUT_DIR}" STREQUAL "")
+ set(LLVM_LIT_BASE_DIR ${LLVM_LIT_OUTPUT_DIR})
+ elseif(NOT "${LLVM_RUNTIME_OUTPUT_INTDIR}" STREQUAL "")
+ set(LLVM_LIT_BASE_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
+ else()
+ set(LLVM_LIT_BASE_DIR "")
+ endif()
+
+ # Cache this so we don't have to do it again and have subsequent calls
+ # potentially disagree on the value.
+ set_property(GLOBAL PROPERTY LLVM_LIT_BASE_DIR ${LLVM_LIT_BASE_DIR})
+ set(${base_dir} ${LLVM_LIT_BASE_DIR} PARENT_SCOPE)
endfunction()
# A raw function to create a lit target. This is used to implement the testuite
if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR})
endif ()
- if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
- # reset cache after erraneous r283029
- # TODO: remove this once all buildbots run
- if (LIT_COMMAND STREQUAL "${PYTHON_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py")
- unset(LIT_COMMAND CACHE)
- endif()
- set (LIT_COMMAND "${PYTHON_EXECUTABLE};${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py"
- CACHE STRING "Command used to spawn llvm-lit")
- else()
- find_program(LIT_COMMAND NAMES llvm-lit lit.py lit)
- endif ()
+
+ # Get the path to the lit to *run* tests with. This can be overriden by
+ # the user by specifying -DLLVM_EXTERNAL_LIT=<path-to-lit.py>
+ get_llvm_lit_path(
+ lit_base_dir
+ lit_file_name
+ ALLOW_EXTERNAL
+ )
+
+ set(LIT_COMMAND "${PYTHON_EXECUTABLE};${lit_base_dir}/${lit_file_name}")
list(APPEND LIT_COMMAND ${LIT_ARGS})
foreach(param ${ARG_PARAMS})
list(APPEND LIT_COMMAND --param ${param})
# magic. First we grab one of the types, and a type-specific path. Then from
# the type-specific path we find the last occurrence of the type in the path,
# and replace it with CMAKE_CFG_INTDIR. This allows the build step to be type
- # agnostic again.
+ # agnostic again.
if(NOT ARG_OUTPUT_DIR)
# If you're not overriding the OUTPUT_DIR, we can make the link relative in
# the same directory.
set(sandbox_command "sandbox-exec -p '(version 1) (allow default) ${deny_attributes_gen} ${deny_intrinsics_gen}'")
set_target_properties(${name} PROPERTIES RULE_LAUNCH_COMPILE ${sandbox_command})
endfunction()
+
+# Figure out if we can track VC revisions.
+function(find_first_existing_file out_var)
+ foreach(file ${ARGN})
+ if(EXISTS "${file}")
+ set(${out_var} "${file}" PARENT_SCOPE)
+ return()
+ endif()
+ endforeach()
+endfunction()
+
+macro(find_first_existing_vc_file out_var path)
+ find_program(git_executable NAMES git git.exe git.cmd)
+ # Run from a subdirectory to force git to print an absolute path.
+ execute_process(COMMAND ${git_executable} rev-parse --git-dir
+ WORKING_DIRECTORY ${path}/cmake
+ RESULT_VARIABLE git_result
+ OUTPUT_VARIABLE git_dir
+ ERROR_QUIET)
+ if(git_result EQUAL 0)
+ string(STRIP "${git_dir}" git_dir)
+ set(${out_var} "${git_dir}/logs/HEAD")
+ # some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD
+ if (NOT EXISTS "${git_dir}/logs/HEAD")
+ file(WRITE "${git_dir}/logs/HEAD" "")
+ endif()
+ else()
+ find_first_existing_file(${out_var}
+ "${path}/.svn/wc.db" # SVN 1.7
+ "${path}/.svn/entries" # SVN 1.6
+ )
+ endif()
+endmacro()