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