CMakeLists.txt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. cmake_minimum_required (VERSION 2.8)
  2. project(FortranOnly Fortran)
  3. message("CTEST_FULL_OUTPUT ")
  4. # create a library with hello and world functions
  5. add_library(FortranOnlylib hello.f world.f)
  6. # create an executable that calls hello and world
  7. add_executable(FortranOnly testf.f)
  8. target_link_libraries(FortranOnly FortranOnlylib)
  9. # create a custom command that runs FortranOnly and puts
  10. # the output into the file testfhello.txt
  11. add_custom_command(OUTPUT ${FortranOnly_BINARY_DIR}/testfhello.txt
  12. COMMAND ${FortranOnly_BINARY_DIR}/${CMAKE_CFG_INTDIR}/FortranOnly
  13. > testfhello.txt)
  14. # create a second executable FortranOnly2 that has
  15. # testfhello.txt has an source file so that it will
  16. # run the above custom command.
  17. add_executable(FortranOnly2 testfhello.txt testf.f)
  18. target_link_libraries(FortranOnly2 FortranOnlylib)
  19. # create a custom target to check the content of testfhello.txt
  20. # by running the cmake script checktestf2.cmake
  21. add_custom_target(checktestf2 ALL
  22. COMMAND ${CMAKE_COMMAND}
  23. -P ${FortranOnly_SOURCE_DIR}/checktestf2.cmake)
  24. # create a custom target that runs FortranOnly exectuable and creates
  25. # a file out.txt that should have hello world in it.
  26. add_custom_target(sayhello ALL
  27. COMMAND ${FortranOnly_BINARY_DIR}/${CMAKE_CFG_INTDIR}/FortranOnly > out.txt
  28. )
  29. # make sure stuff is built in the right order
  30. add_dependencies(checktestf2 FortranOnly2)
  31. add_dependencies(sayhello FortranOnly)
  32. add_dependencies(FortranOnly2 FortranOnly)
  33. # add a custom target that checkes that out.txt has the correct
  34. # content
  35. add_custom_target(checksayhello ALL
  36. COMMAND ${CMAKE_COMMAND} -P ${FortranOnly_SOURCE_DIR}/checksayhello.cmake
  37. )
  38. add_dependencies(checksayhello sayhello)