summaryrefslogtreecommitdiff
path: root/Tests/PrecompiledHeader
diff options
context:
space:
mode:
authorAnas Nashif <anas.nashif@intel.com>2012-10-30 15:39:57 -0700
committerAnas Nashif <anas.nashif@intel.com>2012-10-30 15:39:57 -0700
commit035c7fabc3b82cbc9a346c11abe2e9462b4c0379 (patch)
tree7e40f5a790eae329a8c5d3e59f046451767956ff /Tests/PrecompiledHeader
downloadcmake-035c7fabc3b82cbc9a346c11abe2e9462b4c0379.tar.gz
cmake-035c7fabc3b82cbc9a346c11abe2e9462b4c0379.tar.bz2
cmake-035c7fabc3b82cbc9a346c11abe2e9462b4c0379.zip
Imported Upstream version 2.8.9upstream/2.8.9
Diffstat (limited to 'Tests/PrecompiledHeader')
-rw-r--r--Tests/PrecompiledHeader/CMakeLists.txt59
-rw-r--r--Tests/PrecompiledHeader/foo1.c8
-rw-r--r--Tests/PrecompiledHeader/foo2.c9
-rw-r--r--Tests/PrecompiledHeader/foo_precompile.c5
-rw-r--r--Tests/PrecompiledHeader/include/foo.h4
-rw-r--r--Tests/PrecompiledHeader/include/foo_precompiled.h1
6 files changed, 86 insertions, 0 deletions
diff --git a/Tests/PrecompiledHeader/CMakeLists.txt b/Tests/PrecompiledHeader/CMakeLists.txt
new file mode 100644
index 000000000..3374e325f
--- /dev/null
+++ b/Tests/PrecompiledHeader/CMakeLists.txt
@@ -0,0 +1,59 @@
+cmake_minimum_required (VERSION 2.6)
+PROJECT(PrecompiledHeader C)
+
+# Make sure the proper compiler is in use.
+IF(NOT MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$")
+ MESSAGE(FATAL_ERROR "The PrecompiledHeader test works only with MSVC or Intel")
+ENDIF()
+
+# Compute a custom name for the precompiled header.
+IF(CMAKE_CONFIGURATION_TYPES)
+ SET(PCH_DIR "${CMAKE_CURRENT_BINARY_DIR}/PCH/${CMAKE_CFG_INTDIR}")
+ FOREACH(cfg ${CMAKE_CONFIGURATION_TYPES})
+ FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/PCH/${cfg})
+ ENDFOREACH()
+ELSE(CMAKE_CONFIGURATION_TYPES)
+ SET(PCH_DIR "${CMAKE_CURRENT_BINARY_DIR}/PCH")
+ FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/PCH)
+ENDIF(CMAKE_CONFIGURATION_TYPES)
+
+# The VS6 IDE does not support renaming .pch files with /Fp.
+IF("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
+ SET(PCH_USE_INCLUDE_DIR 1)
+ SET(PCH_FILE)
+ELSE("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
+ SET(PCH_USE_INCLUDE_DIR 0)
+ SET(PCH_FILE "\"/Fp${PCH_DIR}/foo_precompiled.pch\"")
+ENDIF("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
+
+# Choose between an explicit include path and using /I during
+# precompilation. The /I form is used to test that the PCH is
+# actually used. In practice the include path form would be used.
+IF(PCH_USE_INCLUDE_DIR)
+ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+ELSE(PCH_USE_INCLUDE_DIR)
+ SET(PCH_INCLUDE_DIR "\"/I${CMAKE_CURRENT_SOURCE_DIR}/include\"")
+ENDIF(PCH_USE_INCLUDE_DIR)
+
+# Create a target that will use a precompiled header.
+SET(foo_SRCS foo1.c foo2.c)
+ADD_EXECUTABLE(foo foo_precompile.c ${foo_SRCS})
+
+# Setup flags on the target to create and use the precompiled header.
+SET_TARGET_PROPERTIES(foo PROPERTIES
+ COMPILE_FLAGS "/Yufoo_precompiled.h /FIfoo_precompiled.h ${PCH_FILE}")
+SET_SOURCE_FILES_PROPERTIES(foo_precompile.c PROPERTIES
+ COMPILE_FLAGS "/Ycfoo_precompiled.h ${PCH_INCLUDE_DIR}")
+
+# Setup dependencies for precompiled header creation and use. The VS
+# IDE takes care of this automatically.
+IF("${CMAKE_GENERATOR}" MATCHES "Makefile" OR
+ "${CMAKE_GENERATOR}" MATCHES "Ninja")
+ # This source file creates the precompiled header as a side-effect.
+ SET_SOURCE_FILES_PROPERTIES(foo_precompile.c PROPERTIES
+ OBJECT_OUTPUTS "${PCH_DIR}/foo_precompiled.pch")
+
+ # These source files use the precompiled header.
+ SET_SOURCE_FILES_PROPERTIES(${foo_SRCS} PROPERTIES
+ OBJECT_DEPENDS "${PCH_DIR}/foo_precompiled.pch")
+ENDIF("${CMAKE_GENERATOR}" MATCHES "Makefile")
diff --git a/Tests/PrecompiledHeader/foo1.c b/Tests/PrecompiledHeader/foo1.c
new file mode 100644
index 000000000..b10eba7e9
--- /dev/null
+++ b/Tests/PrecompiledHeader/foo1.c
@@ -0,0 +1,8 @@
+#ifndef foo_h
+# error "Precompiled header foo_precompiled.h has not been loaded."
+#endif
+
+int main()
+{
+ return foo();
+}
diff --git a/Tests/PrecompiledHeader/foo2.c b/Tests/PrecompiledHeader/foo2.c
new file mode 100644
index 000000000..2845cdb15
--- /dev/null
+++ b/Tests/PrecompiledHeader/foo2.c
@@ -0,0 +1,9 @@
+#ifndef foo_h
+# include "foo.h"
+# error "Precompiled header foo_precompiled.h has not been loaded."
+#endif
+
+int foo()
+{
+ return 0;
+}
diff --git a/Tests/PrecompiledHeader/foo_precompile.c b/Tests/PrecompiledHeader/foo_precompile.c
new file mode 100644
index 000000000..c37d69a1c
--- /dev/null
+++ b/Tests/PrecompiledHeader/foo_precompile.c
@@ -0,0 +1,5 @@
+/* The foo_precompiled.h header is included by a /FI option when this
+ source is used to create a precompiled header. Include it here
+ explicitly to allow dependency scanning to detect the dependency
+ whether or not the include path is known to the scanner. */
+#include "include/foo_precompiled.h"
diff --git a/Tests/PrecompiledHeader/include/foo.h b/Tests/PrecompiledHeader/include/foo.h
new file mode 100644
index 000000000..2210cb41d
--- /dev/null
+++ b/Tests/PrecompiledHeader/include/foo.h
@@ -0,0 +1,4 @@
+#ifndef foo_h
+#define foo_h
+extern int foo();
+#endif
diff --git a/Tests/PrecompiledHeader/include/foo_precompiled.h b/Tests/PrecompiledHeader/include/foo_precompiled.h
new file mode 100644
index 000000000..f4de601ff
--- /dev/null
+++ b/Tests/PrecompiledHeader/include/foo_precompiled.h
@@ -0,0 +1 @@
+#include "foo.h"