diff options
author | Brad King <brad.king@kitware.com> | 2016-09-22 18:23:39 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-09-22 18:52:01 (GMT) |
commit | eb8cd35684f2dc2f53d205d7738e1c01a12a493f (patch) | |
tree | 77732180392bf2da1fe0aa6facd25c9fe95e6614 /Tests/FortranModules | |
parent | a41c8724d155f1cd74ce36cdfbd10da0eac5b389 (diff) | |
download | CMake-eb8cd35684f2dc2f53d205d7738e1c01a12a493f.zip CMake-eb8cd35684f2dc2f53d205d7738e1c01a12a493f.tar.gz CMake-eb8cd35684f2dc2f53d205d7738e1c01a12a493f.tar.bz2 |
Tests: Split Fortran module testing into separate FortranModules test
The main Fortran test is not granular enough. Split some into another
test.
Diffstat (limited to 'Tests/FortranModules')
21 files changed, 237 insertions, 0 deletions
diff --git a/Tests/FortranModules/CMakeLists.txt b/Tests/FortranModules/CMakeLists.txt new file mode 100644 index 0000000..b406df3 --- /dev/null +++ b/Tests/FortranModules/CMakeLists.txt @@ -0,0 +1,78 @@ +cmake_minimum_required (VERSION 3.1) +project(FortranModules Fortran) + +if(NOT DEFINED CMake_TEST_NESTED_MAKE_PROGRAM AND NOT CMAKE_GENERATOR MATCHES "Visual Studio") + set(CMake_TEST_NESTED_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}") +endif() + +add_executable(test_module + test_module_main.f90 + test_module_implementation.f90 + test_module_interface.f90) + +add_executable(test_use_in_comment_fixedform + test_use_in_comment_fixedform.f) +set_property(SOURCE test_use_in_comment_fixedform.f PROPERTY Fortran_FORMAT FIXED) +add_executable(test_use_in_comment_freeform + test_use_in_comment_freeform.f90) +set_property(SOURCE test_use_in_comment_freeform.f90 PROPERTY Fortran_FORMAT FREE) + +add_executable(test_in_interface + in_interface/main.f90 + in_interface/module.f90) + +add_definitions(-DFOO -DBAR=1) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) +add_executable(test_preprocess test_preprocess.F90 test_preprocess_module.F90) + +# Build the external project separately using a custom target. +# Make sure it uses the same build configuration as this test. +if(CMAKE_CONFIGURATION_TYPES) + set(External_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}") + set(External_BUILD_TYPE) +else() + set(External_CONFIG_TYPE) + set(External_BUILD_TYPE -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}) +endif() +set(External_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/External") +set(External_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/External") +if("${CMAKE_CURRENT_BINARY_DIR}" MATCHES " ") + # Our build tree has a space, so the build tool supports spaces. + # Test using modules from a path with spaces. + string(APPEND External_BINARY_DIR " Build") +endif() +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ExternalProject + COMMAND ${CMAKE_CTEST_COMMAND} + ARGS ${External_CONFIG_TYPE} + --build-and-test + ${External_SOURCE_DIR} + ${External_BINARY_DIR} + --build-noclean + --build-two-config + --build-project ExtFort + --build-generator ${CMAKE_GENERATOR} + --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}" + --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}" + --build-options -DCMAKE_Fortran_COMPILER:STRING=${CMAKE_Fortran_COMPILER} + -DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS} + -DCMAKE_Fortran_FLAGS_DEBUG:STRING=${CMAKE_Fortran_FLAGS_DEBUG} + -DCMAKE_Fortran_FLAGS_RELEASE:STRING=${CMAKE_Fortran_FLAGS_RELEASE} + -DCMAKE_Fortran_FLAGS_MINSIZEREL:STRING=${CMAKE_Fortran_FLAGS_MINSIZEREL} + -DCMAKE_Fortran_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_Fortran_FLAGS_RELWITHDEBINFO} + -DCMAKE_MAKE_PROGRAM:FILEPATH=${CMake_TEST_NESTED_MAKE_PROGRAM} + ${External_BUILD_TYPE} + VERBATIM + ) +add_custom_target(ExternalTarget ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ExternalProject) + +# Test module output directory if available. +if(CMAKE_Fortran_MODDIR_FLAG) + set(Library_MODDIR "${CMAKE_CURRENT_BINARY_DIR}/Library/modules") +else() + set(Library_MODDIR "${CMAKE_CURRENT_BINARY_DIR}/Library") +endif() + +add_subdirectory(Library) +add_subdirectory(Subdir) +add_subdirectory(Executable) diff --git a/Tests/FortranModules/Executable/CMakeLists.txt b/Tests/FortranModules/Executable/CMakeLists.txt new file mode 100644 index 0000000..de08d86 --- /dev/null +++ b/Tests/FortranModules/Executable/CMakeLists.txt @@ -0,0 +1,8 @@ +include_directories(${Library_MODDIR}) +include_directories(${External_BINARY_DIR}) +link_directories(${External_BINARY_DIR}) + +add_executable(subdir_exe2 main.f90) +target_link_libraries(subdir_exe2 subdir_mods subdir_mods2) +add_dependencies(subdir_exe2 ExternalTarget) +target_link_libraries(subdir_exe2 myext) diff --git a/Tests/FortranModules/Executable/main.f90 b/Tests/FortranModules/Executable/main.f90 new file mode 100644 index 0000000..640259c --- /dev/null +++ b/Tests/FortranModules/Executable/main.f90 @@ -0,0 +1,7 @@ +PROGRAM MAINF90 + USE libraryModuleA + USE libraryModuleB + USE subdirModuleA + USE externalMod + CALL printExtModGreeting +END PROGRAM MAINF90 diff --git a/Tests/FortranModules/External/CMakeLists.txt b/Tests/FortranModules/External/CMakeLists.txt new file mode 100644 index 0000000..c90a0ffb --- /dev/null +++ b/Tests/FortranModules/External/CMakeLists.txt @@ -0,0 +1,3 @@ +project(ExtFort Fortran) + +add_library(myext a.f90) diff --git a/Tests/FortranModules/External/a.f90 b/Tests/FortranModules/External/a.f90 new file mode 100644 index 0000000..2be73c5 --- /dev/null +++ b/Tests/FortranModules/External/a.f90 @@ -0,0 +1,7 @@ +MODULE externalMod +! +CONTAINS + SUBROUTINE printExtModGreeting + WRITE(*,*) "Greetings from Module externalMod" + END SUBROUTINE +END MODULE diff --git a/Tests/FortranModules/Library/CMakeLists.txt b/Tests/FortranModules/Library/CMakeLists.txt new file mode 100644 index 0000000..17438ca --- /dev/null +++ b/Tests/FortranModules/Library/CMakeLists.txt @@ -0,0 +1,11 @@ +include_directories(${Library_MODDIR}) +add_library(subdir_mods a.f90 b.f90) +add_executable(subdir_exe main.f90) +target_link_libraries(subdir_exe subdir_mods) + +# Test module output directory if available. +if(CMAKE_Fortran_MODDIR_FLAG) + set_target_properties(subdir_mods PROPERTIES + Fortran_MODULE_DIRECTORY modules + ) +endif() diff --git a/Tests/FortranModules/Library/a.f90 b/Tests/FortranModules/Library/a.f90 new file mode 100644 index 0000000..3031c07 --- /dev/null +++ b/Tests/FortranModules/Library/a.f90 @@ -0,0 +1,3 @@ +MODULE libraryModuleA + USE libraryModuleB +END MODULE diff --git a/Tests/FortranModules/Library/b.f90 b/Tests/FortranModules/Library/b.f90 new file mode 100644 index 0000000..ae1edcb --- /dev/null +++ b/Tests/FortranModules/Library/b.f90 @@ -0,0 +1,2 @@ +MODULE libraryModuleB +END MODULE diff --git a/Tests/FortranModules/Library/main.f90 b/Tests/FortranModules/Library/main.f90 new file mode 100644 index 0000000..2385408 --- /dev/null +++ b/Tests/FortranModules/Library/main.f90 @@ -0,0 +1,3 @@ +PROGRAM MAINF90 + USE libraryModuleA +END PROGRAM MAINF90 diff --git a/Tests/FortranModules/Subdir/CMakeLists.txt b/Tests/FortranModules/Subdir/CMakeLists.txt new file mode 100644 index 0000000..52683e5 --- /dev/null +++ b/Tests/FortranModules/Subdir/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(subdir_mods2 subdir.f90) +target_include_directories(subdir_mods2 INTERFACE ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/Tests/FortranModules/Subdir/subdir.f90 b/Tests/FortranModules/Subdir/subdir.f90 new file mode 100644 index 0000000..68955f6 --- /dev/null +++ b/Tests/FortranModules/Subdir/subdir.f90 @@ -0,0 +1,2 @@ +MODULE subdirModuleA +END MODULE diff --git a/Tests/FortranModules/in_interface/main.f90 b/Tests/FortranModules/in_interface/main.f90 new file mode 100644 index 0000000..28bcf36 --- /dev/null +++ b/Tests/FortranModules/in_interface/main.f90 @@ -0,0 +1,3 @@ +program hello + use test_interface +end program hello diff --git a/Tests/FortranModules/in_interface/module.f90 b/Tests/FortranModules/in_interface/module.f90 new file mode 100644 index 0000000..1064d74 --- /dev/null +++ b/Tests/FortranModules/in_interface/module.f90 @@ -0,0 +1,12 @@ +module test_interface + + interface dummy + module procedure module_function + end interface + +contains + + subroutine module_function + end subroutine + +end module test_interface
\ No newline at end of file diff --git a/Tests/FortranModules/include/test_preprocess.h b/Tests/FortranModules/include/test_preprocess.h new file mode 100644 index 0000000..f4a00a9 --- /dev/null +++ b/Tests/FortranModules/include/test_preprocess.h @@ -0,0 +1,5 @@ +#ifdef BAR +PRINT*, 'BAR was defined via ADD_DEFINITIONS' +#else +PRINT*, 'If you can read this something went wrong' +#endif diff --git a/Tests/FortranModules/test_module_implementation.f90 b/Tests/FortranModules/test_module_implementation.f90 new file mode 100644 index 0000000..de3cb57 --- /dev/null +++ b/Tests/FortranModules/test_module_implementation.f90 @@ -0,0 +1,6 @@ +FUNCTION TEST_MODULE_FUNCTION(A,B) + REAL :: TEST_MODULE_FUNCTION + REAL, INTENT(IN) :: A + REAL, INTENT(IN) :: B + TEST_MODULE_FUNCTION = A + B +END FUNCTION TEST_MODULE_FUNCTION diff --git a/Tests/FortranModules/test_module_interface.f90 b/Tests/FortranModules/test_module_interface.f90 new file mode 100644 index 0000000..dd0f35c --- /dev/null +++ b/Tests/FortranModules/test_module_interface.f90 @@ -0,0 +1,9 @@ +MODULE TEST_MODULE + INTERFACE + FUNCTION TEST_MODULE_FUNCTION(A,B) + REAL :: TEST_MODULE_FUNCTION + REAL, INTENT(IN) :: A + REAL, INTENT(IN) :: B + END FUNCTION TEST_MODULE_FUNCTION + END INTERFACE +END MODULE TEST_MODULE diff --git a/Tests/FortranModules/test_module_main.f90 b/Tests/FortranModules/test_module_main.f90 new file mode 100644 index 0000000..6ac97fa --- /dev/null +++ b/Tests/FortranModules/test_module_main.f90 @@ -0,0 +1,4 @@ +PROGRAM MAINF90 + USE TEST_MODULE + PRINT *,'Sum is',TEST_MODULE_FUNCTION(1., 2.) +END PROGRAM MAINF90 diff --git a/Tests/FortranModules/test_preprocess.F90 b/Tests/FortranModules/test_preprocess.F90 new file mode 100644 index 0000000..3a09976 --- /dev/null +++ b/Tests/FortranModules/test_preprocess.F90 @@ -0,0 +1,53 @@ +MODULE Available +! no conent +END MODULE + +PROGRAM PPTEST +! value of InPPFalseBranch ; values of SkipToEnd +! 0 <empty> +#ifndef FOO + ! 1 ; <0> + USE NotAvailable +# ifndef FOO + ! 2 ; <0,0> + USE NotAvailable +# else + ! 2 ; <0,0> + USE NotAvailable +# endif + ! 1 ; <0> +# ifdef FOO + ! 2 ; <0,1> + USE NotAvailable +# else + ! 2 ; <0,1> + USE NotAvailable +# endif + ! 1 ; <0> +#else + ! 0 ; <0> + USE Available +# ifndef FOO + ! 1 ; <0,0> + USE NotAvailable +# else + ! 0 ; <0,0> + USE Available +# endif + ! 0 ; <0> +# ifdef FOO + ! 0 ; <0,1> + USE Available +# else + ! 1 ; <0,1> + USE NotAvailable +# endif + ! 0 ; <0> +#endif +! 0 ; <empty> + +USE PPAvailable + +#include "test_preprocess.h" + +END PROGRAM diff --git a/Tests/FortranModules/test_preprocess_module.F90 b/Tests/FortranModules/test_preprocess_module.F90 new file mode 100644 index 0000000..5849b62 --- /dev/null +++ b/Tests/FortranModules/test_preprocess_module.F90 @@ -0,0 +1,5 @@ +#ifdef FOO +MODULE PPAvailable +! no conent +END MODULE +#endif diff --git a/Tests/FortranModules/test_use_in_comment_fixedform.f b/Tests/FortranModules/test_use_in_comment_fixedform.f new file mode 100644 index 0000000..39f486b --- /dev/null +++ b/Tests/FortranModules/test_use_in_comment_fixedform.f @@ -0,0 +1,7 @@ + PROGRAM foo +! USE bar +! use bar +! Use bar + + WRITE(*,*) 'Hello, Fortran world.' + END PROGRAM diff --git a/Tests/FortranModules/test_use_in_comment_freeform.f90 b/Tests/FortranModules/test_use_in_comment_freeform.f90 new file mode 100644 index 0000000..48bcd5a --- /dev/null +++ b/Tests/FortranModules/test_use_in_comment_freeform.f90 @@ -0,0 +1,7 @@ +PROGRAM foo +! USE bar +! use bar +! Use bar + + WRITE(*,*) 'Hello, Fortran world.' +END PROGRAM |