You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.4 KiB

  1. # cmake/modules/language_support.cmake
  2. #
  3. # Temporary additional general language support is contained within this
  4. # file.
  5. # This additional function definition is needed to provide a workaround for
  6. # CMake bug 9220.
  7. # On debian testing (cmake 2.6.2), I get return code zero when calling
  8. # cmake the first time, but cmake crashes when running a second time
  9. # as follows:
  10. #
  11. # -- The Fortran compiler identification is unknown
  12. # CMake Error at /usr/share/cmake-2.6/Modules/CMakeFortranInformation.cmake:7 (GET_FILENAME_COMPONENT):
  13. # get_filename_component called with incorrect number of arguments
  14. # Call Stack (most recent call first):
  15. # CMakeLists.txt:3 (enable_language)
  16. #
  17. # My workaround is to invoke cmake twice. If both return codes are zero,
  18. # it is safe to invoke ENABLE_LANGUAGE(Fortran OPTIONAL)
  19. function(workaround_9220 language language_works)
  20. #message("DEBUG: language = ${language}")
  21. set(text
  22. "project(test NONE)
  23. cmake_minimum_required(VERSION 2.8.0)
  24. set (CMAKE_Fortran_FLAGS \"${CMAKE_Fortran_FLAGS}\")
  25. set (CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS}\")
  26. enable_language(${language} OPTIONAL)
  27. ")
  28. file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/language_tests/${language})
  29. file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/language_tests/${language})
  30. file(WRITE ${CMAKE_BINARY_DIR}/language_tests/${language}/CMakeLists.txt
  31. ${text})
  32. execute_process(
  33. COMMAND ${CMAKE_COMMAND} . -G "${CMAKE_GENERATOR}"
  34. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/language_tests/${language}
  35. RESULT_VARIABLE return_code
  36. OUTPUT_QUIET
  37. ERROR_QUIET
  38. )
  39. if(return_code EQUAL 0)
  40. # Second run
  41. execute_process (
  42. COMMAND ${CMAKE_COMMAND} . -G "${CMAKE_GENERATOR}"
  43. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/language_tests/${language}
  44. RESULT_VARIABLE return_code
  45. OUTPUT_QUIET
  46. ERROR_QUIET
  47. )
  48. if(return_code EQUAL 0)
  49. set(${language_works} ON PARENT_SCOPE)
  50. else(return_code EQUAL 0)
  51. set(${language_works} OFF PARENT_SCOPE)
  52. endif(return_code EQUAL 0)
  53. else(return_code EQUAL 0)
  54. set(${language_works} OFF PARENT_SCOPE)
  55. endif(return_code EQUAL 0)
  56. endfunction(workaround_9220)
  57. # Temporary tests of the above function.
  58. #workaround_9220(CXX CXX_language_works)
  59. #message("CXX_language_works = ${CXX_language_works}")
  60. #workaround_9220(CXXp CXXp_language_works)
  61. #message("CXXp_language_works = ${CXXp_language_works}")