1 # ============================================================================ 2 # Copyright (c) 2011-2012 University of Pennsylvania 3 # Copyright (c) 2013-2016 Andreas Schuh 6 # See COPYING file for license information or visit 7 # https://cmake-basis.github.io/download.html#license 8 # ============================================================================ 10 ############################################################################## 11 # @file MatlabTools.cmake 12 # @brief Enables use of MATLAB Compiler and build of MEX-files. 15 ############################################################################## 24 # ============================================================================ 26 # ============================================================================ 28 # Note: Required because generate_matlab_executable.cmake uses this module. 30 include (CMakeParseArguments)
31 include ("${CMAKE_CURRENT_LIST_DIR}/CommonTools.cmake
") 32 include ("${CMAKE_CURRENT_LIST_DIR}/UtilitiesTools.cmake
") 34 # ============================================================================ 36 # ============================================================================ 38 ## @addtogroup BasisSettings 41 ## @brief Enable/Disable compilation of MATLAB sources if the MATLAB Compiler is available. 42 option (BASIS_COMPILE_MATLAB "Enable compilation of MATLAB sources
if MATLAB Compiler (mcc)
is available." ON)
45 # ---------------------------------------------------------------------------- 46 ## @brief Add global MATLAB MEX-script options to CMake cache 48 # @par MATLAB MEX-script options: 51 # @tp @b BASIS_MEX_TIMEOUT @endtp 52 # <td>Timeout for MEX script execution.</td> 55 # @tp @b BASIS_MEX_FLAGS @endtp 56 # <td>Compile flags used to build MEX-files using the MEX script.</td> 60 if (MATLAB_MEX_EXECUTABLE)
61 set (BASIS_MEX_TIMEOUT "600" CACHE STRING "Timeout for MEX script execution")
62 set (BASIS_MEX_FLAGS "" CACHE STRING "Common MEX switches (separated by ' '; use '\\' to mask ' ').")
63 mark_as_advanced (BASIS_MEX_FLAGS)
64 mark_as_advanced (BASIS_MEX_TIMEOUT)
68 # ---------------------------------------------------------------------------- 69 ## @brief Add global MATLAB Compiler (mcc) options to CMake cache 71 # @par MATLAB Compiler options: 74 # @tp @b BASIS_MCC_MATLAB_MODE @endtp 75 # <td>Enable/Disable invocation of MATLAB Compiler in MATLAB mode.</td> 78 # @tp @b BASIS_MCC_FLAGS @endtp 79 # <td>Compile flags used to build MATLAB Compiler targets.</td> 82 # @tp @b BASIS_MCC_TIMEOUT @endtp 83 # <td>Timeout for building MATLAB Compiler targets.</td> 86 # @tp @b BASIS_MCC_RETRY_ATTEMPTS @endtp 87 # <td>Maximum number of retries on MATLAB Compiler license checkout.</td> 90 # @tp @b BASIS_MCC_RETRY_DELAY @endtp 91 # <td>Delay between retries to build MATLAB Compiler compiled targets on license checkout errors.</td> 97 "Prefer MATLAB mode over standalone mode to invoke MATLAB Compiler to release MCC licence ASAP."
98 OFF
# using MATLAB mode is preferred when the license is shared 99 # among users as it releases the license immediately once done 103 "-R -singleCompThread" 105 "Common MATLAB Compiler flags (separated by ' '; use '\\' to mask ' ')." 107 set (BASIS_MCC_TIMEOUT
"1800" CACHE STRING
"Timeout for MATLAB Compiler execution")
108 set (BASIS_MCC_RETRY_ATTEMPTS
"4" CACHE STRING
"Maximum number of retries on MATLAB Compiler license checkout error.")
109 set (BASIS_MCC_RETRY_DELAY
"30" CACHE STRING
"Delay between retries to build MATLAB Compiler compiled targets on license checkout error.")
110 mark_as_advanced (BASIS_MCC_MATLAB_MODE)
111 mark_as_advanced (BASIS_MCC_FLAGS)
112 mark_as_advanced (BASIS_MCC_TIMEOUT)
113 mark_as_advanced (BASIS_MCC_RETRY_ATTEMPTS)
114 mark_as_advanced (BASIS_MCC_RETRY_DELAY)
118 # end of Doxygen group 120 # ============================================================================ 122 # ============================================================================ 124 # ---------------------------------------------------------------------------- 125 ## @brief Determine version of MATLAB installation. 127 # @param [out] VERSION Value returned by the "version" command of MATLAB or 128 # an empty string if execution of MATLAB failed. 130 # @returns Sets the variable named by @p VERSION to the full MATLAB version. 132 # @ingroup CMakeUtilities 134 if (NOT MATLAB_EXECUTABLE)
135 set (${
VERSION}
"" PARENT_SCOPE)
138 set (WORKING_DIR
"${CMAKE_BINARY_DIR}/CMakeFiles")
139 set (OUTPUT_FILE
"${WORKING_DIR}/MatlabVersion.txt")
140 # read MATLAB version from existing output file 141 set (_MATLAB_VERSION)
142 if (EXISTS
"${OUTPUT_FILE}")
143 file (READ
"${OUTPUT_FILE}" LINES)
144 string (REGEX REPLACE
"\n" ";" LINES
"${LINES}")
145 string (REGEX REPLACE
"^;|;$" "" LINES
"${LINES}")
146 list (LENGTH LINES NLINES)
148 list (GET LINES 0 _MATLAB_EXECUTABLE)
149 list (GET LINES 1 _MATLAB_VERSION)
151 if (NOT _MATLAB_EXECUTABLE MATCHES
"^${RE}$")
152 set (_MATLAB_VERSION)
157 # run matlab command to write return value of "version" command to text file 158 if (NOT _MATLAB_VERSION)
159 message (STATUS
"Determining MATLAB version...")
160 set (
CMD "${MATLAB_EXECUTABLE}" -nodesktop -nosplash -singleCompThread)
162 list (APPEND
CMD -automation)
164 list (APPEND
CMD -nojvm)
166 file (WRITE
"${WORKING_DIR}/basis_get_full_matlab_version.m" 167 "% DO NOT EDIT. Automatically created by BASIS (basis_get_full_matlab_version). 168 fid = fopen ('${OUTPUT_FILE}', 'w') 169 if fid == -1, fprintf(2, '??? Error: Failed to open file ${OUTPUT_FILE} for writing!'), quit force, end 170 fprintf (fid, '${MATLAB_EXECUTABLE}\\n%s\\n', version) 176 COMMAND ${
CMD} -r
"cd('${WORKING_DIR}');basis_get_full_matlab_version;" 177 WORKING_DIRECTORY
"${WORKING_DIR}" 179 TIMEOUT 600 # MATLAB startup can be *very* slow the first time
183 if (NOT
RETVAL EQUAL 0 OR
STDERR MATCHES
"\\?\\?\\? Error")
184 set (${
VERSION}
"" PARENT_SCOPE)
185 if (
RETVAL MATCHES
"timeout")
186 set (REASON
": ${RETVAL}")
187 elseif (NOT
RETVAL EQUAL 0)
188 set (REASON
" with exit code: ${RETVAL}")
190 set (REASON
": Failed to open file ${OUTPUT_FILE} for writing")
192 message (STATUS
"Determining MATLAB version... - failed${REASON}")
195 # wait until MATLAB process terminated entirely and wrote the (buffered?) file 198 while (NOT EXISTS
"${OUTPUT_FILE}")
199 math (EXPR nsleep_count
"${nsleep_count}+1")
200 if (nsleep_count GREATER nsleep_max)
201 message (STATUS
"Determining MATLAB version... - failed: File ${OUTPUT_FILE} still non-existent after ${nsleep_max}s of successful MATLAB termination")
205 execute_process (
COMMAND ping 1.1.1.1 -n 1 -w 1000 OUTPUT_QUIET)
207 execute_process (
COMMAND sleep 1 OUTPUT_QUIET)
210 # read MATLAB version from text file 211 file (READ
"${OUTPUT_FILE}" LINES)
212 string (REGEX REPLACE
"\n" ";" LINES
"${LINES}")
213 string (REGEX REPLACE
"^;|;$" "" LINES
"${LINES}")
214 list (LENGTH LINES NLINES)
216 list (GET LINES 1 _MATLAB_VERSION)
218 set (${
VERSION}
"" PARENT_SCOPE)
219 message (STATUS
"Determining MATLAB version... - failed")
223 message (STATUS
"Determining MATLAB version... - done: ${_MATLAB_VERSION}")
225 message (STATUS
"Determining MATLAB version... - done")
229 set (${
VERSION}
"${_MATLAB_VERSION}" PARENT_SCOPE)
232 # ---------------------------------------------------------------------------- 233 ## @brief Get version of MATLAB installation. 235 # @param [out] ARGV1 If given, the named variable is set to the version string 236 # ("<major>.<minor>.<patch>") of the MATLAB installation. 237 # Otherwise, the variables @c MATLAB_VERSION_STRING, 238 # @c MATLAB_VERSION_MAJOR, @c MATLAB_VERSION_MINOR, 239 # @c MATLAB_VERSION_PATCH, and @c MATLAB_RELEASE are set 240 # in the scope of the caller. 242 # @ingroup CMakeUtilities 245 message (FATAL_ERROR
"basis_get_matlab_version(): Too many arguments!")
248 if (
VERSION MATCHES
"^([0-9]+)\\.([0-9]+)\\.([0-9]+)")
249 set (VERSION_STRING
"${CMAKE_MATCH_0}")
254 set (VERSION_STRING
"0.0")
260 set (${ARGV0}
"${VERSION_STRING}" PARENT_SCOPE)
262 set (MATLAB_VERSION_STRING
"${VERSION_STRING}" PARENT_SCOPE)
263 set (MATLAB_VERSION_MAJOR
"${VERSION_MAJOR}" PARENT_SCOPE)
264 set (MATLAB_VERSION_MINOR
"${VERSION_MINOR}" PARENT_SCOPE)
265 set (MATLAB_VERSION_PATCH
"${VERSION_PATCH}" PARENT_SCOPE)
266 if (
VERSION MATCHES
".*\\\((.+)\\\)")
267 set (MATLAB_RELEASE
"${CMAKE_MATCH_1}" PARENT_SCOPE)
269 set (MATLAB_RELEASE
"" PARENT_SCOPE)
274 # ---------------------------------------------------------------------------- 275 ## @brief Get release version of MATLAB installation. 277 # @param [out] ARGV1 If given, the named variable is set to the release string 278 # of the MATLAB installation, e.g., "R2009b". Otherwise, 279 # the variable @c MATLAB_RELEASE is set in the scope of the 282 # @ingroup CMakeUtilities 285 message (FATAL_ERROR
"basis_get_matlab_release(): Too many arguments!")
288 if (
VERSION MATCHES
".*\\\((.+)\\\)")
289 set (
RELEASE "${CMAKE_MATCH_1}")
294 set (${ARGV0}
"${RELEASE}" PARENT_SCOPE)
296 set (MATLAB_RELEASE
"${RELEASE}")
300 # ---------------------------------------------------------------------------- 301 ## @brief Determine extension of MEX-files for this architecture. 303 # @param [out] ARGN The first argument ARGV0 is set to the extension of 304 # MEX-files (excluding '.'). If the CMake variable MEX_EXT 305 # is set, its value is returned. Otherwise, this function 306 # tries to determine it from the system information. 307 # If the extension could not be determined, an empty string 308 # is returned. If no argument is given, the extension is 309 # cached as the variable MEX_EXT. 311 # @returns Sets the variable named by the first argument to the 312 # platform-specific extension of MEX-files. 314 # @ingroup CMakeUtilities 316 #
default return value
317 set (MEXEXT
"${MEX_EXT}")
318 # use MEXEXT if possible 319 if (NOT MEXEXT AND MATLAB_MEXEXT_EXECUTABLE)
321 COMMAND "${MATLAB_MEXEXT_EXECUTABLE}" 323 OUTPUT_VARIABLE MEXEXT
325 OUTPUT_STRIP_TRAILING_WHITESPACE
331 # otherwise, determine extension given CMake variables describing the system 333 if (CMAKE_SYSTEM_NAME MATCHES
"Linux")
334 if (CMAKE_SYSTEM_PROCESSOR MATCHES
"x86_64" OR
335 CMAKE_SIZEOF_VOID_P MATCHES 8)
336 set (MEXEXT
"mexa64")
337 elseif (CMAKE_SYSTEM_PROCESSOR MATCHES
"x86" OR
338 CMAKE_SYSTEM_PROCESSOR MATCHES
"i686")
339 set (MEXEXT
"mexglx")
341 elseif (CMAKE_SYSTEM_NAME MATCHES
"Windows")
342 if (CMAKE_SYSTEM_PROCESSOR MATCHES
"x86_64" OR
343 CMAKE_SIZEOF_VOID_P MATCHES 8)
344 set (MEXEXT
"mexw64")
345 elseif (CMAKE_SYSTEM_PROCESSOR MATCHES
"x86" OR
346 CMAKE_SYSTEM_PROCESSOR MATCHES
"i686")
347 set (MEXEXT
"mexw32")
349 elseif (CMAKE_SYSTEM_NAME MATCHES
"Darwin")
350 if (CMAKE_SYSTEM_PROCESSOR MATCHES
"x86_64" OR
351 CMAKE_SIZEOF_VOID_P MATCHES 8)
352 set (MEXEXT
"mexmaci64")
354 set (MEXEXT
"mexmaci")
356 elseif (CMAKE_SYSTEM_NAME MATCHES
"SunOS")
357 set (MEXEXT
"mexs64")
362 set (
"${ARGV0}" "${MEXEXT}" PARENT_SCOPE)
369 set (MEX_EXT
"${MEXEXT}" CACHE STRING
"The extension of MEX-files for this architecture." FORCE)
371 mark_as_advanced (MEX_EXT)
376 # ---------------------------------------------------------------------------- 377 ## @brief This function writes a MATLAB M-file with addpath() statements. 379 # This function writes an MATLAB M-file into the top directory of the build 380 # tree which contains an addpath() statement for each directory that was added 381 # via basis_include_directories(). 383 # @returns Creates file add_\<project\>_paths.m in the current binary directory. 385 # @ingroup CMakeUtilities 391 # ---------------------------------------------------------------------------- 392 ## @brief This function writes a MATLAB M-file with addpath() statements. 394 # @param [in] MFILE Name of M-file. 395 # @param [in] ARGN The remaining arguments are the paths which should be added 396 # to the search path of MATLAB when this M-file is being 397 # executed. If the option APPEND is given, the paths are 398 # appended to the specified M-file. Otherwise, any existing 399 # file will be overwritten. The given directory paths can 400 # be relative, in which case they are interpreted relative 401 # to the location of the written M-file using the mfilename() 402 # function of MATLAB. 404 # @ingroup CMakeUtilities 406 CMAKE_PARSE_ARGUMENTS (ARGN
"APPEND" "" "" ${ARGN})
408 file (WRITE
"${MFILE}" "% DO NOT edit. This file is automatically generated by BASIS. 409 [mfiledir, ~, ~, ~] = fileparts(mfilename('fullpath'));\n")
411 foreach (P IN LISTS ARGN_UNPARSED_ARGUMENTS)
412 if (P MATCHES
"^\\.?$")
413 file (APPEND
"${MFILE}" "addpath(mfiledir);\n")
414 elseif (IS_ABSOLUTE
"${P}")
415 file (APPEND
"${MFILE}" "addpath('${P}');\n")
417 file (APPEND
"${MFILE}" "addpath([mfiledir '/${P}']);\n")
422 # ---------------------------------------------------------------------------- 423 ## @brief Generate MATLAB wrapper executable. 425 # This function writes a Bash script on Unix or a Windows Command script on 426 # Windows platforms which execute the specified MATLAB command using the -r 427 # option of the matlab executable and the -nodesktop and -nosplash options. 428 # It is used by the build scripts generated by the basis_build_mcc_target() 429 # in order to build an executable from MATLAB source files without the use 430 # of the MATLAB Compiler. In this case, the MATLAB source files are simply 431 # copied to the installation directory and the wrapper script written by 432 # this function used to execute the main function with the command-line 433 # arguments passed on to this executable. 435 # @param [in] OUTPUT_FILE Name of the output executable file. 436 # @param [in] ARGN The remaining options 440 # @tp @b DESTINATION dir @endtp 441 # <td>Installation destination. (default: directory of @c OUTPUT_FILE)</td> 444 # @tp @b COMMAND name @endtp 445 # <td>Name of the MATLAB command to execute, i.e., 446 # the name of the main function.</td> 449 # @tp @b STARTUP mfile @endtp 450 # <td>Absolute path of a startup M-file.</td> 453 # @tp @b MATLABPATH dir1[ dir2...] 454 # <td>List of directories to be added to the MATLAB search path.</td> 457 # @tp @b OPTIONS opt1[ opt2...] 458 # <td>Additional options to pass on to the <tt>matlab</tt> executable.</td> 462 CMAKE_PARSE_ARGUMENTS (ARGN
"" "COMMAND;STARTUP;DESTINATION" "OPTIONS;MATLABPATH" ${ARGN})
463 if (NOT MATLAB_EXECUTABLE)
464 set (MATLAB_EXECUTABLE matlab)
467 message (
"basis_generate_matlab_executable(): Missing OUTPUT_FILE argument!")
469 if (NOT ARGN_DESTINATION)
474 foreach (P IN LISTS ARGN_MATLABPATH)
475 if (P MATCHES
"^\\.?$")
477 elseif (NOT IS_ABSOLUTE
"${P}")
478 set (P
"$__DIR__/${P}")
480 list (APPEND MATLABPATH
"${P}")
483 list (REMOVE_DUPLICATES MATLABPATH)
490 if (STARTUP_PKG MATCHES
"^\\+")
492 string (REGEX REPLACE
"^\\+" "" STARTUP_PKG
"${STARTUP_PKG}")
493 set (STARTUP_COMMAND
"${STARTUP_PKG}.${STARTUP_COMMAND}")
495 if (IS_ABSOLUTE
"${STARTUP_DIR}")
496 file (RELATIVE_PATH STARTUP_DIR
"${ARGN_DESTINATION}" "${STARTUP_DIR}")
499 set (STARTUP_DIR
"$__DIR__/${STARTUP_DIR}")
501 set (STARTUP_DIR
"$__DIR__")
503 list (FIND MATLABPATH
"${STARTUP_DIR}" IDX)
505 set (STARTUP_CODE
", addpath('${STARTUP_DIR}')")
509 set (STARTUP_CODE
"${STARTUP_CODE}, ${STARTUP_COMMAND}")
513 # write wrapper executable 516 set (MATLABPATH
", addpath('${MATLABPATH}', '-begin')")
520 file (WRITE
"${OUTPUT_FILE}" 521 # note that Bash variables within the script are denoted by $var
522 # instead of ${var} to prevent CMake from substituting these patterns
525 readonly __DIR__=\"${BASIS_BASH___DIR__}\" 531 if [[ -n \"$errlog\" ]]; then 532 grep '??? Error' \"$errlog\" &> /dev/null 533 [[ $? -ne 0 ]] || status=1 539 if [[ -d \"$TMPDIR\" ]]; then 545 errlog=`mktemp \"$tmpdir/${ARGN_COMMAND}-log.XXXXXX\"` 547 echo \"Failed to create temporary log file in '$tmpdir'!\" 1>&2 552 while [[ $# -gt 0 ]]; do 553 [[ -z \"$args\" ]] || args=\"$args, \" 558 echo 'Launching MATLAB to execute ${ARGN_COMMAND} function...' 559 trap finish EXIT # DO NOT install trap earlier ! 560 '${MATLAB_EXECUTABLE}' -nodesktop -nosplash ${ARGN_OPTIONS} \\ 561 -r \"try${MATLABPATH}${STARTUP_CODE}, ${ARGN_COMMAND}($args), catch err, fprintf(2, ['??? Error executing ${ARGN_COMMAND}\\n' err.message '\\n']), end, quit force\" \\ 562 2> >(tee \"$errlog\" >&2)" 563 ) # end of file(WRITE) command
565 execute_process (
COMMAND /bin/chmod +x
"${OUTPUT_FILE}")
569 # ============================================================================ 571 # ============================================================================ 573 # ---------------------------------------------------------------------------- 574 ## @brief Add MEX-file target. 576 # @note This function should not be used directly. Instead, it is called 577 # by basis_add_library() if the (detected) programming language 578 # of the given source code files is @c CXX (i.e., C/C++) and the @c MEX 579 # type option is given. 581 # This function is used to add a shared library target which is built 582 # using the MATLAB MEX script (mex). 584 # By default, the BASIS C++ utilities library is added as link dependency. 585 # If none of the BASIS C++ utilities are used by this target, the option 586 # NO_BASIS_UTILITIES can be given. To enable this option by default, set the 587 # variable @c BASIS_UTILITIES to @c FALSE, best in the <tt>Settings.cmake</tt> 588 # file located in the @c PROJECT_CONFIG_DIR (add such file if missing). 589 # If the use of the BASIS C++ utilities is disabled by default, the 590 # @c USE_BASIS_UTILITIES option can be used to enable them for this target 591 # only. Note that the utilities library is a static library and thus the linker 592 # would simply not include any of the BASIS utility functions in the final 593 # binary file if not used. The only advantage of setting @c BASIS_UTILITIES to 594 # @c FALSE or to always specify @c NO_BASIS_UTILITIES if no target uses the 595 # utilities is that the BASIS utilities library will not be build in this case. 597 # A custom CMake build target with the following properties is added by this 598 # function to the build system. These properties are used by 599 # basis_build_mex_target() to generate a build script written in CMake 600 # code which is executed by a custom CMake command. Before the invokation of 601 # basis_build_mex_target(), the target properties can be modified using 602 # basis_set_target_properties(). 604 # @note Custom BASIS build targets are finalized by BASIS using basis_project_end(), 605 # i.e., the end of the root CMake configuration file of the (sub-)project. 607 # @par Properties on script library targets 610 # @tp @b MFILE file @endtp 611 # <td>MATLAB source file with function prototype and documentation of MEX-file. 612 # (default: none)</td> 615 # @tp @b PREFIX prefix @endtp 616 # <td>Output prefix of build MEX-file such as package name 617 # (the prefix must include the leading + and trailing /).</td> 621 # @attention Properties documented as read-only must not be modified. 623 # An install command for the added library target is added by this function 624 # as well. The MEX-file will be installed as part of the specified @p COMPONENT 625 # in the @c INSTALL_LIBRARY_DIR on Unix and @c INSTALL_RUNTIME_DIR on Windows. 627 # @param [in] TARGET_NAME Name of build target. 628 # @param [in] ARGN The remaining arguments are parsed and the following 629 # arguments extracted. All unparsed arguments are treated 630 # as the source files of the MEX-file. 634 # @tp @b COMPONENT name @endtp 635 # <td>Name of installation component as part of which this MEX-file is being 636 # installed if the @c LIBRARY_INSTALL_DIRECTORY property is not "none". 637 # (default: @c BASIS_LIBRARY_COMPONENT)</td> 640 # @tp @b [NO]EXPORT @endtp 641 # <td>Whether to export this target. (default: @c TRUE)</td> 644 # @tp @b NO_BASIS_UTILITIES @endtp 645 # <td>Specify that the BASIS utilities are not used by this MEX-file and 646 # hence no link dependency on the BASIS utilities shall be added. 647 # (default: @c NOT BASIS_UTILITIES)</td> 650 # @tp @b USE_BASIS_UTILITIES @endtp 651 # <td>Specify that the BASIS utilities are used and required by this MEX-file 652 # and hence a link dependency on the BASIS utilities must be added. 653 # (default: @c BASIS_UTILITIES)</td> 656 # @tp @b FINAL @endtp 657 # <td>Finalize custom targets immediately. Any following target property changes 658 # will have no effect. When this option is used, the custom target which 659 # executes the custom build command is added in the current working directory. 660 # Otherwise it will be added in the top-level source directory of the project. 661 # Which with the Visual Studio generators adds the corresponding Visual Studio 662 # Project files directly to the top-level build directory. This can be avoided 663 # using this option or calling basis_finalize_targets() at the end of each 664 # CMakeLists.txt file.</td> 668 # @returns Adds custom target to build MEX-file using the MEX script. 670 # @sa basis_add_library() 672 # @ingroup CMakeUtilities 677 message (STATUS
"Adding MEX-file ${TARGET_UID}...")
678 # required commands available ? 679 if (NOT MATLAB_MEX_EXECUTABLE)
680 message (FATAL_ERROR
"MATLAB MEX script (mex) not found! It is required to build target ${TARGET_UID}." 681 " Forgot to add MATLAB{mex} as dependency? Otherwise, set MATLAB_MEX_EXECUTABLE manually and try again.")
685 CMAKE_PARSE_ARGUMENTS (
687 "USE_BASIS_UTILITIES;NO_BASIS_UTILITIES;EXPORT;NOEXPORT;FINAL" 688 "COMPONENT;DESTINATION" 692 set (
SOURCES ${ARGN_UNPARSED_ARGUMENTS})
694 if (ARGN_USE_BASIS_UTILITIES AND ARGN_NO_BASIS_UTILITIES)
695 message (FATAL_ERROR
"Target ${TARGET_UID}: Options USE_BASIS_UTILITIES and NO_BASIS_UTILITIES are mutually exclusive!")
697 if (ARGN_USE_BASIS_UTILITIES)
698 set (USES_BASIS_UTILITIES TRUE)
699 elseif (ARGN_NO_BASIS_UTILITIES)
700 set (USES_BASIS_UTILITIES FALSE)
707 if (CMAKE_CURRENT_SOURCE_DIR MATCHES
"^${RE}")
712 # installation component 713 if (NOT ARGN_COMPONENT)
714 set (ARGN_COMPONENT
"${BASIS_LIBRARY_COMPONENT}")
716 if (NOT ARGN_COMPONENT)
717 set (ARGN_COMPONENT
"Unspecified")
719 # installation directory 720 if (ARGN_DESTINATION)
721 if (ARGN_DESTINATION MATCHES
"^[nN][oO][nN][eE]$")
722 set (ARGN_DESTINATION)
723 elseif (IS_ABSOLUTE
"${ARGN_DESTINATION}")
724 file (RELATIVE_PATH ARGN_DESTINATION
"${CMAKE_INSTALL_PREFIX}" "${ARGN_DESTINATION}")
727 set (ARGN_DESTINATION
"${INSTALL_MATLAB_LIBRARY_DIR}")
729 # configure (.in) source files 733 get_directory_property (INCLUDE_DIRS INCLUDE_DIRECTORIES)
734 get_directory_property (LINK_DIRS LINK_DIRECTORIES)
736 list (INSERT LINK_DIRS 0
"${MATLAB_LIBRARY_DIR}")
744 BASIS_INCLUDE_DIRECTORIES
"${INCLUDE_DIRS}" 745 BASIS_LINK_DIRECTORIES
"${LINK_DIRS}" 746 BUILD_DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TARGET_UID}" 747 SOURCE_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}" 748 BINARY_DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}" 749 LIBRARY_OUTPUT_DIRECTORY
"${BINARY_MATLAB_LIBRARY_DIR}" 750 LIBRARY_INSTALL_DIRECTORY
"${ARGN_DESTINATION}" 751 LIBRARY_COMPONENT
"${ARGN_COMPONENT}" 752 COMPILE_FLAGS
"${BASIS_MEX_FLAGS}" 754 LINK_DEPENDS
"${LINK_DEPENDS}" 762 # link to BASIS utilities
763 if (USES_BASIS_UTILITIES)
770 # add target to list of targets 772 message (STATUS
"Adding MEX-file ${TARGET_UID}... - done")
775 # ============================================================================ 776 # MATLAB Compiler target 777 # ============================================================================ 779 # ---------------------------------------------------------------------------- 780 ## @brief Add MATLAB Compiler target. 782 # @note This function should not be used directly. Instead, it is called 783 # by either basis_add_executable() or basis_add_library() if the 784 # (detected) programming language of the given source code files is 787 # This function is used to add an executable or shared library target which is 788 # built using the MATLAB Compiler (MCC). 790 # A custom CMake build target with the following properties is added by this 791 # function to the build system. These properties are used by 792 # basis_build_mcc_target() to generate a build script written in CMake 793 # code which is executed by a custom CMake command. Before the invokation of 794 # basis_build_mcc_target(), the target properties can be modified using 795 # basis_set_target_properties(). 797 # @note Custom BASIS build targets are finalized by BASIS using basis_project_end(), 798 # i.e., the end of the root CMake configuration file of the (sub-)project. 800 # @par Properties on MATLAB Compiler targets 802 # <tr><td>TODO</td></tr> 805 # An install command for the added executable or library target is added by 806 # this function as well. The executable will be installed as part of the 807 # @p RUNTIME_COMPONENT in the directory @c INSTALL_RUNTIME_DIR. The runtime 808 # library will be installed as part of the @p RUNTIME_COMPONENT in the directory 809 # @c INSTALL_LIBRARY_DIR on Unix and @c INSTALL_RUNTIME_DIR on Windows. 810 # Static/import libraries will be installed as part of the @p LIBRARY_COMPONENT 811 # in the directory @c INSTALL_ARCHIVE_DIR. 813 # @note If this function is used within the @c PROJECT_TESTING_DIR, the built 814 # executable is output to the @c BINARY_TESTING_DIR directory tree instead. 815 # Moreover, no installation rules are added. Test executables are further 816 # not exported, regardless of the value of the @c EXPORT property. 818 # @param [in] TARGET_NAME Name of build target. 819 # @param [in] ARGN The remaining arguments are parsed and the following 820 # arguments extracted. All unparsed arguments are treated 821 # as the MATLAB or C/C++ source files, respectively. 825 # @tp <b>EXECUTABLE</b>|<b>LIBEXEC</b>|<b>SHARED</b> @endtp 826 # <td>Type of the MATLAB Compiler target which can be either a stand-alone 827 # executable, an auxiliary executable, or a shared library. 828 # (default: @c EXECUTABLE)</td> 831 # @tp @b COMPONENT name @endtp 832 # <td>Name of component as part of which this executable or library will be 833 # installed if the @c RUNTIME_INSTALL_DIRECTORY or @c LIBRARY_INSTALL_DIRECTORY 834 # property is not "none". Used only if @p RUNTIME_COMPONENT or 835 # @p LIBRARY_COMPONENT not specified. 836 # (default: see @p RUNTIME_COMPONENT and @p LIBRARY_COMPONENT arguments)</td> 839 # @tp @b DESTINATION dir @endtp 840 # <td>Installation directory for executable or runtime and library component 841 # of shared library relative to @c CMAKE_INSTALL_PREFIX. Used only if 842 # @p RUNTIME_DESTINATION or @p LIBRARY_DESTINATION not specified. 843 # If "none" (case-insensitive) is given as argument, no default installation 844 # rules are added. (default: see @p RUNTIME_DESTINATION and 845 # @p LIBRARY_DESTINATION arguments)</td> 848 # @tp @b LIBRARY_COMPONENT name @endtp 849 # <td>Name of component as part of which import/static library will be intalled 850 # if a shared library is build and the @c LIBRARY_INSTALL_DIRECTORY property is 851 # not "none". (default: @c COMPONENT if specified or @c BASIS_LIBRARY_COMPONENT 855 # @tp @b LIBRARY_DESTINATION dir @endtp 856 # <td>Installation directory of the library component relative to 857 # @c CMAKE_INSTALL_PREFIX. If "none" (case-insensitive) is given as argument or 858 # an executable is build, no installation rule for the library component is added. 859 # (default: @c INSTALL_ARCHIVE_DIR)</td> 862 # @tp @b HEADER_DESTINATION dir @endtp 863 # <td>Installation directory of the library header file relative to 864 # @c INSTALL_INCLUDE_DIR. If "none" (case-insensitive) is given as argument or 865 # an executable is build, no installation rule for the library header file is added. 866 # (default: @c INSTALL_INCLUDE_DIR)</td> 869 # @tp @b RUNTIME_COMPONENT name @endtp 870 # <td>Name of component as part of which executable or runtime library, respectively, 871 # will be installed if the @c RUNTIME_INSTALL_DIRECTORY property is not "none". 872 # (default: @c COMPONENT if specified or @c BASIS_RUNTIME_COMPONENT otherwise)</td> 875 # @tp @b RUNTIME_DESTINATION dir @endtp 876 # <td>Installation directory of the executable or runtime component of the shared library 877 # relative to @c CMAKE_INSTALL_PREFIX. If "none" (case-insensitive) is given as argument, 878 # no installation rule for the runtime library is added. 879 # (default: @c INSTALL_LIBRARY_DIR for shared libraries on Unix or 880 # @c INSTALL_RUNTIME_DIR otherwise)</td> 883 # @tp @b [NO]EXPORT @endtp 884 # <td>Whether to export this target. (default: @c TRUE)</td> 887 # @tp @b NO_BASIS_UTILITIES @endtp 888 # <td>Specify that the BASIS utilities are not used by this executable or shared library 889 # and hence no link dependency on the BASIS utilities shall be added. 890 # (default: @c NOT BASIS_UTILITIES)</td> 893 # @tp @b USE_BASIS_UTILITIES @endtp 894 # <td>Specify that the BASIS utilities are used and required by this executable 895 # or shared library, respectively, and hence a link dependency on the BASIS utilities 897 # (default: @c BASIS_UTILITIES)</td> 900 # @tp @b FINAL @endtp 901 # <td>Finalize custom targets immediately. Any following target property changes 902 # will have no effect. When this option is used, the custom target which 903 # executes the custom build command is added in the current working directory. 904 # Otherwise it will be added in the top-level source directory of the project. 905 # Which with the Visual Studio generators adds the corresponding Visual Studio 906 # Project files directly to the top-level build directory. This can be avoided 907 # using this option or calling basis_finalize_targets() at the end of each 908 # CMakeLists.txt file.</td> 912 # @todo Consider NO_BASIS_UTILITIES and USE_BASIS_UTILITIES options after the BASIS 913 # utilities for MATLAB have been implemented. 915 # @returns Adds custom target which builds depending on the @p BASIS_TYPE property 916 # either an executable or a shared library using the MATLAB Compiler. 918 # @sa basis_add_executable() 919 # @sa basis_add_library() 921 # @ingroup CMakeUtilities 927 CMAKE_PARSE_ARGUMENTS (
929 "SHARED;EXECUTABLE;LIBEXEC;USE_BASIS_UTILITIES;NO_BASIS_UTILITIES;EXPORT;NOEXPORT;FINAL" 930 "COMPONENT;RUNTIME_COMPONENT;LIBRARY_COMPONENT;DESTINATION;RUNTIME_DESTINATION;LIBRARY_DESTINATION;HEADER_DESTINATION" 934 set (
SOURCES "${ARGN_UNPARSED_ARGUMENTS}")
936 if (ARGN_USE_BASIS_UTILITIES AND ARGN_NO_BASIS_UTILITIES)
937 message (FATAL_ERROR
"Target ${TARGET_UID}: Options USE_BASIS_UTILITIES and NO_BASIS_UTILITIES are mutually exclusive!")
939 if (ARGN_USE_BASIS_UTILITIES)
940 set (USES_BASIS_UTILITIES TRUE)
941 elseif (ARGN_NO_BASIS_UTILITIES)
942 set (USES_BASIS_UTILITIES FALSE)
946 if (ARGN_SHARED AND (ARGN_EXECUTABLE OR ARGN_LIBEXEC))
947 message (FATAL_ERROR
"Target ${TARGET_UID}: Options SHARED and EXECUTABLE or LIBEXEC are mutually exclusive!")
952 set (TYPE EXECUTABLE)
954 string (TOLOWER
"${TYPE}" type)
955 message (STATUS
"Adding MATLAB ${type} ${TARGET_UID}...")
958 if (CMAKE_CURRENT_SOURCE_DIR MATCHES
"^${RE}")
965 set (LIBRARY_OUTPUT_DIRECTORY
"${TESTING_LIBRARY_DIR}")
967 set (RUNTIME_OUTPUT_DIRECTORY
"${TESTING_LIBEXEC_DIR}")
969 set (RUNTIME_OUTPUT_DIRECTORY
"${TESTING_RUNTIME_DIR}")
972 set (LIBRARY_OUTPUT_DIRECTORY
"${BINARY_LIBRARY_DIR}")
974 set (RUNTIME_OUTPUT_DIRECTORY
"${BINARY_LIBEXEC_DIR}")
976 set (RUNTIME_OUTPUT_DIRECTORY
"${BINARY_RUNTIME_DIR}")
979 # installation component 981 if (NOT ARGN_LIBRARY_COMPONENT)
982 set (ARGN_LIBRARY_COMPONENT
"${ARGN_COMPONENT}")
984 if (NOT ARGN_RUNTIME_COMPONENT)
985 set (ARGN_RUNTIME_COMPONENT
"${ARGN_COMPONENT}")
988 if (NOT ARGN_RUNTIME_COMPONENT)
989 set (ARGN_RUNTIME_COMPONENT
"${BASIS_RUNTIME_COMPONENT}")
991 if (NOT ARGN_RUNTIME_COMPONENT)
992 set (ARGN_RUNTIME_COMPONENT
"Unspecified")
994 if (NOT ARGN_LIBRARY_COMPONENT)
995 set (ARGN_LIBRARY_COMPONENT
"${BASIS_LIBRARY_COMPONENT}")
997 if (NOT ARGN_LIBRARY_COMPONENT)
998 set (ARGN_LIBRARY_COMPONENT
"Unspecified")
1000 # installation directories 1001 if (ARGN_DESTINATION)
1002 if (NOT ARGN_RUNTIME_DESTINATION)
1003 set (ARGN_RUNTIME_DESTINATION
"${ARGN_DESTINATION}")
1005 if (NOT ARGN_LIBRARY_DESTINATION)
1006 set (ARGN_LIBRARY_DESTINATION
"${ARGN_DESTINATION}")
1008 if (NOT ARGN_HEADER_DESTINATION)
1009 set (ARGN_HEADER_DESTINATION
"${ARGN_DESTINATION}")
1012 if (NOT ARGN_RUNTIME_DESTINATION AND NOT IS_TEST)
1014 set (ARGN_RUNTIME_DESTINATION
"${INSTALL_LIBEXEC_DIR}")
1016 set (ARGN_RUNTIME_DESTINATION
"${INSTALL_RUNTIME_DIR}")
1019 if (NOT ARGN_LIBRARY_DESTINATION AND NOT IS_TEST)
1020 set (ARGN_LIBRARY_DESTINATION
"${INSTALL_LIBRARY_DIR}")
1022 if (NOT ARGN_HEADER_DESTINATION AND NOT IS_TEST)
1023 set (ARGN_HEADER_DESTINATION
".")
1025 if (ARGN_RUNTIME_DESTINATION MATCHES
"^[nN][oO][nN][eE]$")
1026 set (ARGN_RUNTIME_DESTINATION)
1028 if (ARGN_LIBRARY_DESTINATION MATCHES
"^[nN][oO][nN][eE]$")
1029 set (ARGN_LIBRARY_DESTINATION)
1031 if (ARGN_HEADER_DESTINATION MATCHES
"^[nN][oO][nN][eE]$")
1032 set (ARGN_HEADER_DESTINATION)
1033 elseif (NOT IS_ABSOLUTE ARGN_HEADER_DESTINATION)
1034 set (ARGN_HEADER_DESTINATION
"${BINARY_INCLUDE_DIR}/${ARGN_HEADER_DESTINATION}")
1036 # whether to compile and compilation flags (for mcc) 1037 if (
"^${TYPE}$" STREQUAL
"^LIBRARY$")
1040 if (MATLAB_MCC_EXECUTABLE)
1044 message (WARNING
"MATLAB Compiler not found. Will generate a wrapper script for target" 1045 " ${TARGET_UID} which executes the MATLAB code using the -r option of" 1046 " the MATLAB interpreter. It is recommended to compile the MATLAB code" 1047 " using the MATLAB Compiler if possible, however. Therefore, make sure" 1048 " that the MATLAB Compiler is available and check the value of the" 1049 " advanced MATLAB_MCC_EXECUTABLE variable in CMake." 1050 "\nMake sure to include MATLAB{mcc} as project dependency.")
1055 if (WIN32 AND NOT COMPILE)
1056 # TODO implement generation of Windows Command on Windows 1058 if (PROJECT_CONTACT)
1059 set (
CONTACT "\n\nYou may further want to contact ${PROJECT_CONTACT} in order to ask" 1060 " for a binary distribution package which contains pre-build binaries" 1061 " created using the MATLAB Compiler and download the MATLAB Compiler" 1062 " Runtime only if no MATLAB Compiler license is available to you.")
1068 message (FATAL_ERROR
"The optional generation of a Windows Command which executes" 1069 " the MATLAB code using the -r option of the MATLAB interpreter" 1070 " as an alternative to the build of the MATLAB sources using" 1071 " the MATLAB Compiler is not yet implemented. You will have" 1072 " to obtain a MATLAB Compiler license and set the advanced" 1073 " MATLAB_MCC_EXECUTABLE variable in CMake or use this package" 1074 " on a Unix system instead.${CONTACT}")
1077 if (NOT MATLAB_MCC_EXECUTABLE)
1078 message (FATAL_ERROR
"MATLAB Compiler not found! It is required to build target ${TARGET_UID}." 1079 " Ensure that MATLAB{mcc} is declared as project dependency" 1080 " and check the setting of MATLAB_DIR and/or MATLAB_MCC_EXECUTABLE.")
1084 if (NOT MATLAB_EXECUTABLE)
1085 message (FATAL_ERROR
"MATLAB not found! It is required to build target ${TARGET_UID}." 1086 " Ensure that MATLAB{matlab} is declared as project dependency" 1087 " and check the setting of MATLAB_DIR and/or MATLAB_EXECUTABLE.")
1090 if (
"^${TYPE}$" STREQUAL
"^EXECUTABLE$")
1091 set (COMPILE_FLAGS
"${BASIS_MCC_FLAGS}")
1093 set (COMPILE_FLAGS
"")
1095 # output file name prefix/suffix 1096 if (
"^${TYPE}$" STREQUAL
"^EXECUTABLE$")
1098 if (WIN32 AND
"^${COMPILE_FLAGS}$" STREQUAL
"^NOMCC$")
1106 set (SUFFIX .lib) # link library file extension
1115 # configure (.in) source files 1120 get_directory_property (INCLUDE_DIRS INCLUDE_DIRECTORIES)
1121 get_directory_property (LINK_DIRS LINK_DIRECTORIES)
1126 BASIS_TYPE
"MCC_${TYPE}" 1128 BASIS_INCLUDE_DIRECTORIES
"${INCLUDE_DIRS}" 1129 BASIS_LINK_DIRECTORIES
"${LINK_DIRS}" 1130 BUILD_DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TARGET_UID}" 1131 SOURCE_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}" 1132 BINARY_DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}" 1133 LIBRARY_OUTPUT_DIRECTORY
"${LIBRARY_OUTPUT_DIRECTORY}" 1134 LIBRARY_INSTALL_DIRECTORY
"${ARGN_LIBRARY_DESTINATION}" 1135 LIBRARY_HEADER_DIRECTORY
"${ARGN_HEADER_DESTINATION}" 1136 LIBRARY_COMPONENT
"${ARGN_LIBRARY_COMPONENT}" 1137 RUNTIME_OUTPUT_DIRECTORY
"${RUNTIME_OUTPUT_DIRECTORY}" 1138 RUNTIME_INSTALL_DIRECTORY
"${ARGN_RUNTIME_DESTINATION}" 1139 RUNTIME_COMPONENT
"${ARGN_RUNTIME_COMPONENT}" 1141 OUTPUT_NAME
"${OUTPUT_NAME}" 1143 COMPILE_FLAGS
"${COMPILE_FLAGS}" 1144 COMPILE
"${COMPILE}" 1147 LIBEXEC ${ARGN_LIBEXEC}
1154 # add target to list of targets 1156 message (STATUS
"Adding MATLAB ${type} ${TARGET_UID}... - done")
1159 # ============================================================================ 1160 # custom build commands 1161 # ============================================================================ 1163 # ---------------------------------------------------------------------------- 1164 ## @brief Add custom command for build of MEX-file. 1166 # This function is called by basis_finalize_targets() which in turn is called 1167 # by basis_project_end(), i.e., the end of the root CMake configuration file 1168 # of the (sub-)project. 1170 # @param [in] TARGET_UID Name/UID of custom target added by basis_add_mex_file(). 1172 # @sa basis_add_mex_file() 1174 # @ingroup CMakeUtilities 1176 # does
this target exist ?
1178 if (NOT TARGET
"${TARGET_UID}")
1179 message (FATAL_ERROR
"Unknown build target: ${TARGET_UID}")
1182 message (STATUS
"Adding build command for target ${TARGET_UID}...")
1184 # get target properties 1190 BASIS_INCLUDE_DIRECTORIES
1191 BASIS_LINK_DIRECTORIES
1195 LIBRARY_OUTPUT_DIRECTORY
1196 LIBRARY_INSTALL_DIRECTORY
1208 get_target_property (IS_TEST ${TARGET_UID} TEST)
1209 foreach (PROPERTY ${PROPERTIES})
1210 get_target_property (${PROPERTY} ${TARGET_UID} ${PROPERTY})
1211 if (NOT ${PROPERTY})
1215 # sanity check of property values 1216 if (NOT BASIS_TYPE MATCHES
"^MEX$")
1217 message (FATAL_ERROR
"Target ${TARGET_UID}: Invalid BASIS_TYPE: ${BASIS_TYPE}")
1219 list (GET SOURCES 0 BUILD_DIR)
# CMake <3.1 stores path to internal build directory here 1220 if (BUILD_DIR MATCHES
"CMakeFiles")
1221 list (REMOVE_AT SOURCES 0)
1223 set (BUILD_DIR
"${BUILD_DIRECTORY}.dir")
1225 message (FATAL_ERROR
"Target ${TARGET_UID}: Empty SOURCES list!" 1226 " Have you accidentally modified this read-only property or" 1227 " is your (newer) CMake version not compatible with BASIS?")
1229 if (NOT LIBRARY_COMPONENT)
1230 set (LIBRARY_COMPONENT
"Unspecified")
1233 if (NOT IS_ABSOLUTE
"${MFILE}")
1234 set (MFILE
"${SOURCE_DIRECTORY}/${MFILE}")
1236 if (NOT EXISTS
"${MFILE}")
1237 message (FATAL_ERROR
"M-file ${MFILE} of MEX-file target ${TARGET_UID} does not exist!")
1241 if (NOT OUTPUT_NAME)
1242 set (OUTPUT_NAME
"${TARGET_NAME}")
1245 set (OUTPUT_NAME
"${OUTPUT_NAME}${SUFFIX}")
1247 string (REGEX REPLACE
"/+" "/" PREFIX
"${PREFIX}")
1248 string (REGEX REPLACE
"/$" "" PREFIX
"${PREFIX}")
1249 if (PREFIX AND NOT PREFIX MATCHES
"^/")
1250 set (PREFIX
"/${PREFIX}")
1252 # initialize dependencies of custom build command 1253 set (DEPENDS ${SOURCES})
1254 #
get list of libraries to link to
1256 foreach (LIB ${LINK_DEPENDS})
1260 string (REPLACE
"<${BASIS_GE_CONFIG}>" "{CONFIG}" LIB_FILE
"${LIB_FILE}")
1261 list (APPEND DEPENDS ${UID})
1263 set (LIB_FILE
"${LIB}")
1265 list (APPEND LINK_LIBS
"${LIB_FILE}")
1268 # decompose user supplied MEX switches 1270 string (REGEX REPLACE
"${VAR}=\"([^\"]+)\"|${VAR}=([^\" ])*" "" COMPILE_FLAGS
"${COMPILE_FLAGS}")
1272 set (${VAR}
"${CMAKE_MATCH_1}")
1273 elseif (CMAKE_MATCH_2)
1274 set (${VAR}
"${CMAKE_MATCH_2}")
1289 extract (LDCXXFLAGS)
1293 # set defaults for not provided options 1295 set (CC
"${CMAKE_C_COMPILER}")
1298 set (CFLAGS
"${CMAKE_C_FLAGS}")
1300 if (NOT CFLAGS MATCHES
"( |^)-fPIC( |$)")
1301 set (CFLAGS
"-fPIC ${CFLAGS}")
1304 set (CXX
"${CMAKE_CXX_COMPILER}")
1307 set (CXXFLAGS
"${CMAKE_CXX_FLAGS}")
1309 if (NOT CXXFLAGS MATCHES
"( |^)-fPIC( |$)")
1310 set (CXXFLAGS
"-fPIC ${CXXFLAGS}")
1313 set (LD
"${CMAKE_CXX_COMPILER}") #
do not use CMAKE_LINKER here
1316 set (LDFLAGS
"\$LDFLAGS ${CMAKE_SHARED_LINKER_FLAGS}")
1318 # We chose to use CLIBS and CXXLIBS instead of the -L and -l switches 1319 # to add also link libraries added via basis_target_link_libraries() 1320 # because the MEX script will not use these arguments if CLIBS or CXXLIBS 1321 # is set. Moreover, the -l switch can only be used to link to a shared 1322 # library and not a static one (on UNIX). 1323 #foreach (LIB ${LINK_LIBS}) 1324 # if (LIB MATCHES "[/\\\.]") 1325 # set (CXXLIBS "${CXXLIBS} ${LIB}") 1329 # get remaining switches 1331 # assemble MEX switches 1334 list (APPEND MEX_ARGS
"CC=${CC}" "CFLAGS=${CFLAGS}")
# C compiler and flags 1336 list (APPEND MEX_ARGS
"CLIBS=${CLIBS}")
# C link libraries 1338 list (APPEND MEX_ARGS "CXX=${CXX}
" "CXXFLAGS=${CXXFLAGS}
") # C++ compiler and flags 1340 list (APPEND MEX_ARGS "CXXLIBS=${CXXLIBS}
") # C++ link libraries 1343 list (APPEND MEX_ARGS "LD=${LD}
") # C linker 1346 list (APPEND MEX_ARGS "LDFLAGS=${LDFLAGS}
") # C link flags 1349 list (APPEND MEX_ARGS "LDCXX=${LDCXX}
") # C++ linker 1352 list (APPEND MEX_ARGS "LDCXXFLAGS=${LDCXXFLAGS}
") # C++ link flags 1355 list (APPEND MEX_ARGS "-outdir
" "${BUILD_DIR}
") # output directory 1356 list (APPEND MEX_ARGS "-output
" "${OUTPUT_NAME_WE}
") # output name (w/o extension) 1357 foreach (INCLUDE_PATH ${BASIS_INCLUDE_DIRECTORIES}) # include directories 1358 list (FIND MEX_ARGS "-I${INCLUDE_PATH}
" IDX) # as specified via 1359 if (INCLUDE_PATH AND IDX EQUAL -1) # basis_include_directories() 1360 list (APPEND MEX_ARGS "-I${INCLUDE_PATH}
") 1365 foreach (LINK_DIR ${BASIS_LINK_DIRECTORIES}) # link directories 1367 string (REPLACE "/
" "\\
" LINK_DIR "${
LINK_DIR}
") 1368 set (LINK_DIR "/LIBPATH:\\\
"${LINK_DIR}\\\"")
1372 list (APPEND MEX_LIBPATH "${
LINK_DIR}
") # as specified via basis_link_directories() 1374 foreach (LIBRARY ${LINK_LIBS}) # link libraries 1375 get_filename_component (LINK_DIR "${LIBRARY}
" PATH) # as specified via basis_target_link_libraries() 1376 get_filename_component (LINK_LIB "${LIBRARY}
" NAME) 1377 string (REGEX REPLACE "\\.(so|dylib)(\\.[0-9]+)*$
" "" LINK_LIB "${
LINK_LIB}
") 1378 if (CMAKE_SYSTEM_NAME MATCHES "Darwin
") 1379 # cf. https://github.com/cmake-basis/BASIS/issues/443 1380 string (REGEX REPLACE "\\.a(\\.[0-9]+)*$
" "" LINK_LIB "${
LINK_LIB}
") 1382 string (REGEX REPLACE "^-l
" "" LINK_LIB "${
LINK_LIB}
") 1385 string (REPLACE "/
" "\\
" LINK_DIR "${
LINK_DIR}
") 1386 set (LINK_DIR "/LIBPATH:\\\
"${LINK_DIR}\\\"")
1390 list (APPEND MEX_LIBPATH
"${LINK_DIR}")
1393 if (NOT
LINK_LIB MATCHES
"\\.lib$")
1397 string (REGEX REPLACE
"^lib" "" LINK_LIB "${LINK_LIB}")
1400 list (APPEND MEX_LIBS
"${LINK_LIB}")
1403 list (REMOVE_DUPLICATES MEX_LIBPATH)
1405 # do not remove duplicate entries in MEX_LIBS which may be needed 1406 # to resolve (cyclic) dependencies between statically linked libraries 1407 # (cf. https://github.com/cmake-basis/BASIS/issues/444) 1408 if (MEX_LIBPATH OR MEX_LIBS)
1412 list (APPEND MEX_ARGS
"LINKFLAGS#$LINKFLAGS ${MEX_LIBPATH} ${MEX_LIBS}")
1414 list (APPEND MEX_ARGS ${MEX_LIBPATH} ${MEX_LIBS})
1417 # other user switches 1418 list (APPEND MEX_ARGS ${MEX_USER_ARGS})
1420 list (APPEND MEX_ARGS ${SOURCES})
1421 # build command
for invocation of MEX script
1428 set (
BUILD_MFILE "${LIBRARY_OUTPUT_DIRECTORY}${PREFIX}/${OUTPUT_NAME_WE}.m")
1433 # configure build script 1434 configure_file (
"${BASIS_SCRIPT_EXECUTE_PROCESS}" "${BUILD_SCRIPT}" @ONLY)
1435 # relative paths used for comments of commands 1436 file (RELATIVE_PATH REL
"${CMAKE_BINARY_DIR}" "${BUILD_OUTPUT}")
1437 # add custom command to build executable using MEX script 1438 add_custom_command (
1439 OUTPUT
"${BUILD_OUTPUT}" 1440 # rebuild when input sources were modified
1441 DEPENDS
"${BUILD_SCRIPT}" "${CMAKE_CURRENT_LIST_FILE}" ${DEPENDS}
1442 # invoke MEX script, wrapping the command in CMake execute_process() 1443 # command allows for inspection of command output for error messages 1444 # and specification of timeout 1446 "-DCONFIG=$<${BASIS_GE_CONFIG}>" 1447 "-DWORKING_DIRECTORY=${BUILD_DIR}" 1448 "-DTIMEOUT=${BASIS_MEX_TIMEOUT}" 1449 "-DERROR_EXPRESSION=[E|e]rror:" 1450 "-DOUTPUT_FILE=${BUILD_LOG}" 1451 "-DERROR_FILE=${BUILD_LOG}" 1454 "-P" "${BUILD_SCRIPT}" 1455 # post-build command 1456 COMMAND "${CMAKE_COMMAND}" -E copy
"${BUILD_DIR}/${OUTPUT_NAME}" "${BUILD_OUTPUT}" 1457 COMMAND "${CMAKE_COMMAND}" -E
remove "${BUILD_DIR}/${OUTPUT_NAME}" 1458 # inform user where build log can be found 1459 COMMAND "${CMAKE_COMMAND}" -E echo
"Build log written to ${BUILD_LOG}" 1461 COMMENT
"Building MEX-file ${REL}..." 1465 add_custom_command (
1466 OUTPUT
"${BUILD_MFILE}" 1468 COMMAND "${CMAKE_COMMAND}" -E copy
"${MFILE}" "${BUILD_MFILE}" 1469 COMMENT
"Copying M-file of ${REL}..." 1473 add_custom_target (_${TARGET_UID} DEPENDS ${BUILD_OUTPUTS} SOURCES ${SOURCES})
1474 add_dependencies (${TARGET_UID} _${TARGET_UID})
1475 # cleanup on
"make clean" 1479 ADDITIONAL_MAKE_CLEAN_FILES
1480 "${BUILD_DIR}/${OUTPUT_NAME}" 1489 if (LIBRARY_INSTALL_DIRECTORY)
1491 FILES ${BUILD_OUTPUTS}
1492 DESTINATION
"${LIBRARY_INSTALL_DIRECTORY}${PREFIX}" 1493 COMPONENT
"${LIBRARY_COMPONENT}" 1497 message (STATUS
"Adding build command for target ${TARGET_UID}... - done")
1501 # ---------------------------------------------------------------------------- 1502 ## @brief Add custom command for build of MATLAB Compiler target. 1504 # This function is called by basis_finalize_targets() which in turn is called 1505 # by basis_project_end(), i.e., the end of the root CMake configuration file 1506 # of the (sub-)project. 1508 # @param [in] TARGET_UID Name/UID of custom target added by basis_add_mcc_target(). 1510 # @sa basis_add_mcc_target() 1512 # @ingroup CMakeUtilities 1514 # does
this target exist ?
1516 if (NOT TARGET
"${TARGET_UID}")
1517 message (FATAL_ERROR
"Unknown target ${TARGET_UID}!")
1520 message (STATUS
"Adding build command for target ${TARGET_UID}...")
1522 # get target properties 1528 BASIS_INCLUDE_DIRECTORIES
1529 BASIS_LINK_DIRECTORIES
1533 LIBRARY_OUTPUT_DIRECTORY
1534 LIBRARY_INSTALL_DIRECTORY
1535 LIBRARY_HEADER_DIRECTORY
1537 RUNTIME_OUTPUT_DIRECTORY
1538 RUNTIME_INSTALL_DIRECTORY
1549 get_target_property (IS_TEST ${TARGET_UID} TEST)
1550 foreach (PROPERTY ${PROPERTIES})
1551 get_target_property (${PROPERTY} ${TARGET_UID} ${PROPERTY})
1552 if (NOT ${PROPERTY})
1556 # sanity checks of property values 1557 set (EXECUTABLE FALSE)
1560 if (BASIS_TYPE MATCHES
"^MCC_(EXECUTABLE|LIBEXEC|LIBRARY)$")
1561 set (${CMAKE_MATCH_1} TRUE)
1563 set (EXECUTABLE TRUE)
1566 message (FATAL_ERROR
"Target ${TARGET_UID}: Invalid BASIS_TYPE: ${BASIS_TYPE}")
1568 list (GET SOURCES 0 BUILD_DIR)
# CMake <3.1 stores path to internal build directory here 1569 if (BUILD_DIR MATCHES
"CMakeFiles")
1570 list (REMOVE_AT SOURCES 0)
1572 set (BUILD_DIR
"${BUILD_DIRECTORY}.dir")
1574 message (FATAL_ERROR
"Target ${TARGET_UID}: Empty SOURCES list!" 1575 " Have you accidentally modified this read-only property or" 1576 " is your (newer) CMake version not compatible with BASIS?")
1578 list (GET SOURCES 0 MAIN_SOURCE)
# entry point 1579 if (NOT RUNTIME_COMPONENT)
1580 set (RUNTIME_COMPONENT
"Unspecified")
1582 if (NOT LIBRARY_COMPONENT)
1583 set (LIBRARY_COMPONENT
"Unspecified")
1586 if (NOT OUTPUT_NAME)
1587 set (OUTPUT_NAME
"${TARGET_NAME}")
1590 set (OUTPUT_NAME
"${PREFIX}${OUTPUT_NAME}")
1593 set (OUTPUT_NAME
"${OUTPUT_NAME}${SUFFIX}")
1596 # MCC only allows alpha-numeric characters and underscores 1597 # TODO: Figure out how to build a shared library without this restriction 1598 # (cf. https://github.com/cmake-basis/BASIS/issues/410). 1599 if (NOT OUTPUT_NAME MATCHES
"[a-zA-Z][_a-zA-Z0-9]*")
1600 message (FATAL_ERROR
"Target ${TARGET_UID} has invalid output name ${OUTPUT_NAME}." 1601 "MCC only allows alpha-numeric characters and underscores. " 1602 "See GitHub issue #410 for updates on this restriction at\n" 1603 "https://github.com/cmake-basis/BASIS/issues/410")
1605 set (MCC_OUTPUT_NAME
"${OUTPUT_NAME}")
1606 set (MCC_OUTPUT_NAME_WE
"${OUTPUT_NAME_WE}")
1607 #string (REGEX REPLACE "\\+|-" "_" MCC_OUTPUT_NAME "${OUTPUT_NAME}") 1608 #get_filename_component (MCC_OUTPUT_NAME_WE "${MCC_OUTPUT_NAME}" NAME_WE) 1609 # initialize dependencies of custom build command 1610 set (DEPENDS ${SOURCES})
1611 # build output file and comment
1612 file (RELATIVE_PATH REL
"${CMAKE_BINARY_DIR}" "${BUILD_DIR}/${OUTPUT_NAME}")
1614 set (
BUILD_OUTPUT "${LIBRARY_OUTPUT_DIRECTORY}/${OUTPUT_NAME}")
1615 set (BUILD_COMMENT
"Building MATLAB library ${REL}...")
1617 set (
BUILD_OUTPUT "${RUNTIME_OUTPUT_DIRECTORY}/${OUTPUT_NAME}")
1618 set (BUILD_COMMENT
"Building MATLAB executable ${REL}...")
1620 # -------------------------------------------------------------------------- 1621 # assemble build command for build of executable wrapper script 1622 if (EXECUTABLE AND NOT COMPILE)
1623 # used to recognize source files which are located in the build tree 1625 # main MATLAB function and search path 1629 if (SOURCE_PACKAGE MATCHES
"^\\+")
1631 set (MATLAB_COMMAND
"${SOURCE_PACKAGE}.${MATLAB_COMMAND}")
1632 string (REGEX REPLACE
"^\\+" "" MATLAB_COMMAND
"${MATLAB_COMMAND}")
1634 set (SOURCE_PACKAGE
"${MATLAB_COMMAND}")
1637 set (BINARY_DIR
"${PROJECT_BINARY_DIR}/${DIR}") # location of configured sources
1639 set (OUTPUT_FILE
"${BUILD_OUTPUT}")
1642 set (INSTALL_FILE
"${BUILD_DIR}/${OUTPUT_NAME}") # file to be installed
1643 set (INSTALL_DIR
"${CMAKE_INSTALL_PREFIX}/${RUNTIME_INSTALL_DIRECTORY}") # location of installed wrapper
1644 set (INSTALL_SOURCE_DIR
"${INSTALL_MATLAB_LIBRARY_DIR}") # location of installed MATLAB sources
1645 if (NOT SOURCE_PACKAGE MATCHES
"^\\+")
1646 set (INSTALL_SOURCE_DIR
"${INSTALL_SOURCE_DIR}/${SOURCE_PACKAGE}")
1649 if (SOURCE_PACKAGE MATCHES
"^\\+")
1650 set (BUILD_STARTUP_FILE
"${BINARY_DIR}/${SOURCE_PACKAGE}/startup.m")
1651 set (INSTALL_STARTUP_FILE
"${BUILD_DIR}/startup.m")
1652 set (INSTALL_STARTUP_DIR
"${CMAKE_INSTALL_PREFIX}/${INSTALL_SOURCE_DIR}/${SOURCE_PACKAGE}")
1654 set (BUILD_STARTUP_FILE
"${BINARY_DIR}/startup.m")
1655 set (INSTALL_STARTUP_FILE
"${BUILD_DIR}/startup.m")
1656 set (INSTALL_STARTUP_DIR
"${CMAKE_INSTALL_PREFIX}/${INSTALL_SOURCE_DIR}")
1660 list (APPEND BUILD_OUTPUT
"${INSTALL_STARTUP_FILE}")
1661 # MATLAB search path 1663 # The following paths are written to the startup M-file such 1664 # that they can conveniently be added to the search path within an 1665 # interactive MATLAB sesssion. The path to this startup file is 1666 # added to the search path by the wrapper executable first, and 1667 # then this startup file is evaluated which adds all additional 1668 # paths. If no startup file is specified, all paths are added 1669 # to the search path on the command-line in the wrapper script. 1670 set (BUILD_MATLABPATH)
1671 set (INSTALL_MATLABPATH)
1672 # if any source file was configured and hence is located in the 1673 # build tree instead of the source tree, add corresponding build 1674 # tree path to BUILD_MATLABPATH as well 1675 if (SOURCES MATCHES
"^${BINARY_CODE_DIR_RE}")
1676 file (RELATIVE_PATH REL
"${BUILD_STARTUP_DIR}" "${BINARY_DIR}")
1678 list (APPEND BUILD_MATLABPATH
"${REL}")
1680 list (APPEND BUILD_MATLABPATH
".")
1683 list (APPEND BUILD_MATLABPATH
"${SOURCE_DIR}")
1684 # The following is not required because startup script is located 1685 # in the same directory as the other sources and basis_generate_matlab_executable() 1686 # adds this path automatically in order to run the startup script. 1687 # Moreover, if anyone wants to run the startup script, they have to 1688 # add this path manually or make it the current directory first. 1689 #file (RELATIVE_PATH REL "${INSTALL_STARTUP_DIR}" "${CMAKE_INSTALL_PREFIX}/${INSTALL_SOURCE_DIR}") 1691 # list (APPEND INSTALL_MATLABPATH "${REL}") 1693 # list (APPEND INSTALL_MATLABPATH ".") 1695 # link dependencies, i.e., MEX-files 1696 foreach (LINK_DEPEND ${LINK_DEPENDS})
1700 if (LINK_DEPEND MATCHES
"\\.mex")
1702 list (APPEND BUILD_MATLABPATH
"${LINK_PATH}")
1703 list (APPEND DEPENDS ${UID})
1708 if (NOT IMPORTED OR BUNDLED)
1709 file (RELATIVE_PATH REL
"${INSTALL_STARTUP_DIR}" "${LINK_DEPEND}")
1711 set (LINK_DEPEND
"${REL}")
1713 set (LINK_DEPEND
".")
1716 if (LINK_DEPEND MATCHES
"\\.mex")
1718 list (APPEND INSTALL_MATLABPATH
"${LINK_PATH}")
1720 elseif (IS_ABSOLUTE
"${LINK_DEPEND}")
1721 if (IS_DIRECTORY
"${LINK_DEPEND}")
1722 list (APPEND BUILD_MATLABPATH
"${LINK_DEPEND}")
1723 list (APPEND INSTALL_MATLABPATH
"${LINK_DEPEND}")
1724 elseif (EXISTS
"${LINK_DEPEND}" AND LINK_DEPEND MATCHES
"\\.mex")
1726 list (APPEND BUILD_MATLABPATH
"${LINK_PATH}")
1727 list (APPEND INSTALL_MATLABPATH
"${LINK_PATH}")
1731 # cleanup directory paths 1732 string (REGEX REPLACE
"/+" "/" BUILD_MATLABPATH
"${BUILD_MATLABPATH}")
1733 string (REGEX REPLACE
"/+" "/" INSTALL_MATLABPATH
"${INSTALL_MATLABPATH}")
1734 string (REGEX REPLACE
"/(;|$)" "\\1" BUILD_MATLABPATH
"${BUILD_MATLABPATH}")
1735 string (REGEX REPLACE
"/(;|$)" "\\1" INSTALL_MATLABPATH
"${INSTALL_MATLABPATH}")
1737 if (BUILD_MATLABPATH)
1738 list (REMOVE_DUPLICATES BUILD_MATLABPATH)
1740 if (INSTALL_MATLABPATH)
1741 list (REMOVE_DUPLICATES INSTALL_MATLABPATH)
1743 # configure build script 1745 configure_file (
"${BASIS_MODULE_PATH}/generate_matlab_executable.cmake.in" "${BUILD_SCRIPT}" @ONLY)
1746 # add custom command to build wrapper executable 1747 add_custom_command (
1748 OUTPUT ${BUILD_OUTPUT}
1749 # rebuild when input sources were modified 1750 MAIN_DEPENDENCY
"${MAIN_SOURCE}" 1751 DEPENDS
"${BUILD_SCRIPT}" "${CMAKE_CURRENT_LIST_FILE}" ${DEPENDS}
1752 # invoke MATLAB Compiler in either MATLAB or standalone mode 1753 # wrapping command in CMake execute_process () command allows for inspection 1754 # parsing of command output for error messages and specification of timeout 1755 COMMAND "${CMAKE_COMMAND}" "-P" "${BUILD_SCRIPT}" 1757 COMMENT
"${BUILD_COMMENT}" 1759 # install source files - preserving relative paths in SOURCE_DIR
1760 foreach (SOURCE IN LISTS SOURCES)
1762 if (SOURCE MATCHES
"^${BINARY_CODE_DIR_RE}")
1767 if (REL MATCHES
"^\\.?$|^\\.\\./")
1770 DESTINATION
"${INSTALL_SOURCE_DIR}" 1771 COMPONENT
"${RUNTIME_COMPONENT}" 1776 DESTINATION
"${INSTALL_SOURCE_DIR}/${REL}" 1777 COMPONENT
"${RUNTIME_COMPONENT}" 1781 # -------------------------------------------------------------------------- 1782 # assemble build command for build using MATLAB Compiler 1784 set (INSTALL_FILE
"${BUILD_OUTPUT}") # file to be installed
1785 #
get list of libraries to link to (
e.g., MEX-file)
1787 foreach (LIB ${LINK_DEPENDS})
1791 string (REPLACE
"<${BASIS_GE_CONFIG}>" "{CONFIG}" LIB_FILE
"${LIB_FILE}")
1792 list (APPEND DEPENDS ${UID})
1794 set (LIB_FILE
"${LIB}")
1796 list (APPEND LINK_LIBS
"${LIB_FILE}")
1798 # MATLAB search path 1799 foreach (P ${SOURCES})
1801 list (APPEND MATLABPATH
"${P}")
1803 list (APPEND MATLABPATH ${BASIS_INCLUDE_DIRECTORIES})
1804 # MATLAB Compiler arguments
1805 string (REGEX REPLACE
" +" ";" MCC_ARGS
"${COMPILE_FLAGS}")
# user specified flags 1806 foreach (P IN LISTS MATLABPATH) # search path, -I options
1807 string (REGEX REPLACE
"/(\\+|@).*$" "" P
"${P}")
# remove package/class subdirectories 1808 list (FIND MCC_ARGS
"${P}" IDX)
# skip if already added 1810 math (EXPR IDX
"${IDX} - 1")
1811 list (GET MCC_ARGS ${IDX} OPT)
1812 if (NOT OPT MATCHES
"^-I$")
1816 if (EXISTS
"${P}" AND IDX EQUAL -1)
1817 list (APPEND MCC_ARGS -I
"${P}")
1821 list (APPEND MCC_ARGS -W
"cpplib:${MCC_OUTPUT_NAME_WE}" -T link:lib)
# build library 1823 list (APPEND MCC_ARGS -m -o
"${MCC_OUTPUT_NAME_WE}")
# build standalone application 1825 list (APPEND MCC_ARGS -d
"${BUILD_DIR}")
# (temp) output directory 1826 list (APPEND MCC_ARGS ${SOURCES}) # source M-files
1827 foreach (LIB ${LINK_LIBS}) # link libraries,
e.g. MEX-files
1828 list (FIND MCC_ARGS
"${LIB}" IDX)
1829 if (LIB AND IDX EQUAL -1)
1830 list (APPEND MCC_ARGS
"-a" "${LIB}")
1833 # build command for invocation of MATLAB Compiler in standalone mode 1834 set (
BUILD_CMD "${MATLAB_MCC_EXECUTABLE}" ${MCC_USER_ARGS} ${MCC_ARGS})
1835 set (
BUILD_LOG "${BUILD_DIR}/build.log")
1837 set (WORKING_DIR
"${SOURCE_DIRECTORY}")
1838 set (MATLAB_MODE OFF)
1839 # build command
for invocation of MATLAB Compiler in MATLAB mode
1840 if (BASIS_MCC_MATLAB_MODE)
1841 set (MATLAB_MODE ON)
1842 if (NOT MATLAB_EXECUTABLE)
1843 message (WARNING
"MATLAB executable not found. It is required to build target ${TARGET_UID} in MATLAB mode." 1844 " Either set the advanced option BASIS_MCC_MATLAB_MODE to OFF or add MATLAB{matlab} as dependency." 1845 " Will build target ${TARGET_UID} in standalone mode instead.")
1846 set (MATLAB_MODE OFF)
1852 "${MATLAB_EXECUTABLE}" # run MATLAB
1853 "-nosplash" #
do not display splash screen on start up
1854 "-nodesktop" # run in command line mode
1855 "-nojvm" # we
do not need the Java Virtual Machine
1856 "-r" "try, mcc('-v', '${ARGS}'), catch err, fprintf(2, err.message), end, quit force" 1860 # post-build command 1861 set (POST_BUILD_COMMAND)
1862 if (NOT
"^${MCC_OUTPUT_NAME}$" STREQUAL
"^${OUTPUT_NAME}$")
1863 list (APPEND POST_BUILD_COMMAND
1864 COMMAND "${CMAKE_COMMAND}" -E copy
1865 "${BUILD_DIR}/${MCC_OUTPUT_NAME}" 1866 "${BUILD_DIR}/${OUTPUT_NAME}" 1867 COMMAND "${CMAKE_COMMAND}" -E copy
1868 "${BUILD_DIR}/${MCC_OUTPUT_NAME_WE}.h" 1869 "${BUILD_DIR}/${OUTPUT_NAME_WE}.h" 1873 list (APPEND POST_BUILD_COMMAND
1874 COMMAND "${CMAKE_COMMAND}" -E copy
1875 "${BUILD_DIR}/${OUTPUT_NAME}" 1876 "${LIBRARY_OUTPUT_DIRECTORY}/${OUTPUT_NAME}" 1877 COMMAND "${CMAKE_COMMAND}" -E copy
1878 "${BUILD_DIR}/${OUTPUT_NAME_WE}.h" 1879 "${LIBRARY_HEADER_DIRECTORY}/${OUTPUT_NAME_WE}.h" 1882 list (APPEND POST_BUILD_COMMAND
1883 COMMAND "${CMAKE_COMMAND}" -E copy
1884 "${BUILD_DIR}/${OUTPUT_NAME_WE}.dll" 1885 "${LIBRARY_OUTPUT_DIRECTORY}/${OUTPUT_NAME_WE}.dll")
1888 if (CMAKE_SYSTEM_NAME STREQUAL
"Darwin")
1889 # TODO: This file should be regenerated if it is missing. 1890 file (WRITE
"${BUILD_DIR}/${OUTPUT_NAME}" "#!/bin/bash\nexec $(dirname $BASH_SOURCE)/${OUTPUT_NAME_WE}.app/Contents/MacOS/${MCC_OUTPUT_NAME_WE}")
1891 execute_process (
COMMAND chmod +x
"${BUILD_DIR}/${OUTPUT_NAME}")
1892 list (APPEND POST_BUILD_COMMAND
1893 COMMAND "${CMAKE_COMMAND}" -E copy_directory
1894 "${BUILD_DIR}/${OUTPUT_NAME_WE}.app" 1895 "${RUNTIME_OUTPUT_DIRECTORY}/${OUTPUT_NAME_WE}.app" 1896 COMMAND "${CMAKE_COMMAND}" -E copy
1897 "${BUILD_DIR}/${OUTPUT_NAME}" 1898 "${RUNTIME_OUTPUT_DIRECTORY}/${OUTPUT_NAME}" 1901 list (APPEND POST_BUILD_COMMAND
1902 COMMAND "${CMAKE_COMMAND}" -E copy
1903 "${BUILD_DIR}/${OUTPUT_NAME}" 1904 "${RUNTIME_OUTPUT_DIRECTORY}/${OUTPUT_NAME}" 1908 # configure build script 1909 configure_file (
"${BASIS_SCRIPT_EXECUTE_PROCESS}" "${BUILD_SCRIPT}" @ONLY)
1910 # add custom command to build executable using MATLAB Compiler 1911 add_custom_command (
1912 OUTPUT ${BUILD_OUTPUT}
1913 # rebuild when input sources were modified 1914 MAIN_DEPENDENCY
"${MAIN_SOURCE}" 1916 # invoke MATLAB Compiler in either MATLAB or standalone mode 1917 # wrapping command in CMake execute_process() command allows for inspection 1918 # of command output for error messages and specification of timeout 1920 "-DCONFIG=$<${BASIS_GE_CONFIG}>" 1921 "-DWORKING_DIRECTORY=${WORKING_DIR}" 1922 "-DTIMEOUT=${BASIS_MCC_TIMEOUT}" 1923 "-DRETRY_EXPRESSION=License checkout failed" 1924 "-DRETRY_ATTEMPTS=${BASIS_MCC_RETRY_ATTEMPTS}" 1925 "-DRETRY_DELAY=${BASIS_MCC_RETRY_DELAY}" 1926 "-DERROR_EXPRESSION=[E|e]rror:|Illegal output name" 1927 "-DOUTPUT_FILE=${BUILD_LOG}" 1928 "-DERROR_FILE=${BUILD_LOG}" 1931 "-P" "${BUILD_SCRIPT}" 1932 # post build command(s) 1933 ${POST_BUILD_COMMAND}
1934 # inform user where build log can be found 1935 COMMAND "${CMAKE_COMMAND}" -E echo
"Build log written to ${BUILD_LOG}" 1937 COMMENT
"${BUILD_COMMENT}" 1941 # -------------------------------------------------------------------------- 1943 add_custom_target (_${TARGET_UID} DEPENDS ${BUILD_OUTPUT} SOURCES ${SOURCES})
1944 add_dependencies (${TARGET_UID} _${TARGET_UID})
1945 # cleanup on
"make clean" 1946 set (ADDITIONAL_MAKE_CLEAN_FILES
"${BUILD_OUTPUT}")
1948 list (APPEND ADDITIONAL_MAKE_CLEAN_FILES
1949 "${BUILD_DIR}/${MCC_OUTPUT_NAME_WE}.prj" 1950 "${BUILD_DIR}/mccExcludedFiles.log" 1951 "${BUILD_DIR}/mccBuild.log" 1952 "${BUILD_DIR}/readme.txt" 1955 list (APPEND ADDITIONAL_MAKE_CLEAN_FILES
1956 "${BUILD_DIR}/${OUTPUT_NAME_WE}.h" 1957 "${BUILD_DIR}/${MCC_OUTPUT_NAME_WE}.h" 1958 "${BUILD_DIR}/${MCC_OUTPUT_NAME_WE}.c" 1959 "${BUILD_DIR}/${MCC_OUTPUT_NAME_WE}.exports" 1962 list (APPEND ADDITIONAL_MAKE_CLEAN_FILES
1963 "${BUILD_DIR}/${OUTPUT_NAME}" 1964 "${BUILD_DIR}/${MCC_OUTPUT_NAME}" 1965 "${BUILD_DIR}/run_${MCC_OUTPUT_NAME_WE}.sh" 1966 "${BUILD_DIR}/${MCC_OUTPUT_NAME_WE}_main.c" 1967 "${BUILD_DIR}/${MCC_OUTPUT_NAME_WE}_mcc_component_data.c" 1971 set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
"${ADDITIONAL_MAKE_CLEAN_FILES}")
1972 unset (ADDITIONAL_MAKE_CLEAN_FILES)
1977 # install executable or library 1979 if (LIBRARY_HEADER_DIRECTORY)
1980 file (RELATIVE_PATH INCLUDE_DIR_SUFFIX
"${BINARY_INCLUDE_DIR}" "${LIBRARY_HEADER_DIRECTORY}")
1981 if (NOT INCLUDE_DIR_SUFFIX MATCHES
"^../")
1982 string (REGEX REPLACE
"/$" "" INCLUDE_DIR_SUFFIX
"${INCLUDE_DIR_SUFFIX}")
1983 if (INCLUDE_DIR_SUFFIX STREQUAL
".")
1984 set (INCLUDE_DIR_SUFFIX)
1986 set (INCLUDE_DIR_SUFFIX
"/${INCLUDE_DIR_SUFFIX}")
1989 FILES
"${BUILD_DIR}/${OUTPUT_NAME_WE}.h" 1990 DESTINATION
"${INSTALL_INCLUDE_DIR}${INCLUDE_DIR_SUFFIX}" 1991 COMPONENT
"${LIBRARY_COMPONENT}" 1995 if (LIBRARY_INSTALL_DIRECTORY)
1998 FILES
"${BUILD_DIR}/${OUTPUT_NAME_WE}.dll" 1999 DESTINATION
"${RUNTIME_INSTALL_DIRECTORY}" 2000 COMPONENT
"${RUNTIME_COMPONENT}" 2004 FILES
"${INSTALL_FILE}" 2005 DESTINATION
"${LIBRARY_INSTALL_DIRECTORY}" 2006 COMPONENT
"${LIBRARY_COMPONENT}" 2010 if (RUNTIME_INSTALL_DIRECTORY)
2011 if (CMAKE_SYSTEM_NAME STREQUAL
"Darwin")
2013 DIRECTORY
"${BUILD_DIR}/${OUTPUT_NAME_WE}.app" 2014 DESTINATION
"${RUNTIME_INSTALL_DIRECTORY}" 2015 COMPONENT
"${RUNTIME_COMPONENT}" 2016 USE_SOURCE_PERMISSIONS
2020 PROGRAMS
"${INSTALL_FILE}" 2021 DESTINATION
"${RUNTIME_INSTALL_DIRECTORY}" 2022 COMPONENT
"${RUNTIME_COMPONENT}" 2028 message (STATUS
"Adding build command for target ${TARGET_UID}... - done")
function basis_build_mex_file(in TARGET_UID)
Add custom command for build of MEX-file.
function basis_get_matlab_release(out ARGV1)
Get release version of MATLAB installation.
const unsigned int VERSION_MAJOR
The major version number.
function basis_get_target_uid(out TARGET_UID, in TARGET_NAME)
Get "global" target name, i.e., actual CMake target name.
cmake BASIS_UTILITIES
Enable the automatic detection of the use of the BASIS utilities.
function set_target_properties(in ARGN)
Set target property.
function basis_get_relative_path(out REL, in BASE, in PATH)
Get path relative to a given base directory.
function basis_target_link_libraries(in TARGET_NAME, in ARGN)
Add link dependencies to build target.
function is(in result, in expected, in name)
Test whether a given result is equal to the expected result.
function basis_get_project_property(out VARIABLE, in ARGN)
Get project-global property value.
cmake PROJECT_INCLUDE_DIRS
Absolute paths to directories of public header files in source tree.
function basis_finalize_targets(in ARGN)
Finalize custom targets by adding the missing build commands.
macro basis_add_mex_options()
Add global MATLAB MEX-script options to CMake cache.
function basis_check_target_name(in TARGET_NAME)
Checks whether a given name is a valid target name.
macro basis_sanitize_for_regex(out OUT, in STR)
Sanitize string variable for use in regular expression.
cmake MATLAB_LIBRARY_DIR
Directory of MATLAB modules relative to script location.
function basis_get_matlab_version(out ARGV1)
Get version of MATLAB installation.
function basis_add_mcc_target(in TARGET_NAME, in ARGN)
Add MATLAB Compiler target.
function basis_set_project_property()
Set project-global property.
cmake BASIS_EXPORT_DEFAULT
Whether to export targets by default.
macro basis_write_addpaths_mfile(in MFILE, in ARGN)
This function writes a MATLAB M-file with addpath() statements.
macro basis_update_value(in VAR)
Update cache variable.
string VERSION
Project version.
macro basis_set_flag(in PREFIX, out FLAG, in DEFAULT)
Set flag given mutually exclusive ARGN_<FLAG> and ARGN_NO<FLAG> function arguments.
function basis_list_to_string(out STR, in ARGN)
Concatenates all list elements into a single string.
macro basis_add_mcc_options()
Add global MATLAB Compiler (mcc) options to CMake cache.
function basis_add_mex_file(in TARGET_NAME, in ARGN)
Add MEX-file target.
string RELEASE
Project release.
function basis_make_target_uid(out TARGET_UID, in TARGET_NAME)
Make target UID from given target name.
function basis_configure_sources(out LIST_NAME, in ARGN)
Configure .in source files.
#define UNIX
Whether the sources are compiled on a Unix-based system.
function basis_add_custom_export_target(in TARGET_UID, in IS_TEST)
Add target to custom export set.
function basis_mexext(out ARGN)
Determine extension of MEX-files for this architecture.
function basis_string_to_list(out LST, in STR)
Splits a string at space characters into a list.
function basis_get_target_property(out VAR, in TARGET_NAME, in ARGN)
Get value of property set on target.
function basis_list_to_delimited_string(out STR, in DELIM, in ARGN)
Concatenates all list elements into a single delimited string.
const unsigned int VERSION_MINOR
The minor version number.
const unsigned int VERSION_PATCH
The patch number.
function basis_get_full_matlab_version(out VERSION)
Determine version of MATLAB installation.
function basis_create_addpaths_mfile()
This function writes a MATLAB M-file with addpath() statements.
function basis_build_mcc_target(in TARGET_UID)
Add custom command for build of MATLAB Compiler target.
option BASIS_COMPILE_MATLAB
Enable/Disable compilation of MATLAB sources if the MATLAB Compiler is available. ...
option BASIS_VERBOSE
Default Sphinx theme options.
cmake LANGUAGE
Detected scripting language or UNKNOWN.
function basis_get_target_name(out TARGET_NAME, in TARGET_UID)
Get "local" target name, i.e., BASIS target name without check of UID.
function get_filename_component(inout ARGN)
Fixes CMake's get_filename_component() command.
function basis_get_target_location(out VAR, in TARGET_NAME, in PART)
Get location of build target output file(s).
string CONTACT
Default contact to use for help output of executables.