[PATCH] D20221: [test-suite] parameterization of llvm_{multi, single}source()

James Molloy via llvm-commits llvm-commits at lists.llvm.org
Fri May 13 01:26:41 PDT 2016


Hi,

I'm not opposed to this, but I'll let Matthias do the real review as he's
been working most in this area recently.

James

On Thu, 12 May 2016 at 23:29 Artem Belevich via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> tra created this revision.
> tra added a reviewer: MatzeB.
> tra added a subscriber: llvm-commits.
>
> This patch allows various compiler options as arguments to
> llvm_{multi,single}source().
>
> Both now accept following optional arguments that are used in addition to
> those specified via CFLAGS/CXXFLAGS/CPPFLAGS/LDFLAGS variables. This
> allows adjusting build parameters for specific target without having to
> modify global variables which makes build files somewhat less verbose.
>
> In addition to global option, I've added two flags to further customize
> llvm
> test target: LIBS and DEPS. This allows more control over targets that need
> extra dependencies or need to link with shared libraries in non-standard
> directories.
>
>  * CFLAGS/CXXFLAGS/CPPFLAGS -- added to COMPILE_FLAGS property
>  * LDFLAGS -- added to LINK_LIBRARIES property
>  * LIBS -- applies target_link_libraries() which allows cmake to
>           pass proper flags like rpath for shared libraries.
>  * DEPS -- applies add_dependencies()
>
> This change allows reducing amount of boilerplate for most of the simple
> test cases.
> Upcoming patch converts MultiSource/* build files to use this
> functionality.
>
> http://reviews.llvm.org/D20221
>
> Files:
>   cmake/modules/SingleMultiSource.cmake
>
> Index: cmake/modules/SingleMultiSource.cmake
> ===================================================================
> --- cmake/modules/SingleMultiSource.cmake
> +++ cmake/modules/SingleMultiSource.cmake
> @@ -116,30 +116,37 @@
>    llvm_add_test(${testfile} ${executable})
>  endfunction()
>
> -macro(test_suite_add_executable name mainsource)
> -  list(FIND PROGRAMS_TO_SKIP ${name} name_idx)
> +macro(test_suite_add_executable)
> +  cmake_parse_arguments(_ARG "" "PROG;MAIN"
> "SOURCES;CFLAGS;CPPFLAGS;CXXFLAGS;LDFLAGS;LIBS;DEPS" ${ARGN})
> +  list(FIND PROGRAMS_TO_SKIP ${_ARG_PROG} name_idx)
>    # Should we skip this?
>    if(${name_idx} EQUAL -1)
> -    get_unique_exe_name(executable ${mainsource})
> -    add_executable(${executable} ${ARGN})
> -    append_compile_flags(${executable} ${CFLAGS})
> -    append_compile_flags(${executable} ${CPPFLAGS})
> -    append_compile_flags(${executable} ${CXXFLAGS})
> +    get_unique_exe_name(executable ${_ARG_MAIN})
> +    add_executable(${executable} ${_ARG_SOURCES})
> +    append_compile_flags(${executable} ${CFLAGS} ${_ARG_CFLAGS})
> +    append_compile_flags(${executable} ${CPPFLAGS} ${_ARG_CPPFLAGS})
> +    append_compile_flags(${executable} ${CXXFLAGS} ${_ARG_CXXFLAGS})
>      # Note that we cannot use target_link_libraries() here because that
> one
>      # only interprets inputs starting with '-' as flags.
> -    append_link_flags(${executable} ${LDFLAGS})
> +    append_link_flags(${executable} ${LDFLAGS} ${_ARG_LDFLAGS})
> +    if (_ARG_LIBS)
> +      target_link_libraries(${executable} ${_ARG_LIBS})
> +    endif()
>      set(executable_path ${CMAKE_CURRENT_BINARY_DIR}/${executable})
>      if (TEST_SUITE_PROFILE_USE)
>        append_compile_flags(${executable}
> -fprofile-instr-use=${executable_path}.profdata)
>        append_link_flags(${executable}
> -fprofile-instr-use=${executable_path}.profdata)
>      endif()
> +    if (${_ARG_DEPS})
> +      add_dependencies(${executable} ${_ARG_DEPS})
> +    endif()
>
>      set_property(GLOBAL APPEND PROPERTY TEST_SUITE_TARGETS ${executable})
>
>      # Fall back to old style involving RUN_OPTIONS and STDIN_FILENAME if
>      # llvm_test_run() was not called yet.
>      if(NOT TESTSCRIPT)
> -      llvm_test_traditional(${executable_path}.test ${executable_path}
> ${name})
> +      llvm_test_traditional(${executable_path}.test ${executable_path}
> ${_ARG_PROG})
>      else()
>        llvm_add_test(${executable_path}.test ${executable_path})
>      endif()
> @@ -159,24 +166,30 @@
>      string(REGEX REPLACE ".[cp]+$" "" path ${source})
>      string(REGEX REPLACE ".*/" "" name ${path})
>
> -    test_suite_add_executable(${name} ${source} ${source})
> +    test_suite_add_executable(PROG "${name}" MAIN "${source}" SOURCES
> ${source} ${ARGN})
>    endforeach()
>  endmacro()
>
>  # Configure the current directory as a MultiSource subdirectory - i.e.
> there is
>  # one test and it consists of all sources in the directory (or a curated
> list,
>  # if Source is defined).
>  macro(llvm_multisource)
> -  if(DEFINED Source)
> -    set(sources ${Source})
> +  cmake_parse_arguments(_ARG "" "PROG" "SOURCES" ${ARGN})
> +  if(DEFINED Source OR _ARG_SOURCES)
> +    set(sources ${Source} ${_ARG_SOURCES})
>    else()
>      file(GLOB sources *.c *.cpp *.cc)
>    endif()
>    list(LENGTH sources sources_len)
> -
> -  if(sources_len GREATER 0 AND DEFINED PROG)
> +  # PROG passed as an argument has higher precedence.
> +  if (_ARG_PROG)
> +    set(_PROG ${_ARG_PROG})
> +  elseif(DEFINED PROG)
> +    set(_PROG ${PROG})
> +  endif()
> +  if(sources_len GREATER 0 AND _PROG)
>      include_directories(${CMAKE_CURRENT_SOURCE_DIR})
>      include_directories(${CMAKE_CURRENT_BINARY_DIR})
> -    test_suite_add_executable(${PROG} "${PROG}.c" ${sources})
> +    test_suite_add_executable(PROG ${_PROG} MAIN "${_PROG}.c" SOURCES
> ${sources} ${ARGN})
>    endif()
>  endmacro()
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160513/e2c34b7a/attachment.html>


More information about the llvm-commits mailing list