2 # Find the CxxTest suite and declare a helper macro for creating unit tests
3 # and integrating them with CTest.
4 # For more details on CxxTest see http://cxxtest.tigris.org
9 # If true, the CXXTEST_ADD_TEST macro will use
10 # the Python test generator instead of Perl.
15 # True if the CxxTest framework was found
17 # Where to find the CxxTest include directory
18 # CXXTEST_PERL_TESTGEN_EXECUTABLE
19 # The perl-based test generator.
20 # CXXTEST_PYTHON_TESTGEN_EXECUTABLE
21 # The python-based test generator.
23 # MACROS for optional use by CMake users:
25 # CXXTEST_ADD_TEST(<test_name> <gen_source_file> <input_files_to_testgen...>)
26 # Creates a CxxTest runner and adds it to the CTest testing suite
28 # test_name The name of the test
29 # gen_source_file The generated source filename to be generated by CxxTest
30 # input_files_to_testgen The list of header files containing the
31 # CxxTest::TestSuite's to be included in this runner
36 # find_package(CxxTest)
38 # include_directories(${CXXTEST_INCLUDE_DIR})
41 # CXXTEST_ADD_TEST(unittest_foo foo_test.cc
42 # ${CMAKE_CURRENT_SOURCE_DIR}/foo_test.h)
43 # target_link_libraries(unittest_foo foo) # as needed
46 # This will (if CxxTest is found):
47 # 1. Invoke the testgen executable to autogenerate foo_test.cc in the
48 # binary tree from "foo_test.h" in the current source directory.
49 # 2. Create an executable and test called unittest_foo.
54 # #include <cxxtest/TestSuite.h>
56 # class MyTestSuite : public CxxTest::TestSuite
59 # void testAddition( void )
61 # TS_ASSERT( 1 + 1 > 1 );
62 # TS_ASSERT_EQUALS( 1 + 1, 2 );
67 # Version 1.2 (3/2/08)
68 # Included patch from Tyler Roscoe to have the perl & python binaries
69 # detected based on CXXTEST_INCLUDE_DIR
70 # Version 1.1 (2/9/08)
71 # Clarified example to illustrate need to call target_link_libraries()
72 # Changed commands to lowercase
73 # Added licensing info
74 # Version 1.0 (1/8/08)
75 # Fixed CXXTEST_INCLUDE_DIRS so it will work properly
76 # Eliminated superfluous CXXTEST_FOUND assignment
77 # Cleaned up and added more documentation
80 # Copyright (c) 2008-2009
81 # Philip Lowman <philip@yhbt.com>
83 # Redistribution AND use is allowed according to the terms of the New
85 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
87 #=============================================================
88 # CXXTEST_ADD_TEST (public macro)
89 #=============================================================
90 macro(CXXTEST_ADD_TEST _cxxtest_testname _cxxtest_outfname)
91 set(_cxxtest_real_outfname ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_outfname})
92 if(CXXTEST_USE_PYTHON)
93 set(_cxxtest_executable ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE})
95 set(_cxxtest_executable ${CXXTEST_PERL_TESTGEN_EXECUTABLE})
99 OUTPUT ${_cxxtest_real_outfname}
101 COMMAND ${_cxxtest_executable}
102 --error-printer -o ${_cxxtest_real_outfname} ${ARGN}
105 set_source_files_properties(${_cxxtest_real_outfname} PROPERTIES GENERATED true)
106 add_executable(${_cxxtest_testname} ${_cxxtest_real_outfname})
108 if(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
109 add_test(${_cxxtest_testname} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_cxxtest_testname})
110 elseif(EXECUTABLE_OUTPUT_PATH)
111 add_test(${_cxxtest_testname} ${EXECUTABLE_OUTPUT_PATH}/${_cxxtest_testname})
113 add_test(${_cxxtest_testname} ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_testname})
116 endmacro(CXXTEST_ADD_TEST)
118 #=============================================================
120 #=============================================================
122 find_path(CXXTEST_INCLUDE_DIR cxxtest/TestSuite.h)
123 find_program(CXXTEST_PERL_TESTGEN_EXECUTABLE cxxtestgen.pl
124 PATHS ${CXXTEST_INCLUDE_DIR})
125 find_program(CXXTEST_PYTHON_TESTGEN_EXECUTABLE cxxtestgen.py
126 PATHS ${CXXTEST_INCLUDE_DIR})
128 include(FindPackageHandleStandardArgs)
129 FIND_PACKAGE_HANDLE_STANDARD_ARGS(CxxTest DEFAULT_MSG CXXTEST_INCLUDE_DIR)
131 set(CXXTEST_INCLUDE_DIRS ${CXXTEST_INCLUDE_DIR})