FindCxxTest.cmake 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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
  5. #
  6. # INPUT Variables
  7. #
  8. # CXXTEST_USE_PYTHON
  9. # If true, the CXXTEST_ADD_TEST macro will use
  10. # the Python test generator instead of Perl.
  11. #
  12. # OUTPUT Variables
  13. #
  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.
  22. #
  23. # MACROS for optional use by CMake users:
  24. #
  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:
  35. #
  36. # find_package(CxxTest)
  37. # if(CXXTEST_FOUND)
  38. # include_directories(${CXXTEST_INCLUDE_DIR})
  39. # enable_testing()
  40. #
  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()
  45. #
  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:
  53. #
  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. # };
  65. #
  66. #=============================================================================
  67. # Copyright 2008-2009 Kitware, Inc.
  68. # Copyright 2008-2009 Philip Lowman <[email protected]>
  69. #
  70. # Distributed under the OSI-approved BSD License (the "License");
  71. # see accompanying file Copyright.txt for details.
  72. #
  73. # This software is distributed WITHOUT ANY WARRANTY; without even the
  74. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  75. # See the License for more information.
  76. #=============================================================================
  77. # (To distributed this file outside of CMake, substitute the full
  78. # License text for the above reference.)
  79. # Version 1.2 (3/2/08)
  80. # Included patch from Tyler Roscoe to have the perl & python binaries
  81. # detected based on CXXTEST_INCLUDE_DIR
  82. # Version 1.1 (2/9/08)
  83. # Clarified example to illustrate need to call target_link_libraries()
  84. # Changed commands to lowercase
  85. # Added licensing info
  86. # Version 1.0 (1/8/08)
  87. # Fixed CXXTEST_INCLUDE_DIRS so it will work properly
  88. # Eliminated superfluous CXXTEST_FOUND assignment
  89. # Cleaned up and added more documentation
  90. #=============================================================
  91. # CXXTEST_ADD_TEST (public macro)
  92. #=============================================================
  93. macro(CXXTEST_ADD_TEST _cxxtest_testname _cxxtest_outfname)
  94. set(_cxxtest_real_outfname ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_outfname})
  95. if(CXXTEST_USE_PYTHON)
  96. set(_cxxtest_executable ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE})
  97. else()
  98. set(_cxxtest_executable ${CXXTEST_PERL_TESTGEN_EXECUTABLE})
  99. endif()
  100. add_custom_command(
  101. OUTPUT ${_cxxtest_real_outfname}
  102. DEPENDS ${ARGN}
  103. COMMAND ${_cxxtest_executable}
  104. --error-printer -o ${_cxxtest_real_outfname} ${ARGN}
  105. )
  106. set_source_files_properties(${_cxxtest_real_outfname} PROPERTIES GENERATED true)
  107. 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()
  115. endmacro(CXXTEST_ADD_TEST)
  116. #=============================================================
  117. # main()
  118. #=============================================================
  119. find_path(CXXTEST_INCLUDE_DIR cxxtest/TestSuite.h)
  120. find_program(CXXTEST_PERL_TESTGEN_EXECUTABLE cxxtestgen.pl
  121. PATHS ${CXXTEST_INCLUDE_DIR})
  122. find_program(CXXTEST_PYTHON_TESTGEN_EXECUTABLE cxxtestgen.py
  123. PATHS ${CXXTEST_INCLUDE_DIR})
  124. include(FindPackageHandleStandardArgs)
  125. FIND_PACKAGE_HANDLE_STANDARD_ARGS(CxxTest DEFAULT_MSG CXXTEST_INCLUDE_DIR)
  126. set(CXXTEST_INCLUDE_DIRS ${CXXTEST_INCLUDE_DIR})