Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Modules / FindCxxTest.cmake
blob8964bc60599006a7cb31b172309e52b89e13941f
1 # - Find CxxTest
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
6 # INPUT Variables
8 #   CXXTEST_USE_PYTHON
9 #       If true, the CXXTEST_ADD_TEST macro will use
10 #       the Python test generator instead of Perl.
12 # OUTPUT Variables
14 #   CXXTEST_FOUND
15 #       True if the CxxTest framework was found
16 #   CXXTEST_INCLUDE_DIR
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
27 #       Parameters:
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
32 #           
33 #       #==============
34 #       Example Usage:
36 #           find_package(CxxTest)
37 #           if(CXXTEST_FOUND)
38 #               include_directories(${CXXTEST_INCLUDE_DIR})
39 #               enable_testing()
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
44 #           endif()
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.
50 #               
51 #      #=============
52 #      Example foo_test.h:
54 #          #include <cxxtest/TestSuite.h>
55 #          
56 #          class MyTestSuite : public CxxTest::TestSuite 
57 #          {
58 #          public:
59 #             void testAddition( void )
60 #             {
61 #                TS_ASSERT( 1 + 1 > 1 );
62 #                TS_ASSERT_EQUALS( 1 + 1, 2 );
63 #             }
64 #          };
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
79 # FindCxxTest.cmake
80 # Copyright (c) 2008-2009
81 #     Philip Lowman <philip@yhbt.com>
83 #  Redistribution AND use is allowed according to the terms of the New
84 #  BSD license.
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})
94     else()
95         set(_cxxtest_executable ${CXXTEST_PERL_TESTGEN_EXECUTABLE})
96     endif()
98     add_custom_command(
99         OUTPUT  ${_cxxtest_real_outfname}
100         DEPENDS ${ARGN}
101         COMMAND ${_cxxtest_executable}
102         --error-printer -o ${_cxxtest_real_outfname} ${ARGN}
103     )
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})
112     else()
113         add_test(${_cxxtest_testname} ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_testname})
114     endif()
116 endmacro(CXXTEST_ADD_TEST)
118 #=============================================================
119 # main()
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})