Re: [CMake] linking main Fortran and C++
On Thu, Oct 21, 2010 at 16:52, M. Scot Breitenfeld brtn...@uiuc.edu wrote: It was part of a section detecting if mpi is present, if it is then it uses the mpi** compiler wrappers instead: IF ( MPI_FOUND ) SET (CMAKE_Fortran_COMPILER mpif90) SET (CMAKE_CC_COMPILER mpicc) This is a typo, should be CMAKE_C_COMPILER. SET (CMAKE_CXX_COMPILER mpicxx) ENDIF() This approach is horribly non-portable, many systems do not have wrapper compilers or they have different names. An easy solution is for the user to set CMAKE_C_COMPILER themselves, as in cmake -DCMAKE_C_COMPILER=/path/to/mpicc. You can also use FindMPI.cmake (which needs love, it's broken in many batch environments) to determine the flags needed to compile and link using the unwrapped compiler. Jed ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] linking main Fortran and C++
I know you're simplifying to provide an example, but I hope you don't normally set CMAKE_CC_COMPILER, CMAKE_Fortran_COMPILER and CMAKE_CXX_COMPILER in your CMakeLists.txt. That's precisely the sort of thing that CMake is meant to find for you. It will find the compilers needed to compile your source, and then you can override CMake's default choice if you want to. On Mon, Oct 18, 2010 at 11:35 PM, Michael Scot Breitenfeld brtn...@uiuc.edu wrote: Thanks, this works now: PROJECT( Test) SET(PACKAGE_NAME TEST) CMAKE_MINIMUM_REQUIRED (VERSION 2.6) SET (CMAKE_Fortran_COMPILER gfortran) SET (CMAKE_CC_COMPILER gcc) SET (CMAKE_CXX_COMPILER g++) # libraries are all shared by default option(BUILD_SHARED_LIBS Build shared libraries OFF) ENABLE_LANGUAGE(Fortran) SET(F_OBJ submain.f90) SET(C_OBJ test.cpp) ADD_LIBRARY (name STATIC ${F_OBJ} ${C_OBJ}) SET_TARGET_PROPERTIES(name PROPERTIES LINKER_LANGUAGE Fortran) ADD_EXECUTABLE(a.out main.f90) SET_TARGET_PROPERTIES(a.out PROPERTIES LINKER_LANGUAGE Fortran) TARGET_LINK_LIBRARIES(a.out name) OUTPUT: Scanning dependencies of target name [ 33%] Building Fortran object CMakeFiles/name.dir/submain.f90.o [ 66%] Building CXX object CMakeFiles/name.dir/test.cpp.o Linking Fortran static library libname.a [ 66%] Built target name Scanning dependencies of target a.out [100%] Building Fortran object CMakeFiles/a.out.dir/main.f90.o Linking Fortran executable a.out [100%] Built target a.out Added bonus is it links -lstdc++ automatically. On 10/18/2010 10:30 PM, Michael Hertling wrote: On 10/19/2010 03:43 AM, Michael Scot Breitenfeld wrote: My main program is in Fortran and I have couple of files that are in C++. When I try to make the library, CMake uses CXX linking (archiving) to make the library. Which I guess is ok, but then when it links the main program it thinks that it is a CXX executable and uses the C++ compiler and not the Fortran compiler so compilation fails. How do I tell cmake to use fortran instead, I thought it would automatically do this from the .f90 suffix. I'm using cmake 2.8.1. Set the LINKER_LANGUAGE property of your main program target to Fortran, and see the CMAKE_LANG_LINKER_PREFERENCE and CMAKE_LANG_LINKER_PREFERENCE_PROPAGATES variables for more information. Regards, Michael My test: PROJECT( Test ) SET(PACKAGE_NAME TEST) CMAKE_MINIMUM_REQUIRED (VERSION 2.6) SET (CMAKE_Fortran_COMPILER gfortran) SET (CMAKE_CC_COMPILER gcc) SET (CMAKE_CXX_COMPILER g++) # libraries are all shared by default option(BUILD_SHARED_LIBS Build shared libraries OFF) ENABLE_LANGUAGE(Fortran) SET(F_OBJ submain.f90) SET(C_OBJ test.cpp) ADD_LIBRARY (name STATIC ${F_OBJ} ${C_OBJ}) ADD_EXECUTABLE(a.out main.f90) TARGET_LINK_LIBRARIES(a.out name) ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] linking main Fortran and C++
On 10/19/2010 03:43 AM, Michael Scot Breitenfeld wrote: My main program is in Fortran and I have couple of files that are in C++. When I try to make the library, CMake uses CXX linking (archiving) to make the library. Which I guess is ok, but then when it links the main program it thinks that it is a CXX executable and uses the C++ compiler and not the Fortran compiler so compilation fails. How do I tell cmake to use fortran instead, I thought it would automatically do this from the .f90 suffix. I'm using cmake 2.8.1. Set the LINKER_LANGUAGE property of your main program target to Fortran, and see the CMAKE_LANG_LINKER_PREFERENCE and CMAKE_LANG_LINKER_PREFERENCE_PROPAGATES variables for more information. Regards, Michael My test: PROJECT( Test ) SET(PACKAGE_NAME TEST) CMAKE_MINIMUM_REQUIRED (VERSION 2.6) SET (CMAKE_Fortran_COMPILER gfortran) SET (CMAKE_CC_COMPILER gcc) SET (CMAKE_CXX_COMPILER g++) # libraries are all shared by default option(BUILD_SHARED_LIBS Build shared libraries OFF) ENABLE_LANGUAGE(Fortran) SET(F_OBJ submain.f90) SET(C_OBJ test.cpp) ADD_LIBRARY (name STATIC ${F_OBJ} ${C_OBJ}) ADD_EXECUTABLE(a.out main.f90) TARGET_LINK_LIBRARIES(a.out name) ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] linking main Fortran and C++
Thanks, this works now: PROJECT( Test) SET(PACKAGE_NAME TEST) CMAKE_MINIMUM_REQUIRED (VERSION 2.6) SET (CMAKE_Fortran_COMPILER gfortran) SET (CMAKE_CC_COMPILER gcc) SET (CMAKE_CXX_COMPILER g++) # libraries are all shared by default option(BUILD_SHARED_LIBS Build shared libraries OFF) ENABLE_LANGUAGE(Fortran) SET(F_OBJ submain.f90) SET(C_OBJ test.cpp) ADD_LIBRARY (name STATIC ${F_OBJ} ${C_OBJ}) SET_TARGET_PROPERTIES(name PROPERTIES LINKER_LANGUAGE Fortran) ADD_EXECUTABLE(a.out main.f90) SET_TARGET_PROPERTIES(a.out PROPERTIES LINKER_LANGUAGE Fortran) TARGET_LINK_LIBRARIES(a.out name) OUTPUT: Scanning dependencies of target name [ 33%] Building Fortran object CMakeFiles/name.dir/submain.f90.o [ 66%] Building CXX object CMakeFiles/name.dir/test.cpp.o Linking Fortran static library libname.a [ 66%] Built target name Scanning dependencies of target a.out [100%] Building Fortran object CMakeFiles/a.out.dir/main.f90.o Linking Fortran executable a.out [100%] Built target a.out Added bonus is it links -lstdc++ automatically. On 10/18/2010 10:30 PM, Michael Hertling wrote: On 10/19/2010 03:43 AM, Michael Scot Breitenfeld wrote: My main program is in Fortran and I have couple of files that are in C++. When I try to make the library, CMake uses CXX linking (archiving) to make the library. Which I guess is ok, but then when it links the main program it thinks that it is a CXX executable and uses the C++ compiler and not the Fortran compiler so compilation fails. How do I tell cmake to use fortran instead, I thought it would automatically do this from the .f90 suffix. I'm using cmake 2.8.1. Set the LINKER_LANGUAGE property of your main program target to Fortran, and see the CMAKE_LANG_LINKER_PREFERENCE and CMAKE_LANG_LINKER_PREFERENCE_PROPAGATES variables for more information. Regards, Michael My test: PROJECT( Test ) SET(PACKAGE_NAME TEST) CMAKE_MINIMUM_REQUIRED (VERSION 2.6) SET (CMAKE_Fortran_COMPILER gfortran) SET (CMAKE_CC_COMPILER gcc) SET (CMAKE_CXX_COMPILER g++) # libraries are all shared by default option(BUILD_SHARED_LIBS Build shared libraries OFF) ENABLE_LANGUAGE(Fortran) SET(F_OBJ submain.f90) SET(C_OBJ test.cpp) ADD_LIBRARY (name STATIC ${F_OBJ} ${C_OBJ}) ADD_EXECUTABLE(a.out main.f90) TARGET_LINK_LIBRARIES(a.out name) ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake