diff --git a/Modules/Compiler/HP-CXX.cmake b/Modules/Compiler/HP-CXX.cmake
index 44470cae0fa180e52aa8b8646fa1377ff94dfb89..6411dac6bb9934f84165cceea5f17edd9beb8339 100644
--- a/Modules/Compiler/HP-CXX.cmake
+++ b/Modules/Compiler/HP-CXX.cmake
@@ -2,3 +2,12 @@ set(CMAKE_CXX_VERBOSE_FLAG "-v")
 
 set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
 set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+
+# HP aCC since version 3.80 supports the flag +hpxstd98 to get ANSI C++98
+# template support. It is known that version 6.25 doesn't need that flag.
+# Current assumption: the flag is needed for every version from 3.80 to 4
+# to get it working.
+if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4 AND
+   NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.80)
+  set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "+hpxstd98")
+endif()
diff --git a/Tests/AliasTarget/CMakeLists.txt b/Tests/AliasTarget/CMakeLists.txt
index 9467faed3cec30779751e33a72eeac4d8607844c..c50b4e6a8460a0a6689875130ac209c1ddd8865f 100644
--- a/Tests/AliasTarget/CMakeLists.txt
+++ b/Tests/AliasTarget/CMakeLists.txt
@@ -1,7 +1,15 @@
-
 cmake_minimum_required(VERSION 2.8.11)
 project(AliasTarget)
 
+set(CMAKE_CXX_STANDARD 98)
+
+# Those versions of the HP compiler that need a flag to get proper C++98
+# template support also need a flag to use the newer C++ library.
+if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND
+    CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA")
+endif ()
+
 add_library(foo SHARED empty.cpp)
 add_library(PREFIX::Foo ALIAS foo)
 add_library(Another::Alias ALIAS foo)
diff --git a/Tests/Complex/CMakeLists.txt b/Tests/Complex/CMakeLists.txt
index d250f539e68510f82252ae82a752d9143de94e46..5fa46bf9e7ba4019daf9d9bd8353145a70b1657a 100644
--- a/Tests/Complex/CMakeLists.txt
+++ b/Tests/Complex/CMakeLists.txt
@@ -392,6 +392,21 @@ if(NOT RESULT STREQUAL "a[b]c[d]e")
     "string(REGEX REPLACE ... ) test failed (\"${RESULT}\" v. \"a[b]c[d]e\")")
 endif()
 
+#
+# This tests needs Ansi C++98
+#
+set(CMAKE_CXX_STANDARD 98)
+#
+# GNU extensions are needed for stricmp() on Windows.
+#
+set(CMAKE_CXX_EXTENSIONS TRUE)
+
+# Those versions of the HP compiler that need a flag to get proper C++98
+# template support also need a flag to use the newer C++ library.
+if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND
+    CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA")
+endif ()
 
 #
 # Create the libs and the main exe
diff --git a/Tests/ComplexOneConfig/CMakeLists.txt b/Tests/ComplexOneConfig/CMakeLists.txt
index bb003419f0e9b3d4c0435a38ce53bd8a80834980..d3d91323e029bc8007431e025a488c2dc425b5a8 100644
--- a/Tests/ComplexOneConfig/CMakeLists.txt
+++ b/Tests/ComplexOneConfig/CMakeLists.txt
@@ -362,6 +362,21 @@ if(NOT RESULT STREQUAL "a[b]c[d]e")
     "string(REGEX REPLACE ... ) test failed (\"${RESULT}\" v. \"a[b]c[d]e\")")
 endif()
 
+#
+# This tests needs Ansi C++98
+#
+set(CMAKE_CXX_STANDARD 98)
+#
+# GNU extensions are needed for stricmp() on Windows.
+#
+set(CMAKE_CXX_EXTENSIONS TRUE)
+
+# Those versions of the HP compiler that need a flag to get proper C++98
+# template support also need a flag to use the newer C++ library.
+if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND
+    CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA")
+endif ()
 
 #
 # Create the libs and the main exe
diff --git a/Tests/Module/GenerateExportHeader/CMakeLists.txt b/Tests/Module/GenerateExportHeader/CMakeLists.txt
index bf867a94f6a9c78c526b6219f9a9ffbd79284ff6..b52c44d7338d0e9e30c45b9fecd0fc02b039bb17 100644
--- a/Tests/Module/GenerateExportHeader/CMakeLists.txt
+++ b/Tests/Module/GenerateExportHeader/CMakeLists.txt
@@ -57,6 +57,15 @@ endif()
 
 include(GenerateExportHeader)
 
+set(CMAKE_CXX_STANDARD 98)
+
+# Those versions of the HP compiler that need a flag to get proper C++98
+# template support also need a flag to use the newer C++ library.
+if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND
+    CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA")
+endif ()
+
 add_subdirectory(lib_shared_and_static)
 
 add_compiler_export_flags()
diff --git a/Tests/Plugin/CMakeLists.txt b/Tests/Plugin/CMakeLists.txt
index c6ed15d36429e372d8495fbe060433310148bc36..ecdece8b507fd999d06f7f61cf3f1a86457d16ff 100644
--- a/Tests/Plugin/CMakeLists.txt
+++ b/Tests/Plugin/CMakeLists.txt
@@ -24,6 +24,16 @@ include_directories(
   ${Plugin_SOURCE_DIR}/include
   )
 
+# We need proper C++98 support from the compiler
+set(CMAKE_CXX_STANDARD 98)
+
+# Those versions of the HP compiler that need a flag to get proper C++98
+# template support also need a flag to use the newer C++ library.
+if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND
+    CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA")
+endif ()
+
 # Create an executable that exports an API for use by plugins.
 add_executable(example_exe src/example_exe.cxx)
 set_target_properties(example_exe PROPERTIES