Index: cmake/modules/SingleMultiSource.cmake =================================================================== --- cmake/modules/SingleMultiSource.cmake +++ cmake/modules/SingleMultiSource.cmake @@ -125,30 +125,37 @@ add_dependencies(${executable} timeit-host fpcmp-host) endmacro() -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() @@ -165,7 +172,7 @@ 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() @@ -173,16 +180,22 @@ # 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()