Index: llvm/trunk/utils/gn/secondary/lld/test/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/lld/test/BUILD.gn +++ llvm/trunk/utils/gn/secondary/lld/test/BUILD.gn @@ -80,6 +80,7 @@ ":lit_site_cfg", ":lit_unit_site_cfg", "//lld/tools/lld:symlinks", + "//lld/unittests", "//llvm/tools/llc", "//llvm/tools/llvm-ar:symlinks", "//llvm/tools/llvm-as", @@ -101,8 +102,6 @@ "//llvm/utils/not", ] testonly = true - - # FIXME: Add dep on "//lld/unittests" target once it exists. } # This is the action that runs all of lld's tests, check-lld. Index: llvm/trunk/utils/gn/secondary/lld/unittests/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/lld/unittests/BUILD.gn +++ llvm/trunk/utils/gn/secondary/lld/unittests/BUILD.gn @@ -0,0 +1,7 @@ +group("unittests") { + deps = [ + "DriverTests", + "MachOTests", + ] + testonly = true +} Index: llvm/trunk/utils/gn/secondary/lld/unittests/DriverTests/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/lld/unittests/DriverTests/BUILD.gn +++ llvm/trunk/utils/gn/secondary/lld/unittests/DriverTests/BUILD.gn @@ -0,0 +1,15 @@ +executable("DriverTests") { + # test/Unit/lit.cfg expects unittests in LLD_BINARY_DIR/unittest + output_dir = target_out_dir + + configs += [ "//llvm/utils/gn/build:lld_code" ] + deps = [ + "//lld/lib/Driver", + "//lld/lib/ReaderWriter/MachO", + "//llvm/utils/unittest/UnitTestMain", + ] + sources = [ + "DarwinLdDriverTest.cpp", + ] + testonly = true +} Index: llvm/trunk/utils/gn/secondary/lld/unittests/MachOTests/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/lld/unittests/MachOTests/BUILD.gn +++ llvm/trunk/utils/gn/secondary/lld/unittests/MachOTests/BUILD.gn @@ -0,0 +1,19 @@ +executable("MachOTests") { + # test/Unit/lit.cfg expects unittests in LLD_BINARY_DIR/unittest + output_dir = target_out_dir + + configs += [ "//llvm/utils/gn/build:lld_code" ] + deps = [ + "//lld/lib/Driver", + "//lld/lib/ReaderWriter/MachO", + "//lld/lib/ReaderWriter/YAML", + "//llvm/utils/unittest/UnitTestMain", + ] + sources = [ + "MachONormalizedFileBinaryReaderTests.cpp", + "MachONormalizedFileBinaryWriterTests.cpp", + "MachONormalizedFileToAtomsTests.cpp", + "MachONormalizedFileYAMLTests.cpp", + ] + testonly = true +} Index: llvm/trunk/utils/gn/secondary/llvm/utils/unittest/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/llvm/utils/unittest/BUILD.gn +++ llvm/trunk/utils/gn/secondary/llvm/utils/unittest/BUILD.gn @@ -0,0 +1,40 @@ +import("//llvm/utils/gn/build/libs/pthread/enable.gni") + +# Used to push the gtest include directories to things depending on :googletest. +config("googletest_config") { + include_dirs = [ + "googlemock/include", + "googletest/include", + ] + + # LLVM requires C++11 but gtest doesn't correctly detect the availability + # of C++11 on MSVC, so we force it on. + defines = [ + "GTEST_LANG_CXX11", + "GTEST_HAS_TR1_TUPLE=0", + ] + if (host_os == "win") { + defines += [ "GTEST_OS_WINDOWS" ] + } + if (!llvm_enable_threads) { + defines += [ "GTEST_HAS_PTHREAD=0" ] + } + defines += [ "GTEST_HAS_RTTI=0" ] +} + +static_library("gtest") { + deps = [ + "//llvm/lib/Support", + ] + include_dirs = [ + "googletest", # For including src/gtest.cc + "googlemock", # For including src/gmock.cc + ] + public_configs = [ ":googletest_config" ] + configs -= [ "//llvm/utils/gn/build:warn_covered_switch_default" ] + sources = [ + "googlemock/src/gmock-all.cc", + "googletest/src/gtest-all.cc", + ] + testonly = true +} Index: llvm/trunk/utils/gn/secondary/llvm/utils/unittest/UnitTestMain/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/llvm/utils/unittest/UnitTestMain/BUILD.gn +++ llvm/trunk/utils/gn/secondary/llvm/utils/unittest/UnitTestMain/BUILD.gn @@ -0,0 +1,25 @@ +source_set("UnitTestMain") { + deps = [ + "//llvm/lib/Support", + ] + + # Make targets depending on this also depend on gtest, to get the gtest + # include_dir. + public_deps = [ + "..:gtest", + ] + sources = [ + "TestMain.cpp", + ] + testonly = true +} + +# Nothing depends on this target, but llvm-config expects it to exist when +# it runs with `--link-static --system-libs`, so humor it. +static_library("gtest_main") { + deps = [ + ":UnitTestMain", + ] + complete_static_lib = true + testonly = true +}