summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-05-18 18:39:25 (GMT)
committerBrad King <brad.king@kitware.com>2015-05-19 17:16:29 (GMT)
commitada5ffce7bad40c56e5d0dd76b9a7b30c96a9e92 (patch)
tree31755e49ec06997658c4cc24ef3ae33f1b3869df /Tests/RunCMake
parent67fa3da9e84888029d128280f35a8e7b3d208377 (diff)
downloadCMake-ada5ffce7bad40c56e5d0dd76b9a7b30c96a9e92.zip
CMake-ada5ffce7bad40c56e5d0dd76b9a7b30c96a9e92.tar.gz
CMake-ada5ffce7bad40c56e5d0dd76b9a7b30c96a9e92.tar.bz2
Add options to run include-what-you-use with the compiler
Create a <LANG>_INCLUDE_WHAT_YOU_USE target property (initialized by a CMAKE_<LANG>_INCLUDE_WHAT_YOU_USE variable) to specify an IWYU command line to be run along with the compiler.
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r--Tests/RunCMake/CMakeLists.txt5
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/C-Build-stdout.txt4
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/C.cmake3
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/CXX-Build-stdout.txt4
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/CXX.cmake3
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/RunCMakeTest.cmake18
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/main.c1
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/main.cxx1
-rw-r--r--Tests/RunCMake/pseudo_iwyu.c7
10 files changed, 49 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 16fb056..2100b55 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -241,3 +241,8 @@ if(CMAKE_OSX_ARCHITECTURES AND XCODE AND NOT "${XCODE_VERSION}" MATCHES "^[^12]"
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CFG_INTDIR}"
)
endif()
+
+if("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
+ add_executable(pseudo_iwyu pseudo_iwyu.c)
+ add_RunCMake_test(IncludeWhatYouUse -DPSEUDO_IWYU=$<TARGET_FILE:pseudo_iwyu>)
+endif()
diff --git a/Tests/RunCMake/IncludeWhatYouUse/C-Build-stdout.txt b/Tests/RunCMake/IncludeWhatYouUse/C-Build-stdout.txt
new file mode 100644
index 0000000..cb74677
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/C-Build-stdout.txt
@@ -0,0 +1,4 @@
+Warning: include-what-you-use reported diagnostics:
+should add these lines:
+*
+#include <\.\.\.>
diff --git a/Tests/RunCMake/IncludeWhatYouUse/C.cmake b/Tests/RunCMake/IncludeWhatYouUse/C.cmake
new file mode 100644
index 0000000..f400e86
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/C.cmake
@@ -0,0 +1,3 @@
+enable_language(C)
+set(CMAKE_C_INCLUDE_WHAT_YOU_USE "${PSEUDO_IWYU}" -some -args)
+add_executable(main main.c)
diff --git a/Tests/RunCMake/IncludeWhatYouUse/CMakeLists.txt b/Tests/RunCMake/IncludeWhatYouUse/CMakeLists.txt
new file mode 100644
index 0000000..18dfd26
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.2)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/IncludeWhatYouUse/CXX-Build-stdout.txt b/Tests/RunCMake/IncludeWhatYouUse/CXX-Build-stdout.txt
new file mode 100644
index 0000000..cb74677
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/CXX-Build-stdout.txt
@@ -0,0 +1,4 @@
+Warning: include-what-you-use reported diagnostics:
+should add these lines:
+*
+#include <\.\.\.>
diff --git a/Tests/RunCMake/IncludeWhatYouUse/CXX.cmake b/Tests/RunCMake/IncludeWhatYouUse/CXX.cmake
new file mode 100644
index 0000000..896930c
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/CXX.cmake
@@ -0,0 +1,3 @@
+enable_language(CXX)
+set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${PSEUDO_IWYU}" -some -args)
+add_executable(main main.cxx)
diff --git a/Tests/RunCMake/IncludeWhatYouUse/RunCMakeTest.cmake b/Tests/RunCMake/IncludeWhatYouUse/RunCMakeTest.cmake
new file mode 100644
index 0000000..68c6bd7
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/RunCMakeTest.cmake
@@ -0,0 +1,18 @@
+include(RunCMake)
+
+set(RunCMake_TEST_OPTIONS "-DPSEUDO_IWYU=${PSEUDO_IWYU}")
+
+function(run_iwyu lang)
+ # Use a single build tree for tests without cleaning.
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${lang}-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ run_cmake(${lang})
+
+ set(RunCMake_TEST_OUTPUT_MERGE 1)
+ run_cmake_command(${lang}-Build ${CMAKE_COMMAND} --build .)
+endfunction()
+
+run_iwyu(C)
+run_iwyu(CXX)
diff --git a/Tests/RunCMake/IncludeWhatYouUse/main.c b/Tests/RunCMake/IncludeWhatYouUse/main.c
new file mode 100644
index 0000000..78f2de1
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/main.c
@@ -0,0 +1 @@
+int main(void) { return 0; }
diff --git a/Tests/RunCMake/IncludeWhatYouUse/main.cxx b/Tests/RunCMake/IncludeWhatYouUse/main.cxx
new file mode 100644
index 0000000..76e8197
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/main.cxx
@@ -0,0 +1 @@
+int main() { return 0; }
diff --git a/Tests/RunCMake/pseudo_iwyu.c b/Tests/RunCMake/pseudo_iwyu.c
new file mode 100644
index 0000000..1e25de7
--- /dev/null
+++ b/Tests/RunCMake/pseudo_iwyu.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(void)
+{
+ fprintf(stderr, "should add these lines:\n#include <...>\n");
+ return 0;
+}