CMakeLists.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. cmake_minimum_required (VERSION 3.9)
  2. project(FortranModules Fortran)
  3. if(NOT DEFINED CMake_TEST_NESTED_MAKE_PROGRAM AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
  4. set(CMake_TEST_NESTED_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}")
  5. endif()
  6. if("x${CMake_TEST_Fortran_SUBMODULES}" STREQUAL "x"
  7. AND NOT CMAKE_VERSION VERSION_LESS 3.6.20160923 # for CheckFortranSourceCompiles SRC_EXT
  8. )
  9. include(CheckFortranSourceCompiles)
  10. CHECK_Fortran_SOURCE_COMPILES([[
  11. module parent
  12. interface
  13. module function id(x)
  14. real, intent(in) :: x
  15. real :: id
  16. end function id
  17. end interface
  18. end module parent
  19. submodule ( parent ) child
  20. contains
  21. module procedure id
  22. f = x
  23. end procedure id
  24. end submodule child
  25. program main
  26. end program
  27. ]] HAVE_SUBMODULES SRC_EXT F90)
  28. set(CMake_TEST_Fortran_SUBMODULES ${HAVE_SUBMODULES})
  29. elseif(CMake_TEST_Fortran_SUBMODULES)
  30. message(STATUS "Enabling Fortran submodule tests by explicit request.")
  31. endif()
  32. add_executable(test_module
  33. test_module_main.f90
  34. test_module_implementation.f90
  35. test_module_interface.f90)
  36. add_executable(test_use_in_comment_fixedform
  37. test_use_in_comment_fixedform.f)
  38. set_property(SOURCE test_use_in_comment_fixedform.f PROPERTY Fortran_FORMAT FIXED)
  39. add_executable(test_use_in_comment_freeform
  40. test_use_in_comment_freeform.f90)
  41. set_property(SOURCE test_use_in_comment_freeform.f90 PROPERTY Fortran_FORMAT FREE)
  42. add_executable(test_in_interface
  43. in_interface/main.f90
  44. in_interface/module.f90)
  45. add_definitions(-DFOO -DBAR=1)
  46. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
  47. add_executable(test_preprocess test_preprocess.F90 test_preprocess_module.F90)
  48. add_executable(test_non_pp_include test_non_pp_include_main.f90)
  49. # Build the external project separately using a custom target.
  50. # Make sure it uses the same build configuration as this test.
  51. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  52. if(_isMultiConfig)
  53. set(External_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
  54. set(External_BUILD_TYPE)
  55. else()
  56. set(External_CONFIG_TYPE)
  57. set(External_BUILD_TYPE -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE})
  58. endif()
  59. set(External_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/External")
  60. set(External_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/External")
  61. if("${CMAKE_CURRENT_BINARY_DIR}" MATCHES " ")
  62. # Our build tree has a space, so the build tool supports spaces.
  63. # Test using modules from a path with spaces.
  64. string(APPEND External_BINARY_DIR " Build")
  65. endif()
  66. add_custom_command(
  67. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ExternalProject
  68. COMMAND ${CMAKE_CTEST_COMMAND}
  69. ARGS ${External_CONFIG_TYPE}
  70. --build-and-test
  71. ${External_SOURCE_DIR}
  72. ${External_BINARY_DIR}
  73. --build-noclean
  74. --build-two-config
  75. --build-project ExtFort
  76. --build-generator ${CMAKE_GENERATOR}
  77. --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
  78. --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
  79. --build-options -DCMAKE_Fortran_COMPILER:STRING=${CMAKE_Fortran_COMPILER}
  80. -DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}
  81. -DCMAKE_Fortran_FLAGS_DEBUG:STRING=${CMAKE_Fortran_FLAGS_DEBUG}
  82. -DCMAKE_Fortran_FLAGS_RELEASE:STRING=${CMAKE_Fortran_FLAGS_RELEASE}
  83. -DCMAKE_Fortran_FLAGS_MINSIZEREL:STRING=${CMAKE_Fortran_FLAGS_MINSIZEREL}
  84. -DCMAKE_Fortran_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_Fortran_FLAGS_RELWITHDEBINFO}
  85. -DCMAKE_MAKE_PROGRAM:FILEPATH=${CMake_TEST_NESTED_MAKE_PROGRAM}
  86. ${External_BUILD_TYPE}
  87. VERBATIM
  88. )
  89. add_custom_target(ExternalTarget ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ExternalProject)
  90. # Test module output directory if available.
  91. if(CMAKE_Fortran_MODDIR_FLAG)
  92. set(Library_MODDIR "${CMAKE_CURRENT_BINARY_DIR}/Library/modules")
  93. else()
  94. set(Library_MODDIR "${CMAKE_CURRENT_BINARY_DIR}/Library")
  95. endif()
  96. add_subdirectory(Library)
  97. add_subdirectory(Subdir)
  98. add_subdirectory(Executable)
  99. if(CMake_TEST_Fortran_SUBMODULES)
  100. add_subdirectory(Submodules)
  101. endif()