CMakeLists.txt 4.9 KB

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