[CMake] Extension proposal: CheckFortranFuinctionExists.cmake

Hauke Heibel heibel at cs.tum.edu
Wed Jun 25 09:15:56 EDT 2008


Hi there,

I started diving into the world of CMake and spend the last two days in 
trying to convert a project of mine to be working with CMake.

We are using BLAS in the project, so obviously I gave FIND_PACKAGE(BLAS) 
a shot. In the beginning it was not really working, but I found a 
workaround which I would like to discuss - maybe it will be useful for 
others as well.

So here is the scenario. I am given a machine having only access to 
static pre-compiled libraries of BLAS (in my case atlas.lib, cblas.lib 
and f77blas.lib). It would be great if the FIND_PACKAGE script would 
allow me to use these libraries even when I do not have a Fortran 
compiler at hand. Why should I need it anyways - the libs are pre-compiled.

So in the first step I managed to get FindBLAS.cmake running that far, 
that it finds the libs but as said before, it was failing due to the 
missing Fortran compiler. To resolve this final issue I did the following.

Since Fortran compiled libraries can be used from C/C++, why not simply 
create a test based on a .cpp file. I gave it a try and it seems to work:

CheckFortranFunctionExists.cmake (I cut things short here)

IF(_LANGUAGES_ MATCHES Fortran)
  #
ELSE(_LANGUAGES_ MATCHES Fortran)
  FILE(WRITE
    
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.cpp
    "
    extern \"C\" void ${FUNCTION}();
    int main(int argc, char* argv[])
    {
      ${FUNCTION}(); // force linking
      return 0;
    }
    "
  )
  try_compile(${VARIABLE}
    ${CMAKE_BINARY_DIR}
    
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.cpp
    CMAKE_FLAGS "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}"
    OUTPUT_VARIABLE OUTPUT
  )
ENDIF(_LANGUAGES_ MATCHES Fortran)

Unless I did not get something seriously wrong with the idea of testing, 
the proposed method should work. If anybody is interested, I could 
create a CVS patch and submit it as a feature request to Mantis.

Regards,
Hauke

-- 
Tim Hauke Heibel
Computer Aided Medical Procedures (CAMP)
fon: +49 89 289 19427
fax: +49 89 289 17059



More information about the CMake mailing list