[CMake] Fortran+CXX project with CMake 2.2.2
Karl Merkley
karl at elemtech.com
Thu Nov 10 10:41:46 EST 2005
>> I am running the Darwin 2.2.2 version downloaded from www.cmake.org.
>>
>> I have a simple CMakeLists.txt where I want to combine C++ and
>> FORTRAN.
>>
>> PROJECT(add_fortran FORTRAN)
>> ADD_EXECUTABLE(add_fortran main.cpp testf1.f)
>>
>> When I execute cmake I get the following errors.
>>
>> . . .
>> "/Users/kgmerk/projects/cmake_fortran/build/CMakeTmp/
>> testFortranCompiler.f". TRY_COMPILE only works for enabled
>> languages.
>> Currently enabled languages are: FORTRAN
>> See PROJECT command for help enabling other languages.
>> -- Check for working Fortran compiler: g77 -- broken
>> The Fortran compiler "g77" is not able to compile a simple test
>> program.
>> It fails with the following output:
>>
On Nov 9, 2005, at 7:00 PM, William A. Hoffman wrote:
> It should be :
>
> PROJECT(add_fortran Fortran)
>
Just for archival purposes, here is the CMakeLists.txt that actually
works. I also added a test to make sure both .f and .F extensions were
handled correctly.
# The project must specify all languages that are being used in the
project
PROJECT(add_fortran CXX Fortran)
ADD_EXECUTABLE(add_fortran main.cpp testf1.F testf2.f)
# You must which linker to use for a multiple language project
SET_TARGET_PROPERTIES(add_fortran PROPERTIES LINKER_LANGUAGE CXX)
# You need to find and link with libg2c (I _think_ this applies only if
you are using g77)
FIND_PATH(G2C_DIR libg2c.a /opt/local/lib)
LINK_DIRECTORIES(${G2C_DIR})
TARGET_LINK_LIBRARIES(add_fortran g2c)
More information about the CMake
mailing list