[pkg-d-commits] [ldc] 187/211: CMake: Simplify unittest targets
Matthias Klumpp
mak at moszumanska.debian.org
Sun Apr 23 22:36:22 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.1.0
in repository ldc.
commit 3063c27d3a0ade16f83f8bdfb62183eef2972970
Author: Martin <noone at nowhere.com>
Date: Sat Dec 3 23:57:58 2016 +0100
CMake: Simplify unittest targets
Simply compile the D unittest modules and C/ASM parts into libraries
druntime-ldc-unittest[-debug] / phobos2-ldc-unittest[-debug], not just
when building shared libs.
Previously, when building static libs, only the C/ASM parts were compiled
to static libraries, and the D unittest objects were linked in manually
when building the test runners, to make sure all objects are pulled in.
Some linker command-line magic allows pulling in all objects from the
static unittest libraries too.
Also make sure to have consistent multilib suffices for CMake build and
test targets and add a missing dependency for the Phobos test runner (it
requires druntime-ldc-unittest[-debug] for linking).
---
.travis.yml | 4 +-
runtime/CMakeLists.txt | 199 ++++++++++++++++++------------------------------
tests/d2/CMakeLists.txt | 4 +-
3 files changed, 80 insertions(+), 127 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index eac6cb9..266ecac 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -82,8 +82,8 @@ script:
# Build Phobos & druntime unittest modules.
-
if [ "${OPTS}" = "-DMULTILIB=ON" ]; then
- make -j2 phobos2-ldc-unittest-debug phobos2-ldc-unittest phobos2-ldc-unittest-debug-32 phobos2-ldc-unittest-32;
- make -j3 druntime-ldc-unittest-debug druntime-ldc-unittest druntime-ldc-unittest-debug-32 druntime-ldc-unittest-32;
+ make -j2 phobos2-ldc-unittest-debug phobos2-ldc-unittest phobos2-ldc-unittest-debug_32 phobos2-ldc-unittest_32;
+ make -j3 druntime-ldc-unittest-debug druntime-ldc-unittest druntime-ldc-unittest-debug_32 druntime-ldc-unittest_32;
else
make -j2 phobos2-ldc-unittest-debug phobos2-ldc-unittest;
make -j3 druntime-ldc-unittest-debug druntime-ldc-unittest;
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt
index 9ef6ac7..d4c6838 100644
--- a/runtime/CMakeLists.txt
+++ b/runtime/CMakeLists.txt
@@ -609,133 +609,85 @@ endforeach()
#
# Build the "test runner" executables containing the druntime and Phobos unit
-# tests. They are invoked with the modules to test later. When using a shared
-# runtime, we just build another copy of the two libraries with -unittest
-# enabled. When linking statically, we have to directly pass the object files
-# to the linking command instead so that all tests are pulled in.
+# tests. They are invoked with the modules to test later.
+# We just build another copy of the two libraries with -unittest enabled and
+# link the test runners against those. Some linker command-line magic is
+# required to make sure all objects are pulled in.
+
+macro(append_flags_to_pull_in_all_objects lib name_suffix target_suffix output_flags)
+ if(BUILD_SHARED_LIBS)
+ if(MSVC OR APPLE)
+ list(APPEND ${output_flags} "-L$<TARGET_LINKER_FILE:${lib}${target_suffix}>")
+ else()
+ list(APPEND ${output_flags} -L--no-as-needed -L-l${lib}${name_suffix} -L--as-needed)
+ endif()
+ else()
+ if(MSVC)
+ # the MS linker supports /WHOLEARCHIVE since VS 2015 Update 2
+ list(APPEND ${output_flags} -L/WHOLEARCHIVE:${lib}${name_suffix})
+ elseif(APPLE)
+ list(APPEND ${output_flags} "-L-Wl,-force_load,$<TARGET_LINKER_FILE:${lib}${target_suffix}>")
+ else()
+ list(APPEND ${output_flags} -L--whole-archive -L-l${lib}${name_suffix} -L--no-whole-archive)
+ endif()
+ endif()
+endmacro()
macro(build_test_runner name_suffix path_suffix d_flags c_flags)
set(flags "${D_FLAGS};${d_flags};-unittest")
- if(BUILD_SHARED_LIBS)
- set(unittest_libs "")
- build_runtime(
- "${flags}"
- "${RT_CFLAGS} ${c_flags}"
- "${LD_FLAGS} ${c_flags}"
- "-unittest${name_suffix}"
- "${path_suffix}"
- unittest_libs
- )
- # Only build the unittest libraries when running the tests. Unfortunately,
- # I couldn't find an easier way to make a test depend on a CMake target than
- # just invoking the build command through the CMake executable.
- set_target_properties(${unittest_libs} PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT_BUILD ON)
- foreach(l ${unittest_libs})
- add_test(build-${l} "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${l})
- endforeach()
+ set(unittest_libs "")
+ build_runtime(
+ "${flags}"
+ "${RT_CFLAGS} ${c_flags}"
+ "${LD_FLAGS} ${c_flags}"
+ "-unittest${name_suffix}"
+ "${path_suffix}"
+ unittest_libs
+ )
- if(NOT APPLE)
- list(APPEND flags -L--no-as-needed)
- endif()
+ # Only build the unittest libraries when running the tests. Unfortunately,
+ # I couldn't find an easier way to make a test depend on a CMake target than
+ # just invoking the build command through the CMake executable.
+ set_target_properties(${unittest_libs} PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT_BUILD ON)
+ foreach(l ${unittest_libs})
+ add_test(build-${l} "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${l})
+ endforeach()
- set(libarg "druntime-ldc-unittest${name_suffix}")
- add_test(NAME build-druntime-test-runner${name_suffix}
- COMMAND ${LDC_EXE_FULL}
- -of${PROJECT_BINARY_DIR}/druntime-test-runner${name_suffix}${CMAKE_EXECUTABLE_SUFFIX}
- -defaultlib=${libarg} -debuglib=${libarg}
- -singleobj ${flags} ${RUNTIME_DIR}/src/test_runner.d
- )
- set_tests_properties(build-druntime-test-runner${name_suffix} PROPERTIES
- DEPENDS build-druntime-ldc-unittest${name_suffix})
-
- if(PHOBOS2_DIR)
- set(libarg "phobos2-ldc-unittest${name_suffix},druntime-ldc-unittest${name_suffix}")
- add_test(NAME build-phobos2-test-runner${name_suffix}
- COMMAND ${LDC_EXE_FULL}
- -of${PROJECT_BINARY_DIR}/phobos2-test-runner${name_suffix}${CMAKE_EXECUTABLE_SUFFIX}
- -defaultlib=${libarg} -debuglib=${libarg}
- -singleobj ${flags} ${RUNTIME_DIR}/src/test_runner.d
- )
- set_tests_properties(build-phobos2-test-runner${name_suffix} PROPERTIES
- DEPENDS build-phobos2-ldc-unittest${name_suffix})
- endif()
- else()
- set(druntime_o "")
- set(druntime_bc "")
- set(casm_lib_path "${CMAKE_BINARY_DIR}/lib${path_suffix}")
- compile_druntime("${flags}" "-unittest${name_suffix}" "${path_suffix}" druntime_o druntime_bc)
-
- # We need to compile a small static library with the C/ASM files, as
- # there is no easy way of getting the object file names used when
- # compiling the main libraries. If we could require CMake 2.8.8, we
- # would be able to just build the files once (resp. twice for multilib)
- # for both the runtime debug/release builds and the tests. Oh well.
- set(druntime-casm druntime-ldc-casm${name_suffix})
- add_library(${druntime-casm} STATIC
- ${CORE_C} ${DCRT_C} ${DCRT_ASM})
- set_target_properties(
- ${druntime-casm} PROPERTIES
- LINKER_LANGUAGE C
- COMPILE_FLAGS "${RT_CFLAGS} ${c_flags}"
- LINK_FLAGS "${LD_FLAGS} ${ld_flags}"
- ARCHIVE_OUTPUT_DIRECTORY ${casm_lib_path}
- )
+ get_target_suffix("${name_suffix}" "${path_suffix}" target_suffix)
- # See shared library case for explanation.
- set_target_properties(${druntime-casm} PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT_BUILD ON)
- add_custom_target(druntime-ldc-unittest${name_suffix} DEPENDS ${druntime_o} ${druntime-casm})
- add_test(build-druntime-ldc-unittest${name_suffix} "${CMAKE_COMMAND}"
- --build ${CMAKE_BINARY_DIR} --target druntime-ldc-unittest${name_suffix})
+ set(tmpflags "${flags}")
+ append_flags_to_pull_in_all_objects("druntime-ldc-unittest" "${name_suffix}" "${target_suffix}" tmpflags)
+ add_test(NAME build-druntime-test-runner${target_suffix}
+ COMMAND ${LDC_EXE_FULL}
+ -of${PROJECT_BINARY_DIR}/druntime-test-runner${target_suffix}${CMAKE_EXECUTABLE_SUFFIX}
+ -defaultlib= -debuglib=
+ ${tmpflags} ${RUNTIME_DIR}/src/test_runner.d
+ )
+ set_tests_properties(build-druntime-test-runner${target_suffix} PROPERTIES
+ DEPENDS build-druntime-ldc-unittest${target_suffix})
- add_test(NAME build-druntime-test-runner${name_suffix}
+ if(PHOBOS2_DIR)
+ set(tmpflags "${flags}")
+ append_flags_to_pull_in_all_objects("phobos2-ldc-unittest" "${name_suffix}" "${target_suffix}" tmpflags)
+ set(libarg "druntime-ldc-unittest${name_suffix}")
+ add_test(NAME build-phobos2-test-runner${target_suffix}
COMMAND ${LDC_EXE_FULL}
- -of${PROJECT_BINARY_DIR}/druntime-test-runner${name_suffix}${CMAKE_EXECUTABLE_SUFFIX}
- -defaultlib=${druntime-casm} -debuglib=${druntime-casm}
- -singleobj ${flags} ${druntime_o} ${RUNTIME_DIR}/src/test_runner.d
+ -of${PROJECT_BINARY_DIR}/phobos2-test-runner${target_suffix}${CMAKE_EXECUTABLE_SUFFIX}
+ -defaultlib=${libarg} -debuglib=${libarg}
+ ${tmpflags} ${RUNTIME_DIR}/src/test_runner.d
)
- set_tests_properties(build-druntime-test-runner${name_suffix} PROPERTIES
- DEPENDS build-druntime-ldc-unittest${name_suffix}
+ set_tests_properties(build-phobos2-test-runner${target_suffix} PROPERTIES
+ DEPENDS "build-druntime-ldc-unittest${target_suffix};build-phobos2-ldc-unittest${target_suffix}"
)
-
- # And the same for Phobos.
- if(PHOBOS2_DIR)
- set(phobos2_o "")
- set(phobos2_bc "")
- compile_phobos2("${flags}" "-unittest${name_suffix}" "${path_suffix}" phobos2_o phobos2_bc)
-
- set(phobos2-casm phobos2-ldc-casm${name_suffix})
- add_library(${phobos2-casm} STATIC ${ZLIB_C})
- set_target_properties(
- ${phobos2-casm} PROPERTIES
- LINKER_LANGUAGE C
- COMPILE_FLAGS "${RT_CFLAGS} ${c_flags}"
- LINK_FLAGS "${LD_FLAGS} ${ld_flags}"
- ARCHIVE_OUTPUT_DIRECTORY ${casm_lib_path}
- )
-
- set_target_properties(${phobos2-casm} PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT_BUILD ON)
- add_custom_target(phobos2-ldc-unittest${name_suffix} DEPENDS ${phobos2_o} ${phobos2-casm})
- add_test(build-phobos2-ldc-unittest${name_suffix} "${CMAKE_COMMAND}"
- --build ${CMAKE_BINARY_DIR} --target phobos2-ldc-unittest${name_suffix})
-
- add_test(NAME build-phobos2-test-runner${name_suffix}
- COMMAND ${LDC_EXE_FULL}
- -of${PROJECT_BINARY_DIR}/phobos2-test-runner${name_suffix}${CMAKE_EXECUTABLE_SUFFIX}
- -defaultlib=druntime-ldc,${phobos2-casm} -debuglib=druntime-ldc,${phobos2-casm}
- -singleobj ${flags} ${phobos2_o} ${RUNTIME_DIR}/src/test_runner.d
- )
- set_tests_properties(build-phobos2-test-runner${name_suffix} PROPERTIES
- DEPENDS build-phobos2-ldc-unittest${name_suffix}
- )
- endif()
endif()
endmacro()
+
build_test_runner("" "${LIB_SUFFIX}" "${D_FLAGS_RELEASE}" "")
build_test_runner("-debug" "${LIB_SUFFIX}" "${D_FLAGS_DEBUG}" "")
if(MULTILIB AND ${HOST_BITNESS} EQUAL 64)
- build_test_runner("-32" "${MULTILIB_SUFFIX}" "${D_FLAGS_RELEASE};-m32" "-m32")
- build_test_runner("-debug-32" "${MULTILIB_SUFFIX}" "${D_FLAGS_DEBUG};-m32" "-m32")
+ build_test_runner("" "${MULTILIB_SUFFIX}" "${D_FLAGS_RELEASE};-m32" "-m32")
+ build_test_runner("-debug" "${MULTILIB_SUFFIX}" "${D_FLAGS_DEBUG};-m32" "-m32")
endif()
# Add the druntime/Phobos test runner invocations for all the different modules.
@@ -756,30 +708,31 @@ macro(file_to_module_name file_name out_module_name)
string(REPLACE "rt.invariant" "invariant" ${out_module_name} ${module})
endmacro()
-function(add_tests d_files runner name_suffix)
+function(add_tests d_files runner target_suffix)
foreach(file ${d_files})
file_to_module_name(${file} module)
- add_test(NAME "${module}${name_suffix}"
+ add_test(NAME "${module}${target_suffix}"
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
- COMMAND ${runner}-test-runner${name_suffix} ${module}
+ COMMAND ${runner}-test-runner${target_suffix} ${module}
)
- set_tests_properties("${module}${name_suffix}" PROPERTIES
- DEPENDS build-${runner}-test-runner${name_suffix}
+ set_tests_properties("${module}${target_suffix}" PROPERTIES
+ DEPENDS build-${runner}-test-runner${target_suffix}
)
endforeach()
endfunction()
-function(add_runtime_tests name_suffix)
- add_tests("${CORE_D};${DCRT_D};${GC_D}" "druntime" "${name_suffix}")
+function(add_runtime_tests name_suffix path_suffix)
+ get_target_suffix("${name_suffix}" "${path_suffix}" target_suffix)
+ add_tests("${CORE_D};${DCRT_D};${GC_D}" "druntime" "${target_suffix}")
if(PHOBOS2_DIR)
- add_tests("${PHOBOS2_D}" "phobos2" "${name_suffix}")
+ add_tests("${PHOBOS2_D}" "phobos2" "${target_suffix}")
endif()
endfunction()
-add_runtime_tests("")
-add_runtime_tests("-debug")
+add_runtime_tests("" "${LIB_SUFFIX}")
+add_runtime_tests("-debug" "${LIB_SUFFIX}")
if(MULTILIB AND ${HOST_BITNESS} EQUAL 64)
- add_runtime_tests("-32")
- add_runtime_tests("-debug-32")
+ add_runtime_tests("" "${MULTILIB_SUFFIX}")
+ add_runtime_tests("-debug" "${MULTILIB_SUFFIX}")
endif()
# Add the standalone druntime tests.
diff --git a/tests/d2/CMakeLists.txt b/tests/d2/CMakeLists.txt
index cf64789..87c3dea 100644
--- a/tests/d2/CMakeLists.txt
+++ b/tests/d2/CMakeLists.txt
@@ -53,6 +53,6 @@ add_testsuite("" -O3 "OFF" ${host_model})
if(MULTILIB AND host_model EQUAL 64)
# Also test in 32 bit mode on x86_64 multilib builds.
- add_testsuite("-debug-32" "-g -link-debuglib" "${gdb_flags}" 32)
- add_testsuite("-32" -O3 "OFF" 32)
+ add_testsuite("-debug_32" "-g -link-debuglib" "${gdb_flags}" 32)
+ add_testsuite("_32" -O3 "OFF" 32)
endif()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list