diff options
-rw-r--r-- | Help/release/dev/FindMatlab-simulink.rst | 4 | ||||
-rw-r--r-- | Modules/FindMatlab.cmake | 47 | ||||
-rw-r--r-- | Source/CMakeVersion.cmake | 2 | ||||
-rw-r--r-- | Tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/FortranModules/CMakeLists.txt | 31 | ||||
-rw-r--r-- | Tests/FortranModules/Submodules/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/FortranModules/Submodules/main.f90 | 5 | ||||
-rw-r--r-- | Tests/FortranModules/Submodules/provide.f90 | 57 |
8 files changed, 142 insertions, 6 deletions
diff --git a/Help/release/dev/FindMatlab-simulink.rst b/Help/release/dev/FindMatlab-simulink.rst new file mode 100644 index 0000000..cd25412 --- /dev/null +++ b/Help/release/dev/FindMatlab-simulink.rst @@ -0,0 +1,4 @@ +FindMatlab-simulink +------------------- + +* The :module:`FindMatlab` module learned to find a SIMULINK component. diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index c813f8f..8b41bb9 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -18,6 +18,8 @@ # * ``MX_LIBRARY``, ``ENG_LIBRARY`` and ``MAT_LIBRARY``: respectively the MX, # ENG and MAT libraries of Matlab # * ``MAIN_PROGRAM`` the Matlab binary program. +# * ``MEX_COMPILER`` the MEX compiler. +# * ``SIMULINK`` the Simulink environment. # # .. note:: # @@ -819,12 +821,13 @@ endfunction() # order to produce a MEX file. The final name of the produced output may be # specified, as well as additional link libraries, and a documentation entry # for the MEX file. Remaining arguments of the call are passed to the -# :command:`add_library` command. +# :command:`add_library` or :command:`add_executable` command. # # :: # # matlab_add_mex( # NAME <name> +# [EXECUTABLE | MODULE | SHARED] # SRC src1 [src2 ...] # [OUTPUT_NAME output_name] # [DOCUMENTATION file.txt] @@ -835,7 +838,7 @@ endfunction() # ``NAME`` # name of the target. # ``SRC`` -# list of tje source files. +# list of source files. # ``LINK_TO`` # a list of additional link dependencies. The target links to ``libmex`` # by default. If ``Matlab_MX_LIBRARY`` is defined, it also @@ -851,6 +854,10 @@ endfunction() # mex file, and with extension `.m`. In that case, typing ``help <name>`` # in Matlab prints the documentation contained in this file. # +# ``MODULE`` or ``SHARED`` may be given to specify the type of library to be +# created. ``EXECUTABLE`` may be given to create an executable instead of +# a library. If no type is given explicitly, the type is ``SHARED``. +# # The documentation file is not processed and should be in the following # format: # @@ -859,7 +866,7 @@ endfunction() # % This is the documentation # function ret = mex_target_output_name(input1) # -function(matlab_add_mex ) +function(matlab_add_mex) if(NOT WIN32) # we do not need all this on Windows @@ -871,6 +878,7 @@ function(matlab_add_mex ) endif() + set(options EXECUTABLE MODULE SHARED) set(oneValueArgs NAME DOCUMENTATION OUTPUT_NAME) set(multiValueArgs LINK_TO SRC) @@ -885,11 +893,25 @@ function(matlab_add_mex ) set(${prefix}_OUTPUT_NAME ${${prefix}_NAME}) endif() - add_library(${${prefix}_NAME} - SHARED + if(${prefix}_EXECUTABLE) + add_executable(${${prefix}_NAME} + ${${prefix}_SRC} + ${${prefix}_DOCUMENTATION} + ${${prefix}_UNPARSED_ARGUMENTS}) + else() + if(${prefix}_MODULE) + set(type MODULE) + else() + set(type SHARED) + endif() + + add_library(${${prefix}_NAME} + ${type} ${${prefix}_SRC} ${${prefix}_DOCUMENTATION} ${${prefix}_UNPARSED_ARGUMENTS}) + endif() + target_include_directories(${${prefix}_NAME} PRIVATE ${Matlab_INCLUDE_DIRS}) if(DEFINED Matlab_MX_LIBRARY) @@ -1463,6 +1485,21 @@ if(_matlab_find_mat GREATER -1) endif() unset(_matlab_find_mat) +# Component Simulink +list(FIND Matlab_FIND_COMPONENTS SIMULINK _matlab_find_simulink) +if(_matlab_find_simulink GREATER -1) + find_path( + Matlab_SIMULINK_INCLUDE_DIR + simstruc.h + PATHS "${Matlab_ROOT_DIR}/simulink/include" + NO_DEFAULT_PATH + ) + if(Matlab_SIMULINK_INCLUDE_DIR) + set(Matlab_SIMULINK_FOUND TRUE) + list(APPEND Matlab_INCLUDE_DIRS "${Matlab_SIMULINK_INCLUDE_DIR}") + endif() +endif() +unset(_matlab_find_simulink) unset(_matlab_lib_dir_for_search) diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 27ca0ca..9a10ddb 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 6) -set(CMake_VERSION_PATCH 20160923) +set(CMake_VERSION_PATCH 20160926) #set(CMake_VERSION_RC 1) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 235e38a..3681843 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -3109,6 +3109,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release --build-project FortranModules --build-options ${build_options} -DCMake_TEST_NESTED_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM} + -DCMake_TEST_Fortran_SUBMODULES:BOOL=${CMake_TEST_Fortran_SUBMODULES} ) list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/FortranModules") endif() diff --git a/Tests/FortranModules/CMakeLists.txt b/Tests/FortranModules/CMakeLists.txt index b406df3..ff12771 100644 --- a/Tests/FortranModules/CMakeLists.txt +++ b/Tests/FortranModules/CMakeLists.txt @@ -5,6 +5,33 @@ if(NOT DEFINED CMake_TEST_NESTED_MAKE_PROGRAM AND NOT CMAKE_GENERATOR MATCHES "V set(CMake_TEST_NESTED_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}") endif() +if("x${CMake_TEST_Fortran_SUBMODULES}" STREQUAL "x" + AND NOT CMAKE_VERSION VERSION_LESS 3.6.20160923 # for CheckFortranSourceCompiles SRC_EXT + ) + include(CheckFortranSourceCompiles) + CHECK_Fortran_SOURCE_COMPILES([[ +module parent + interface + module function id(x) + real, intent(in) :: x + real :: id + end function id + end interface +end module parent +submodule ( parent ) child +contains + module procedure id + f = x + end procedure id +end submodule child +program main +end program +]] HAVE_SUBMODULES SRC_EXT F90) + set(CMake_TEST_Fortran_SUBMODULES ${HAVE_SUBMODULES}) +elseif(CMake_TEST_Fortran_SUBMODULES) + message(STATUS "Enabling Fortran submodule tests by explicit request.") +endif() + add_executable(test_module test_module_main.f90 test_module_implementation.f90 @@ -76,3 +103,7 @@ endif() add_subdirectory(Library) add_subdirectory(Subdir) add_subdirectory(Executable) + +if(CMake_TEST_Fortran_SUBMODULES) + add_subdirectory(Submodules) +endif() diff --git a/Tests/FortranModules/Submodules/CMakeLists.txt b/Tests/FortranModules/Submodules/CMakeLists.txt new file mode 100644 index 0000000..bf0152f --- /dev/null +++ b/Tests/FortranModules/Submodules/CMakeLists.txt @@ -0,0 +1 @@ +add_executable(submod main.f90 provide.f90) diff --git a/Tests/FortranModules/Submodules/main.f90 b/Tests/FortranModules/Submodules/main.f90 new file mode 100644 index 0000000..3c750ce --- /dev/null +++ b/Tests/FortranModules/Submodules/main.f90 @@ -0,0 +1,5 @@ +program main + use parent, only : child_function,grandchild_subroutine + implicit none + if (child_function()) call grandchild_subroutine +end program diff --git a/Tests/FortranModules/Submodules/provide.f90 b/Tests/FortranModules/Submodules/provide.f90 new file mode 100644 index 0000000..0ad216a --- /dev/null +++ b/Tests/FortranModules/Submodules/provide.f90 @@ -0,0 +1,57 @@ +! The program units in this file consist of a +! module/submodule tree represented by the following +! graph: +! +! parent +! | +! / \ +! / \ +! child sibling +! | +! grandchild +! +! where the parent node is a module and all other +! nodes are submodules. + +module parent + implicit none + + interface + + ! Test Fortran 2008 "module function" syntax + module function child_function() result(child_stuff) + logical :: child_stuff + end function + + ! Test Fortran 2008 "module subroutine" syntax + module subroutine grandchild_subroutine() + end subroutine + + end interface + +end module parent + +! Test the notation for a 1st-generation direct +! descendant of a parent module +submodule ( parent ) child + implicit none +contains + module function child_function() result(child_stuff) + logical :: child_stuff + child_stuff=.true. + end function +end submodule child + +! Empty submodule for checking disambiguation of +! nodes at the same vertical level in the tree +submodule ( parent ) sibling +end submodule sibling + +! Test the notation for an Nth-generation descendant +! for N>1, which necessitates the colon. +submodule ( parent : child ) grandchild +contains + module subroutine grandchild_subroutine() + print *,"Test passed." + end subroutine +end submodule grandchild |