CMakeLists.txt 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. cmake_minimum_required(VERSION 3.10)
  2. project(FortranModules Fortran)
  3. if("${CMAKE_Fortran_COMPILER_ID};${CMAKE_Fortran_SIMULATE_ID}" MATCHES "^Intel(LLVM)?;MSVC$")
  4. string(APPEND CMAKE_Fortran_FLAGS_DEBUG " -Z7")
  5. string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO " -Z7")
  6. endif()
  7. if(NOT DEFINED CMake_TEST_NESTED_MAKE_PROGRAM AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
  8. set(CMake_TEST_NESTED_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}")
  9. endif()
  10. if(NOT DEFINED CMake_TEST_Fortran_SUBMODULES AND (
  11. # FIXME(#18925): We do not support Cray's module file names.
  12. CMAKE_Fortran_COMPILER_ID STREQUAL "Cray"
  13. ))
  14. set(CMake_TEST_Fortran_SUBMODULES 0)
  15. endif()
  16. if(NOT DEFINED CMake_TEST_Fortran_SUBMODULES)
  17. include(CheckFortranSourceCompiles)
  18. check_fortran_source_compiles([[
  19. module parent
  20. interface
  21. module function id(x)
  22. real, intent(in) :: x
  23. real :: id
  24. end function id
  25. end interface
  26. end module parent
  27. submodule ( parent ) child
  28. contains
  29. module procedure id
  30. id = x
  31. end procedure id
  32. end submodule child
  33. program main
  34. end program
  35. ]] HAVE_SUBMODULES SRC_EXT F90)
  36. set(CMake_TEST_Fortran_SUBMODULES ${HAVE_SUBMODULES})
  37. elseif(CMake_TEST_Fortran_SUBMODULES)
  38. message(STATUS "Enabling Fortran submodule tests by explicit request.")
  39. endif()
  40. add_executable(test_module
  41. test_module_main.f90
  42. test_module_implementation.f90
  43. test_module_interface.f90)
  44. add_executable(test_multi_module
  45. # Place this first so that we do not get "lucky" and find the module provided
  46. # by compiling `test_multi_module.f90` first.
  47. test_multi_module_main.f90
  48. test_multi_module.f90)
  49. set_property(TARGET test_multi_module PROPERTY
  50. JOB_POOL_COMPILE multi_module_serial)
  51. set_property(GLOBAL APPEND PROPERTY
  52. JOB_POOLS multi_module_serial=1)
  53. add_executable(test_use_in_comment_fixedform
  54. test_use_in_comment_fixedform.f)
  55. set_property(SOURCE test_use_in_comment_fixedform.f PROPERTY Fortran_FORMAT FIXED)
  56. add_executable(test_use_in_comment_freeform
  57. test_use_in_comment_freeform.f90)
  58. set_property(SOURCE test_use_in_comment_freeform.f90 PROPERTY Fortran_FORMAT FREE)
  59. add_executable(test_in_interface
  60. in_interface/main.f90
  61. in_interface/module.f90)
  62. add_definitions(-DFOO -DBAR=1)
  63. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
  64. add_executable(test_preprocess test_preprocess.F90 test_preprocess_module.F90)
  65. add_executable(test_non_pp_include test_non_pp_include_main.f90 test_non_pp_include_module.f90)
  66. # Build the external project separately using a custom target.
  67. # Make sure it uses the same build configuration as this test.
  68. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  69. if(_isMultiConfig)
  70. set(External_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
  71. set(External_BUILD_TYPE)
  72. else()
  73. set(External_CONFIG_TYPE)
  74. set(External_BUILD_TYPE -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE})
  75. endif()
  76. set(External_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/External")
  77. set(External_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/External")
  78. if("${CMAKE_CURRENT_BINARY_DIR}" MATCHES " ")
  79. # Our build tree has a space, so the build tool supports spaces.
  80. # Test using modules from a path with spaces.
  81. string(APPEND External_BINARY_DIR " Build")
  82. endif()
  83. add_custom_command(
  84. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ExternalProject
  85. COMMAND ${CMAKE_CTEST_COMMAND}
  86. ARGS ${External_CONFIG_TYPE}
  87. --build-and-test
  88. ${External_SOURCE_DIR}
  89. ${External_BINARY_DIR}
  90. --build-noclean
  91. --build-two-config
  92. --build-project ExtFort
  93. --build-generator ${CMAKE_GENERATOR}
  94. --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
  95. --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
  96. --build-options -DCMAKE_Fortran_COMPILER:STRING=${CMAKE_Fortran_COMPILER}
  97. -DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}
  98. -DCMAKE_Fortran_FLAGS_DEBUG:STRING=${CMAKE_Fortran_FLAGS_DEBUG}
  99. -DCMAKE_Fortran_FLAGS_RELEASE:STRING=${CMAKE_Fortran_FLAGS_RELEASE}
  100. -DCMAKE_Fortran_FLAGS_MINSIZEREL:STRING=${CMAKE_Fortran_FLAGS_MINSIZEREL}
  101. -DCMAKE_Fortran_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_Fortran_FLAGS_RELWITHDEBINFO}
  102. -DCMAKE_MAKE_PROGRAM:FILEPATH=${CMake_TEST_NESTED_MAKE_PROGRAM}
  103. ${External_BUILD_TYPE}
  104. VERBATIM
  105. )
  106. add_custom_target(ExternalTarget ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ExternalProject)
  107. # Test module output directory if available.
  108. if(CMAKE_Fortran_MODDIR_FLAG)
  109. set(Library_MODDIR "${CMAKE_CURRENT_BINARY_DIR}/Library/modules")
  110. else()
  111. set(Library_MODDIR "${CMAKE_CURRENT_BINARY_DIR}/Library")
  112. endif()
  113. add_subdirectory(Library)
  114. add_subdirectory(Subdir)
  115. add_subdirectory(Executable)
  116. if(CMake_TEST_Fortran_SUBMODULES)
  117. add_subdirectory(Submodules)
  118. endif()
  119. add_subdirectory(Issue25112)
  120. add_subdirectory(Issue25223)
  121. if( # Intel Fortran VS Integration breaks on custom targets with Fortran sources
  122. NOT CMAKE_GENERATOR MATCHES "Visual Studio")
  123. add_subdirectory(Issue25252)
  124. add_subdirectory(Issue25252-iface-target)
  125. endif()
  126. add_subdirectory(Issue25252-iface-sources)
  127. add_subdirectory(Issue25365-target-objects)
  128. add_subdirectory(Issue25365-target-objects-iface)
  129. # Issue#25425
  130. add_subdirectory(ModulesViaTargetObjectsSource)
  131. add_subdirectory(ModulesViaSubdirTargetObjectsSource)
  132. add_subdirectory(ModulesViaTargetObjectsLink)
  133. add_subdirectory(ModulesViaSubdirTargetObjectsLink)