소스 검색

Merge topic 'FindCxxTest_11041'

ed78a72 11041: Improve FindCxxTest to use Python or Perl automatically; custom flags
Brad King 15 년 전
부모
커밋
4262c29d14
1개의 변경된 파일79개의 추가작업 그리고 23개의 파일을 삭제
  1. 79 23
      Modules/FindCxxTest.cmake

+ 79 - 23
Modules/FindCxxTest.cmake

@@ -5,20 +5,37 @@
 #
 #
 # INPUT Variables
 # INPUT Variables
 #
 #
-#   CXXTEST_USE_PYTHON
-#       If true, the CXXTEST_ADD_TEST macro will use
-#       the Python test generator instead of Perl.
+#   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.
+#
+#       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.
 #
 #
 # OUTPUT Variables
 # OUTPUT Variables
 #
 #
 #   CXXTEST_FOUND
 #   CXXTEST_FOUND
 #       True if the CxxTest framework was found
 #       True if the CxxTest framework was found
-#   CXXTEST_INCLUDE_DIR
+#   CXXTEST_INCLUDE_DIRS
 #       Where to find the CxxTest include directory
 #       Where to find the CxxTest include directory
 #   CXXTEST_PERL_TESTGEN_EXECUTABLE
 #   CXXTEST_PERL_TESTGEN_EXECUTABLE
-#       The perl-based test generator.
+#       The perl-based test generator
 #   CXXTEST_PYTHON_TESTGEN_EXECUTABLE
 #   CXXTEST_PYTHON_TESTGEN_EXECUTABLE
-#       The python-based test generator.
+#       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)
+#       The full path to the Perl or Python executable on the system
 #
 #
 # MACROS for optional use by CMake users:
 # MACROS for optional use by CMake users:
 #
 #
@@ -26,9 +43,11 @@
 #       Creates a CxxTest runner and adds it to the CTest testing suite
 #       Creates a CxxTest runner and adds it to the CTest testing suite
 #       Parameters:
 #       Parameters:
 #           test_name               The name of the test
 #           test_name               The name of the test
-#           gen_source_file         The generated source filename to be generated by CxxTest
+#           gen_source_file         The generated source filename to be
+#                                   generated by CxxTest
 #           input_files_to_testgen  The list of header files containing the
 #           input_files_to_testgen  The list of header files containing the
-#                                   CxxTest::TestSuite's to be included in this runner
+#                                   CxxTest::TestSuite's to be included in
+#                                   this runner
 #           
 #           
 #       #==============
 #       #==============
 #       Example Usage:
 #       Example Usage:
@@ -65,8 +84,8 @@
 #
 #
 
 
 #=============================================================================
 #=============================================================================
-# Copyright 2008-2009 Kitware, Inc.
-# Copyright 2008-2009 Philip Lowman <[email protected]>
+# Copyright 2008-2010 Kitware, Inc.
+# Copyright 2008-2010 Philip Lowman <[email protected]>
 #
 #
 # Distributed under the OSI-approved BSD License (the "License");
 # Distributed under the OSI-approved BSD License (the "License");
 # see accompanying file Copyright.txt for details.
 # see accompanying file Copyright.txt for details.
@@ -78,6 +97,14 @@
 # (To distribute this file outside of CMake, substitute the full
 # (To distribute this file outside of CMake, substitute the full
 #  License text for the above reference.)
 #  License text for the above reference.)
 
 
+# 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.
 # Version 1.2 (3/2/08)
 # Version 1.2 (3/2/08)
 #     Included patch from Tyler Roscoe to have the perl & python binaries
 #     Included patch from Tyler Roscoe to have the perl & python binaries
 #     detected based on CXXTEST_INCLUDE_DIR
 #     detected based on CXXTEST_INCLUDE_DIR
@@ -95,17 +122,12 @@
 #=============================================================
 #=============================================================
 macro(CXXTEST_ADD_TEST _cxxtest_testname _cxxtest_outfname)
 macro(CXXTEST_ADD_TEST _cxxtest_testname _cxxtest_outfname)
     set(_cxxtest_real_outfname ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_outfname})
     set(_cxxtest_real_outfname ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_outfname})
-    if(CXXTEST_USE_PYTHON)
-        set(_cxxtest_executable ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE})
-    else()
-        set(_cxxtest_executable ${CXXTEST_PERL_TESTGEN_EXECUTABLE})
-    endif()
 
 
     add_custom_command(
     add_custom_command(
         OUTPUT  ${_cxxtest_real_outfname}
         OUTPUT  ${_cxxtest_real_outfname}
         DEPENDS ${ARGN}
         DEPENDS ${ARGN}
-        COMMAND ${_cxxtest_executable}
-        --error-printer -o ${_cxxtest_real_outfname} ${ARGN}
+        COMMAND ${CXXTEST_TESTGEN_INTERPRETER}
+        ${CXXTEST_TESTGEN_EXECUTABLE} ${CXXTEST_TESTGEN_ARGS} -o ${_cxxtest_real_outfname} ${ARGN}
     )
     )
 
 
     set_source_files_properties(${_cxxtest_real_outfname} PROPERTIES GENERATED true)
     set_source_files_properties(${_cxxtest_real_outfname} PROPERTIES GENERATED true)
@@ -124,14 +146,48 @@ endmacro(CXXTEST_ADD_TEST)
 #=============================================================
 #=============================================================
 # main()
 # main()
 #=============================================================
 #=============================================================
+if(NOT DEFINED CXXTEST_TESTGEN_ARGS)
+   set(CXXTEST_TESTGEN_ARGS --error-printer)
+endif()
+
+find_package(PythonInterp QUIET)
+find_package(Perl QUIET)
 
 
 find_path(CXXTEST_INCLUDE_DIR cxxtest/TestSuite.h)
 find_path(CXXTEST_INCLUDE_DIR cxxtest/TestSuite.h)
-find_program(CXXTEST_PERL_TESTGEN_EXECUTABLE cxxtestgen.pl
-    PATHS ${CXXTEST_INCLUDE_DIR})
 find_program(CXXTEST_PYTHON_TESTGEN_EXECUTABLE cxxtestgen.py
 find_program(CXXTEST_PYTHON_TESTGEN_EXECUTABLE cxxtestgen.py
-    PATHS ${CXXTEST_INCLUDE_DIR})
+         PATHS ${CXXTEST_INCLUDE_DIR})
+find_program(CXXTEST_PERL_TESTGEN_EXECUTABLE cxxtestgen.pl
+         PATHS ${CXXTEST_INCLUDE_DIR})
+
+if(PYTHONINTERP_FOUND OR PERL_FOUND)
+   include(FindPackageHandleStandardArgs)
+
+   if(PYTHONINTERP_FOUND AND (CXXTEST_USE_PYTHON OR NOT PERL_FOUND))
+      set(CXXTEST_TESTGEN_EXECUTABLE ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE})
+      set(CXXTEST_TESTGEN_INTERPRETER ${PYTHON_EXECUTABLE})
+      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()
 
 
-include(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(CxxTest DEFAULT_MSG CXXTEST_INCLUDE_DIR)
+   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()
 
 
-set(CXXTEST_INCLUDE_DIRS ${CXXTEST_INCLUDE_DIR})
+endif()