2016-09-27 19:01:08 +00:00
|
|
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
|
|
|
|
2013-10-15 15:17:36 +00:00
|
|
|
#.rst:
|
|
|
|
# FindCxxTest
|
|
|
|
# -----------
|
|
|
|
#
|
|
|
|
# Find CxxTest
|
|
|
|
#
|
|
|
|
# Find the CxxTest suite and declare a helper macro for creating unit
|
|
|
|
# tests and integrating them with CTest. For more details on CxxTest
|
|
|
|
# see http://cxxtest.tigris.org
|
2008-12-12 03:05:30 +00:00
|
|
|
#
|
|
|
|
# INPUT Variables
|
|
|
|
#
|
2013-10-15 15:17:36 +00:00
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# CXXTEST_USE_PYTHON [deprecated since 1.3]
|
|
|
|
# Only used in the case both Python & Perl
|
|
|
|
# are detected on the system to control
|
|
|
|
# which CxxTest code generator is used.
|
|
|
|
# Valid only for CxxTest version 3.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# NOTE: In older versions of this Find Module,
|
|
|
|
# this variable controlled if the Python test
|
|
|
|
# generator was used instead of the Perl one,
|
|
|
|
# regardless of which scripting language the
|
|
|
|
# user had installed.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# CXXTEST_TESTGEN_ARGS (since CMake 2.8.3)
|
|
|
|
# Specify a list of options to pass to the CxxTest code
|
|
|
|
# generator. If not defined, --error-printer is
|
|
|
|
# passed.
|
2010-08-20 01:33:37 +00:00
|
|
|
#
|
|
|
|
#
|
2008-12-12 03:05:30 +00:00
|
|
|
#
|
|
|
|
# OUTPUT Variables
|
|
|
|
#
|
2013-10-15 15:17:36 +00:00
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# CXXTEST_FOUND
|
|
|
|
# True if the CxxTest framework was found
|
|
|
|
# CXXTEST_INCLUDE_DIRS
|
|
|
|
# Where to find the CxxTest include directory
|
|
|
|
# CXXTEST_PERL_TESTGEN_EXECUTABLE
|
|
|
|
# The perl-based test generator
|
|
|
|
# CXXTEST_PYTHON_TESTGEN_EXECUTABLE
|
|
|
|
# The python-based test generator
|
|
|
|
# CXXTEST_TESTGEN_EXECUTABLE (since CMake 2.8.3)
|
|
|
|
# The test generator that is actually used (chosen using user preferences
|
|
|
|
# and interpreters found in the system)
|
|
|
|
# CXXTEST_TESTGEN_INTERPRETER (since CMake 2.8.3)
|
2016-09-28 15:25:54 +00:00
|
|
|
# The full path to the Perl or Python executable on the system, on
|
|
|
|
# platforms where the script cannot be executed using its shebang line.
|
2013-10-15 15:17:36 +00:00
|
|
|
#
|
|
|
|
#
|
2008-12-12 03:05:30 +00:00
|
|
|
#
|
2009-02-10 04:05:38 +00:00
|
|
|
# MACROS for optional use by CMake users:
|
2008-12-12 03:05:30 +00:00
|
|
|
#
|
2013-10-15 15:17:36 +00:00
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# CXXTEST_ADD_TEST(<test_name> <gen_source_file> <input_files_to_testgen...>)
|
|
|
|
# Creates a CxxTest runner and adds it to the CTest testing suite
|
|
|
|
# Parameters:
|
|
|
|
# test_name The name of the test
|
|
|
|
# gen_source_file The generated source filename to be
|
|
|
|
# generated by CxxTest
|
|
|
|
# input_files_to_testgen The list of header files containing the
|
|
|
|
# CxxTest::TestSuite's to be included in
|
|
|
|
# this runner
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# #==============
|
|
|
|
# Example Usage:
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# find_package(CxxTest)
|
|
|
|
# if(CXXTEST_FOUND)
|
|
|
|
# include_directories(${CXXTEST_INCLUDE_DIR})
|
|
|
|
# enable_testing()
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# CXXTEST_ADD_TEST(unittest_foo foo_test.cc
|
|
|
|
# ${CMAKE_CURRENT_SOURCE_DIR}/foo_test.h)
|
|
|
|
# target_link_libraries(unittest_foo foo) # as needed
|
|
|
|
# endif()
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# This will (if CxxTest is found):
|
|
|
|
# 1. Invoke the testgen executable to autogenerate foo_test.cc in the
|
|
|
|
# binary tree from "foo_test.h" in the current source directory.
|
|
|
|
# 2. Create an executable and test called unittest_foo.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# #=============
|
|
|
|
# Example foo_test.h:
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# #include <cxxtest/TestSuite.h>
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# ::
|
2009-01-08 09:47:40 +00:00
|
|
|
#
|
2013-10-15 15:17:36 +00:00
|
|
|
# class MyTestSuite : public CxxTest::TestSuite
|
|
|
|
# {
|
|
|
|
# public:
|
|
|
|
# void testAddition( void )
|
|
|
|
# {
|
|
|
|
# TS_ASSERT( 1 + 1 > 1 );
|
|
|
|
# TS_ASSERT_EQUALS( 1 + 1, 2 );
|
|
|
|
# }
|
|
|
|
# };
|
2009-09-22 02:38:12 +00:00
|
|
|
|
2010-11-19 04:27:35 +00:00
|
|
|
# Version 1.4 (11/18/10) (CMake 2.8.4)
|
|
|
|
# Issue 11384: Added support to the CXX_ADD_TEST macro so header
|
|
|
|
# files (containing the tests themselves) show up in
|
|
|
|
# Visual Studio and other IDEs.
|
|
|
|
#
|
2010-08-20 01:33:37 +00:00
|
|
|
# Version 1.3 (8/19/10) (CMake 2.8.3)
|
|
|
|
# Included patch by Simone Rossetto to check if either Python or Perl
|
|
|
|
# are present in the system. Whichever intepreter that is detected
|
|
|
|
# is now used to run the test generator program. If both interpreters
|
|
|
|
# are detected, the CXXTEST_USE_PYTHON variable is obeyed.
|
|
|
|
#
|
|
|
|
# Also added support for CXXTEST_TESTGEN_ARGS, for manually specifying
|
|
|
|
# options to the CxxTest code generator.
|
2009-03-03 01:29:38 +00:00
|
|
|
# Version 1.2 (3/2/08)
|
|
|
|
# Included patch from Tyler Roscoe to have the perl & python binaries
|
|
|
|
# detected based on CXXTEST_INCLUDE_DIR
|
2009-02-10 04:05:38 +00:00
|
|
|
# Version 1.1 (2/9/08)
|
|
|
|
# Clarified example to illustrate need to call target_link_libraries()
|
|
|
|
# Changed commands to lowercase
|
|
|
|
# Added licensing info
|
2009-01-08 09:47:40 +00:00
|
|
|
# Version 1.0 (1/8/08)
|
|
|
|
# Fixed CXXTEST_INCLUDE_DIRS so it will work properly
|
|
|
|
# Eliminated superfluous CXXTEST_FOUND assignment
|
|
|
|
# Cleaned up and added more documentation
|
2008-12-12 03:05:30 +00:00
|
|
|
|
2009-01-08 09:47:40 +00:00
|
|
|
#=============================================================
|
|
|
|
# CXXTEST_ADD_TEST (public macro)
|
|
|
|
#=============================================================
|
2009-02-10 04:05:38 +00:00
|
|
|
macro(CXXTEST_ADD_TEST _cxxtest_testname _cxxtest_outfname)
|
|
|
|
set(_cxxtest_real_outfname ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_outfname})
|
2008-12-12 03:05:30 +00:00
|
|
|
|
2009-02-10 04:05:38 +00:00
|
|
|
add_custom_command(
|
2008-12-12 03:05:30 +00:00
|
|
|
OUTPUT ${_cxxtest_real_outfname}
|
|
|
|
DEPENDS ${ARGN}
|
2010-08-20 01:33:37 +00:00
|
|
|
COMMAND ${CXXTEST_TESTGEN_INTERPRETER}
|
|
|
|
${CXXTEST_TESTGEN_EXECUTABLE} ${CXXTEST_TESTGEN_ARGS} -o ${_cxxtest_real_outfname} ${ARGN}
|
2008-12-12 03:05:30 +00:00
|
|
|
)
|
|
|
|
|
2009-02-10 04:05:38 +00:00
|
|
|
set_source_files_properties(${_cxxtest_real_outfname} PROPERTIES GENERATED true)
|
2010-11-19 04:27:35 +00:00
|
|
|
add_executable(${_cxxtest_testname} ${_cxxtest_real_outfname} ${ARGN})
|
2008-12-12 03:05:30 +00:00
|
|
|
|
2009-02-10 04:05:38 +00:00
|
|
|
if(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
|
|
|
|
add_test(${_cxxtest_testname} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_cxxtest_testname})
|
|
|
|
elseif(EXECUTABLE_OUTPUT_PATH)
|
|
|
|
add_test(${_cxxtest_testname} ${EXECUTABLE_OUTPUT_PATH}/${_cxxtest_testname})
|
|
|
|
else()
|
|
|
|
add_test(${_cxxtest_testname} ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_testname})
|
|
|
|
endif()
|
2008-12-12 03:05:30 +00:00
|
|
|
|
2012-08-13 17:50:14 +00:00
|
|
|
endmacro()
|
2008-12-12 03:05:30 +00:00
|
|
|
|
2009-01-08 09:47:40 +00:00
|
|
|
#=============================================================
|
|
|
|
# main()
|
|
|
|
#=============================================================
|
2010-08-20 01:33:37 +00:00
|
|
|
if(NOT DEFINED CXXTEST_TESTGEN_ARGS)
|
|
|
|
set(CXXTEST_TESTGEN_ARGS --error-printer)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_package(PythonInterp QUIET)
|
|
|
|
find_package(Perl QUIET)
|
2008-12-12 03:05:30 +00:00
|
|
|
|
2009-02-10 04:05:38 +00:00
|
|
|
find_path(CXXTEST_INCLUDE_DIR cxxtest/TestSuite.h)
|
2012-03-07 12:57:47 +00:00
|
|
|
find_program(CXXTEST_PYTHON_TESTGEN_EXECUTABLE
|
|
|
|
NAMES cxxtestgen cxxtestgen.py
|
2010-08-20 01:33:37 +00:00
|
|
|
PATHS ${CXXTEST_INCLUDE_DIR})
|
|
|
|
find_program(CXXTEST_PERL_TESTGEN_EXECUTABLE cxxtestgen.pl
|
|
|
|
PATHS ${CXXTEST_INCLUDE_DIR})
|
|
|
|
|
|
|
|
if(PYTHONINTERP_FOUND OR PERL_FOUND)
|
Modules: Include builtin FindPackageHandleStandardArgs directly
The FindPackageHandleStandardArgs module was originally created outside
of CMake. It was added for CMake 2.6.0 by commit e118a627 (add a macro
FIND_PACKAGE_HANDLE_STANDARD_ARGS..., 2007-07-18). However, it also
proliferated into a number of other projects that at the time required
only CMake 2.4 and thus could not depend on CMake to provide the module.
CMake's own find modules started using the module in commit b5f656e0
(use the new FIND_PACKAGE_HANDLE_STANDARD_ARGS in some of the FindXXX
modules..., 2007-07-18).
Then commit d358cf5c (add 2nd, more powerful mode to
find_package_handle_standard_args, 2010-07-29) added a new feature to
the interface of the module that was fully optional and backward
compatible with all existing users of the module. Later commit 5f183caa
(FindZLIB: use the FPHSA version mode, 2010-08-04) and others shortly
thereafter started using the new interface in CMake's own find modules.
This change was also backward compatible because it was only an
implementation detail within each module.
Unforutnately these changes introduced a problem for projects that still
have an old copy of FindPackageHandleStandardArgs in CMAKE_MODULE_PATH.
When any such project uses one of CMake's builtin find modules the line
include(FindPackageHandleStandardArgs)
loads the copy from the project which does not have the new interface!
Then the including find module tries to use the new interface with the
old module and fails.
Whether this breakage can be considered a backward incompatible change
in CMake is debatable. The situation is analagous to copying a standard
library header from one version of a compiler into a project and then
observing problems when the next version of the compiler reports errors
in its other headers that depend on its new version of the original
header. Nevertheless it is a change to CMake that causes problems for
projects that worked with previous versions.
This problem was discovered during the 2.8.3 release candidate cycle.
It is an instance of a more general problem with projects that provide
their own versions of CMake modules when other CMake modules depend on
them. At the time we resolved this instance of the problem with commit
b0118402 (Use absolute path to FindPackageHandleStandardArgs.cmake
everywhere, 2010-09-28) for the 2.8.3 release.
In order to address the more general problem we introduced policy
CMP0017 in commit db44848f (Prefer files from CMAKE_ROOT when including
from CMAKE_ROOT, 2010-11-17). That change was followed by commit
ce28737c (Remove usage of CMAKE_CURRENT_LIST_DIR now that we have
CMP0017, 2010-12-20) which reverted the original workaround in favor of
using the policy. However, existing project releases do not set the
policy behavior to NEW and therefore still exhibit the problem.
We introduced in commit a364daf1 (Allow users to specify defaults for
unset policies, 2011-01-03) an option for users to build existing
projects by adding -DCMAKE_POLICY_DEFAULT_CMP0017=NEW to the command
line. Unfortunately this solution still does not allow such projects to
build out of the box, and there is no good way to suggest the use of the
new option.
The only remaining solution to keep existing projects that exhibit this
problem building is to restore the change originally made in commit
b0118402 (Use absolute path to FindPackageHandleStandardArgs.cmake
everywhere, 2010-09-28). This also avoids policy CMP0017 warnings for
this particular instance of the problem the policy addresses.
2011-01-20 15:56:49 +00:00
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
2010-08-20 01:33:37 +00:00
|
|
|
|
2012-03-07 12:57:47 +00:00
|
|
|
if(PYTHONINTERP_FOUND AND (CXXTEST_USE_PYTHON OR NOT PERL_FOUND OR NOT DEFINED CXXTEST_USE_PYTHON))
|
2010-08-20 01:33:37 +00:00
|
|
|
set(CXXTEST_TESTGEN_EXECUTABLE ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE})
|
2016-09-28 15:25:54 +00:00
|
|
|
execute_process(COMMAND ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE} --version
|
|
|
|
OUTPUT_VARIABLE _CXXTEST_OUT ERROR_VARIABLE _CXXTEST_OUT RESULT_VARIABLE _CXXTEST_RESULT)
|
|
|
|
if(_CXXTEST_RESULT EQUAL 0)
|
|
|
|
set(CXXTEST_TESTGEN_INTERPRETER "")
|
|
|
|
else()
|
|
|
|
set(CXXTEST_TESTGEN_INTERPRETER ${PYTHON_EXECUTABLE})
|
|
|
|
endif()
|
2010-08-20 01:33:37 +00:00
|
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CxxTest DEFAULT_MSG
|
|
|
|
CXXTEST_INCLUDE_DIR CXXTEST_PYTHON_TESTGEN_EXECUTABLE)
|
|
|
|
|
|
|
|
elseif(PERL_FOUND)
|
|
|
|
set(CXXTEST_TESTGEN_EXECUTABLE ${CXXTEST_PERL_TESTGEN_EXECUTABLE})
|
|
|
|
set(CXXTEST_TESTGEN_INTERPRETER ${PERL_EXECUTABLE})
|
|
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CxxTest DEFAULT_MSG
|
|
|
|
CXXTEST_INCLUDE_DIR CXXTEST_PERL_TESTGEN_EXECUTABLE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CXXTEST_FOUND)
|
|
|
|
set(CXXTEST_INCLUDE_DIRS ${CXXTEST_INCLUDE_DIR})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
else()
|
2008-12-12 03:05:30 +00:00
|
|
|
|
2010-08-20 01:33:37 +00:00
|
|
|
set(CXXTEST_FOUND false)
|
|
|
|
if(NOT CxxTest_FIND_QUIETLY)
|
|
|
|
if(CxxTest_FIND_REQUIRED)
|
|
|
|
message(FATAL_ERROR "Neither Python nor Perl found, cannot use CxxTest, aborting!")
|
|
|
|
else()
|
|
|
|
message(STATUS "Neither Python nor Perl found, CxxTest will not be used.")
|
|
|
|
endif()
|
|
|
|
endif()
|
2009-02-10 04:05:38 +00:00
|
|
|
|
2010-08-20 01:33:37 +00:00
|
|
|
endif()
|