diff options
-rw-r--r-- | Help/release/dev/useswig-fortran.rst | 7 | ||||
-rw-r--r-- | Help/variable/CMAKE_CFG_INTDIR.rst | 7 | ||||
-rw-r--r-- | Modules/UseSWIG.cmake | 20 | ||||
-rw-r--r-- | Source/CMakeVersion.cmake | 2 | ||||
-rw-r--r-- | Tests/CFBundleTest/VerifyResult.cmake | 2 | ||||
-rw-r--r-- | Tests/CustComDepend/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Tests/RunCMake/Make/RunCMakeTest.cmake | 3 | ||||
-rw-r--r-- | Tests/UseSWIG/BasicConfiguration.cmake | 3 | ||||
-rw-r--r-- | Tests/UseSWIG/BasicFortran/CMakeLists.txt | 23 | ||||
-rw-r--r-- | Tests/UseSWIG/CMakeLists.txt | 15 | ||||
-rw-r--r-- | Tests/UseSWIG/runme.f90 | 77 |
11 files changed, 159 insertions, 4 deletions
diff --git a/Help/release/dev/useswig-fortran.rst b/Help/release/dev/useswig-fortran.rst new file mode 100644 index 0000000..17baf96 --- /dev/null +++ b/Help/release/dev/useswig-fortran.rst @@ -0,0 +1,7 @@ +useswig-fortran +--------------- + +* The :module:`UseSWIG` module now supports Fortran as a target language if + the ``SWIG_EXECUTABLE`` is SWIG-Fortran_. + +.. _`SWIG-Fortran`: https://github.com/swig-fortran/swig diff --git a/Help/variable/CMAKE_CFG_INTDIR.rst b/Help/variable/CMAKE_CFG_INTDIR.rst index af82f75..842654e 100644 --- a/Help/variable/CMAKE_CFG_INTDIR.rst +++ b/Help/variable/CMAKE_CFG_INTDIR.rst @@ -16,6 +16,13 @@ Example values: $(Configuration) = Visual Studio 10 $(CONFIGURATION) = Xcode . = Make-based tools + . = Ninja + ${CONFIGURATION} = Ninja Multi-Config + +Note that this variable only has limited support on +:generator:`Ninja Multi-Config`. It is recommended that you use the +``$<CONFIG>`` :manual:`generator expression <cmake-generator-expressions(7)>` +instead. Since these values are evaluated by the native build system, this variable is suitable only for use in command lines that will be diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index 78522da..f6a20f8 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -341,6 +341,23 @@ function(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile) list(APPEND files "${extra_file}") endforeach() + if (language STREQUAL "FORTRAN" AND CMAKE_Fortran_COMPILER_LOADED) + # Process possible user-supplied extension in flags (obtained via parent + # scope variable) to determine the source file name. + list(FIND SWIG_COMPILATION_FLAGS "-fext" fext_idx) + if (fext_idx EQUAL -1) + # Default Fortran generated extension + set(fext "f90") + else() + # Get extension from user-provided flag + math(EXPR fext_idx "${fext_idx} + 1") + list(GET SWIG_COMPILATION_FLAGS "${fext_idx}" fext) + endif() + set(extra_file "${generatedpath}/${module_basename}.${fext}") + set_source_files_properties("${extra_file}" PROPERTIES LANGUAGE "Fortran") + list(APPEND files "${extra_file}") + endif() + set (${outfiles} ${files} PARENT_SCOPE) endfunction() @@ -415,6 +432,7 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) get_filename_component(swig_source_file_fullname "${infile}" ABSOLUTE) if (NOT SWIG_MODULE_${name}_NOPROXY) + set(SWIG_COMPILATION_FLAGS ${swig_source_file_flags}) SWIG_GET_EXTRA_OUTPUT_FILES(${SWIG_MODULE_${name}_LANGUAGE} swig_extra_generated_files "${outdir}" @@ -787,6 +805,8 @@ function(SWIG_ADD_LIBRARY name) if (APPLE) set_target_properties (${target_name} PROPERTIES SUFFIX ".dylib") endif () + elseif (swig_lowercase_language STREQUAL "fortran") + # Do *not* override the target's library prefix else() # assume empty prefix because we expect the module to be dynamically loaded set_target_properties (${target_name} PROPERTIES PREFIX "") diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index b2cae1f..6d0beef 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,7 +1,7 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 17) -set(CMake_VERSION_PATCH 20200225) +set(CMake_VERSION_PATCH 20200226) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Tests/CFBundleTest/VerifyResult.cmake b/Tests/CFBundleTest/VerifyResult.cmake index e637bb1..ac14e5d 100644 --- a/Tests/CFBundleTest/VerifyResult.cmake +++ b/Tests/CFBundleTest/VerifyResult.cmake @@ -14,7 +14,7 @@ message(STATUS "CTEST_CONFIGURATION_TYPE='${CTEST_CONFIGURATION_TYPE}'") message(STATUS "dir='${dir}'") message(STATUS "gen='${gen}'") -if(gen STREQUAL "Xcode") +if(gen MATCHES "^(Xcode$|Ninja Multi-Config$)") set(expected_filename "${dir}/${CTEST_CONFIGURATION_TYPE}/CFBundleTest.plugin/Contents/MacOS/CFBundleTest") else() set(expected_filename "${dir}/CFBundleTest.plugin/Contents/MacOS/CFBundleTest") diff --git a/Tests/CustComDepend/CMakeLists.txt b/Tests/CustComDepend/CMakeLists.txt index 46276b2..777cdcc 100644 --- a/Tests/CustComDepend/CMakeLists.txt +++ b/Tests/CustComDepend/CMakeLists.txt @@ -6,9 +6,9 @@ set(EXECUTABLE_OUTPUT_PATH ${CustComDepend_BINARY_DIR}/bin) add_executable(foo foo.cxx) add_custom_command( OUTPUT ${CustComDepend_BINARY_DIR}/bar.c - COMMAND ${CustComDepend_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/foo + COMMAND $<TARGET_FILE:foo> ${CustComDepend_BINARY_DIR}/bar.c - DEPENDS ${CustComDepend_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/foo + DEPENDS $<TARGET_FILE:foo> ) add_library(bar SHARED ${CustComDepend_BINARY_DIR}/bar.c) diff --git a/Tests/RunCMake/Make/RunCMakeTest.cmake b/Tests/RunCMake/Make/RunCMakeTest.cmake index 82db6b7..6b2721c 100644 --- a/Tests/RunCMake/Make/RunCMakeTest.cmake +++ b/Tests/RunCMake/Make/RunCMakeTest.cmake @@ -26,10 +26,13 @@ function(run_VerboseBuild) endif() run_cmake_command(VerboseBuild-build ${CMAKE_COMMAND} --build . -v --clean-first) unset(RunCMake-stdout-file) + set(_backup_lang "$ENV{LANG}") if(MAKE_IS_GNU) set(RunCMake-stdout-file VerboseBuild-nowork-gnu-stdout.txt) + set(ENV{LANG} "C") endif() run_cmake_command(VerboseBuild-nowork ${CMAKE_COMMAND} --build . --verbose) + set(ENV{LANG} "${_backup_lang}") endfunction() run_VerboseBuild() diff --git a/Tests/UseSWIG/BasicConfiguration.cmake b/Tests/UseSWIG/BasicConfiguration.cmake index fd3ac40..d054953 100644 --- a/Tests/UseSWIG/BasicConfiguration.cmake +++ b/Tests/UseSWIG/BasicConfiguration.cmake @@ -18,6 +18,9 @@ unset(SWIG_LANG_LIBRARIES) if(${language} MATCHES csharp) set(SWIG_LANG_TYPE TYPE SHARED) endif() +if(${language} MATCHES fortran) + set(SWIG_LANG_TYPE TYPE SHARED) +endif() if(${language} MATCHES python) find_package(Python REQUIRED COMPONENTS Interpreter Development) set(SWIG_LANG_INCLUDE_DIRECTORIES ${Python_INCLUDE_DIRS}) diff --git a/Tests/UseSWIG/BasicFortran/CMakeLists.txt b/Tests/UseSWIG/BasicFortran/CMakeLists.txt new file mode 100644 index 0000000..e81fb85 --- /dev/null +++ b/Tests/UseSWIG/BasicFortran/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.12...3.13) + +project(TestBasicFortran CXX Fortran) + +include(CTest) + +set(language "fortran") + +include (../BasicConfiguration.cmake) +get_target_property(EXAMPLE_PREFIX example PREFIX) +if (NOT EXAMPLE_PREFIX STREQUAL "${CMAKE_SHARED_LIBRARY_PREFIX}" + AND NOT EXAMPLE_PREFIX STREQUAL "EXAMPLE_PREFIX-NOTFOUND") + message(FATAL_ERROR "Unexpected library prefix on target: got " + "'${EXAMPLE_PREFIX}' but expected '${CMAKE_SHARED_LIBRARY_PREFIX}'") +endif() + + +add_executable(runme ${CMAKE_CURRENT_SOURCE_DIR}/../runme.f90) +target_link_libraries(runme example) +set_target_properties(runme PROPERTIES LINKER_LANGUAGE Fortran) + +add_test (NAME BasicFortran + COMMAND $<TARGET_FILE:runme>) diff --git a/Tests/UseSWIG/CMakeLists.txt b/Tests/UseSWIG/CMakeLists.txt index 3cc910f..d102846 100644 --- a/Tests/UseSWIG/CMakeLists.txt +++ b/Tests/UseSWIG/CMakeLists.txt @@ -55,6 +55,21 @@ add_test(NAME UseSWIG.BasicPerl COMMAND --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) +if (CMake_TEST_UseSWIG_Fortran) + check_language(Fortran) + if (CMAKE_Fortran_COMPILER) + add_test(NAME UseSWIG.BasicFortran COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/UseSWIG/BasicFortran" + "${CMake_BINARY_DIR}/Tests/UseSWIG/BasicFortran" + ${build_generator_args} + --build-project TestBasicFortran + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) + endif() +endif() add_test(NAME UseSWIG.MultipleModules COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> diff --git a/Tests/UseSWIG/runme.f90 b/Tests/UseSWIG/runme.f90 new file mode 100644 index 0000000..1d985d3 --- /dev/null +++ b/Tests/UseSWIG/runme.f90 @@ -0,0 +1,77 @@ +! File : runme.f90 +program runme + use ISO_FORTRAN_ENV + implicit none + integer, parameter :: STDOUT = OUTPUT_UNIT + + call run() +contains + +subroutine run() + use example + use iso_c_binding + implicit none + + type(Circle) :: c + type(Square), target :: s ! 'target' allows it to be pointed to + class(Shape), pointer :: sh + integer(C_INT) :: n_shapes + + ! ----- Object creation ----- + + write(STDOUT,*) "Creating some objects" + c = Circle(10.0d0) + s = Square(10.0d0) + + ! ----- Access a static member ----- + write(STDOUT,'(a,i2,a)')"A total of", s%get_nshapes(), " shapes were created" + + ! ----- Member data access ----- + + ! Notice how we can do this using functions specific to + ! the 'Circle' class. + call c%set_x(20.0d0) + call c%set_y(30.0d0) + + ! Now use the same functions in the base class + sh => s + call sh%set_x(-10.0d0) + call sh%set_y( 5.0d0) + + write(STDOUT,*)"Here is their current position:" + write(STDOUT,'(a,f5.1,a,f5.1,a)')" Circle = (", c%get_x(), ",", c%get_y(), " )" + write(STDOUT,'(a,f5.1,a,f5.1,a)')" Square = (", s%get_x(), ",", s%get_y(), " )" + + ! ----- Call some methods ----- + + write(STDOUT,*)"Here are some properties of the shapes:" + call print_shape(c) + call print_shape(s) + + ! ----- Delete everything ----- + + ! Note: this invokes the virtual destructor + call c%release() + call s%release() + + n_shapes = c%get_nshapes() + write(STDOUT,*) n_shapes, "shapes remain" + if (n_shapes /= 0) then + write(STDOUT,*) "Shapes were not freed properly!" + stop 1 + endif + + write(STDOUT,*) "Goodbye" +end subroutine + +subroutine print_shape(s) + use example, only : Shape + use iso_c_binding + implicit none + class(Shape), intent(in) :: s + + write(STDOUT,*)" area = ",s%area() + write(STDOUT,*)" perimeter = ",s%perimeter() +end subroutine + +end program |