I am trying to use the LLVM dragonegg plugin for GCC in a project, which is built using CMake. However I have a hard time figuring out how to tell CMake, what it should do. Dragonegg is a plugin, which makes GCC use part of the LLVM infrastructure to optimize the compiled code. In my case, I am trying to compile some Fortran files with GCC using this plugin, postprocess the emitted LLVM code and link the result into a library.
Here is what I currently do: SET(LL_FILES) SEPARATE_ARGUMENTS(DRAGONEGG_OPTIONS UNIX_COMMAND "${CMAKE_Fortran_FLAGS} -I ${CMAKE_CURRENT_SOURCE_DIR}/ins -S -fplugin=dragonegg.so -fplugin-arg-dragonegg-emit-ir") FOREACH(File ${Src}) GET_FILENAME_COMPONENT(Filename ${File} NAME_WE) SET (LL_FILES ${LL_FILES} ${CMAKE_CURRENT_BINARY_DIR}/${Filename}.ll) ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${Filename}.ll COMMAND ${CMAKE_Fortran_COMPILER} ${DRAGONEGG_OPTIONS} -o ${CMAKE_CURRENT_BINARY_DIR}/${Filename}.ll ${File} DEPENDS ${File}) ENDFOREACH() ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/form.ll COMMAND llvm-link -S -o ${CMAKE_CURRENT_BINARY_DIR}/form.ll ${LL_FILES} DEPENDS ${LL_FILES}) ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/form.opt.ll COMMAND opt -o ${CMAKE_CURRENT_BINARY_DIR}/form.opt.ll ${CMAKE_CURRENT_BINARY_DIR}/form.ll DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/form.ll) ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/form.opt.o COMMAND llc -o ${CMAKE_CURRENT_BINARY_DIR}/form.S ${CMAKE_CURRENT_BINARY_DIR}/form.opt.ll COMMAND as -o ${CMAKE_CURRENT_BINARY_DIR}/form.opt.o ${CMAKE_CURRENT_BINARY_DIR}/form.S DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/form.opt.ll) ADD_LIBRARY(form_ce STATIC ${CMAKE_CURRENT_BINARY_DIR}/form.opt.o) SET_TARGET_PROPERTIES(form_ce PROPERTIES LINKER_LANGUAGE Fortran) Unfortunately calling the Fortran compiler this way looses the dependency scanning, which is important for Fortran module access. I tried using IMPLICIT_DEPENDS on the first custom command, but the documentation says, that it only works for C and CXX. I also thought about directly putting the dragonegg options into CMAKE_Fortran_FLAGS and use ADD_LIBRARY, but this won't work as well, because the files output by the dragonegg plugin are LLVM source files, which have to be explicitly run through the code generator to turn them into normal object files. Any ideas how to solve this? Martin -- 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