On Tue, Oct 22, 2013 at 7:45 PM, Bill Hoffman <bill.hoff...@kitware.com> wrote: > Hi, > > I have thought about CMake doing something automatically here, however, it > could get tricky pretty fast, and it is pretty easy to fix in the CMake file > of the project.
You'd have to detect whether the main function will be in the C part or if the Fortran part contains a PROGRAM subroutine to figure out which part becomes the lib, and which part the executable. You'd have to parse all files to find out. And then what should happen if CMake finds neither, or both? I agree that it's just as easy to sort this out by hand. The disadvantage of splitting the C and Fortran parts into two projects is that sometimes you are likely to get cyclic dependencies between the projects (when C code calls Fortran, and Fortran code calls C code) which can lead to link order issues on linux. You may therefore end up having to split the project into more libraries. which is another reason CMake will not easily be able to do this automatically. On the up side, having to remove the cyclic dependencies may lead to a better code structure, so there's that. > Your example would be: > enable_language(Fortran) > enable_language(C) > add_library(tst_lib_f tst.F) > add_executable(tst cfunc.c) > target_link_libraries(tst tst_lib_f) Actually, since the OP mentions that the main is in Fortran, the solution would be: add_library(tst_lib_c cfunc.c) add_executable(tst tst.F) target_link_libraries(tst tst_lib_c) -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake