diff options
author | Philip Lowman <philip@yhbt.com> | 2008-12-12 03:05:30 (GMT) |
---|---|---|
committer | Philip Lowman <philip@yhbt.com> | 2008-12-12 03:05:30 (GMT) |
commit | 9b9578e098c76a64b78d0f6b464c928e3cf08f05 (patch) | |
tree | 0df25e541fc7ef99440131b4e6bdabaf32d8ac43 /Modules/FindCxxTest.cmake | |
parent | 3ddb9dfdea1c8049e5e7e7b6390e4ec5612d4bfe (diff) | |
download | CMake-9b9578e098c76a64b78d0f6b464c928e3cf08f05.zip CMake-9b9578e098c76a64b78d0f6b464c928e3cf08f05.tar.gz CMake-9b9578e098c76a64b78d0f6b464c928e3cf08f05.tar.bz2 |
ENH: Added FindCxxTest module to assist others in using the CxxTest unit testing framework within CTest
Diffstat (limited to 'Modules/FindCxxTest.cmake')
-rw-r--r-- | Modules/FindCxxTest.cmake | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/Modules/FindCxxTest.cmake b/Modules/FindCxxTest.cmake new file mode 100644 index 0000000..6eb2a73 --- /dev/null +++ b/Modules/FindCxxTest.cmake @@ -0,0 +1,90 @@ +# - Find CxxTest +# Find the CxxTest suite and declare a helper macro for creating unit tests +# and integrating them with CTest. To assist in finding CxxTest the +# CMAKE_PREFIX_PATH variable can be used. +# For more details on CxxTest see http://cxxtest.tigris.org +# +# INPUT Variables +# +# CXXTEST_USE_PYTHON +# If true, have the CXXTEST_ADD_TEST macro use +# the python test generator instead of perl. +# +# OUTPUT Variables +# +# CXXTEST_INCLUDE_DIR +# Where to find the CxxTest include directory +# CXXTEST_FOUND +# True if the CxxTest framework was found +# CXXTEST_PERL_TESTGEN_EXECUTABLE +# The perl-based test generator. +# CXXTEST_PYTHON_TESTGEN_EXECUTABLE +# The python-based test generator. +# +# MACROS for use by CMake users: +# +# 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: +# ENABLE_TESTING() +# CXXTEST_ADD_TEST(unittest_foo foo_test.cc ${CMAKE_CURRENT_SOURCE_DIR}/foo_test.h) +# +# This will: +# 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. +# + +MACRO(CXXTEST_ADD_TEST _cxxtest_testname _cxxtest_outfname) + SET(_cxxtest_real_outfname ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_outfname}) + IF(CXXTEST_USE_PYTHON) + SET(_cxxtest_executable ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE}) + ELSE(CXXTEST_USE_PYTHON) + SET(_cxxtest_executable ${CXXTEST_PERL_TESTGEN_EXECUTABLE}) + ENDIF(CXXTEST_USE_PYTHON) + + ADD_CUSTOM_COMMAND( + OUTPUT ${_cxxtest_real_outfname} + DEPENDS ${ARGN} + COMMAND ${_cxxtest_executable} + --error-printer -o ${_cxxtest_real_outfname} ${ARGN} + ) + + SET_SOURCE_FILES_PROPERTIES(${_cxxtest_real_outfname} PROPERTIES GENERATED true) + ADD_EXECUTABLE(${_cxxtest_testname} ${_cxxtest_real_outfname}) + + IF(CMAKE_RUNTIME_OUTPUT_DIRECTORY) + # The test binary is in 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(CMAKE_RUNTIME_OUTPUT_DIRECTORY) + ADD_TEST(${_cxxtest_testname} ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_testname}) + + ENDIF(CMAKE_RUNTIME_OUTPUT_DIRECTORY) + +ENDMACRO(CXXTEST_ADD_TEST) + +#========= +# main +#========= + +FIND_PATH(CXXTEST_INCLUDE_DIR cxxtest/SelfTest.h) +FIND_PROGRAM(CXXTEST_PERL_TESTGEN_EXECUTABLE cxxtestgen.pl) +FIND_PROGRAM(CXXTEST_PYTHON_TESTGEN_EXECUTABLE cxxtestgen.py) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(CxxTest DEFAULT_MSG CXXTEST_INCLUDE_DIR) +IF(CXXTEST_INCLUDE_DIR) + SET(CXXTEST_INCLUDE_DIRS ${CXXTEST_INCLUDE_DIR}) + SET(CXXTEST_FOUND true) +ENDIF(CXXTEST_INCLUDE_DIR) + |