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 TargetTools.cmake 12 # @brief Functions and macros to add executable and library targets. 15 ############################################################################## 24 ## @addtogroup CMakeUtilities 28 # ============================================================================ 30 # ============================================================================ 32 # ---------------------------------------------------------------------------- 33 ## @brief Set properties on a target. 35 # This function replaces CMake's 36 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_target_properties"> 37 # set_target_properties()</a> command and extends its functionality. 38 # In particular, it maps the given target names to the corresponding target UIDs. 40 # @note If @c BASIS_USE_TARGET_UIDS is @c OFF and is not required by a project, 41 # it is recommended to use set_target_properties() instead (note that 42 # set_target_properties is overriden by the ImportTools.cmake module of BASIS). 43 # This will break the build configuration scripts when @c BASIS_USE_TARGET_UIDS 44 # is set to @c ON later. It should thus only be used if the project will 45 # never use the target UID feature of BASIS. A project can possibly define 46 # a global macro which either calls set_target_properties or 47 # basis_set_target_properties. But be aware of the related CMake bugs 48 # which prevent basis_set_target_properties to do the same already. 49 # ARGV/ARGN do not preserve empty arguments nor list arguments! 51 # @note Due to a bug in CMake (http://www.cmake.org/Bug/view.php?id=12303), 52 # except of the first property given directly after the @c PROPERTIES keyword, 53 # only properties listed in @c BASIS_PROPERTIES_ON_TARGETS can be set. 55 # @param [in] ARGN List of arguments. See 56 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_target_properties"> 57 # set_target_properties()</a>. 59 # @returns Sets the specified properties on the given target. 61 # @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_target_properties 65 # convert target names to UIDs
69 message (FATAL_ERROR
"basis_set_target_properties(): Missing arguments!")
72 while (NOT ARG MATCHES "^PROPERTIES$")
74 list (APPEND TARGET_UIDS "${TARGET_UID}
") 75 list (REMOVE_AT ARGN 0) 83 if (NOT ARG MATCHES "^PROPERTIES$
") 84 message (FATAL_ERROR "Missing PROPERTIES argument!
") 85 elseif (NOT TARGET_UIDS) 86 message (FATAL_ERROR "No target specified!
") 88 # remove PROPERTIES keyword 89 list (REMOVE_AT ARGN 0) 90 math (EXPR N "${N} - 1
") 91 # set targets properties 93 # Note: By iterating over the properties, the empty property values 94 # are correctly passed on to CMake's set_target_properties() 96 # _set_target_properties(${TARGET_UIDS} PROPERTIES ${ARGN}) 97 # (erroneously) discards the empty elements in ARGN. 100 message ("** Target(s): ${TARGET_UIDS}
") 101 message ("** Properties: [${ARGN}]
") 104 list (GET ARGN 0 PROPERTY) 105 list (GET ARGN 1 VALUE) 106 list (REMOVE_AT ARGN 0 1) 108 # The following loop is only required b/c CMake's ARGV and ARGN 109 # lists do not support arguments which are themselves lists. 110 # Therefore, we need a way to decide when the list of values for a 111 # property is terminated. Hence, we only allow known properties 112 # to be set, except for the first property where the name follows 113 # directly after the PROPERTIES keyword. 115 list (GET ARGN 0 ARG) 116 if (ARG MATCHES "${BASIS_PROPERTIES_ON_TARGETS_RE}
") 119 list (APPEND VALUE "${ARG}
") 120 list (REMOVE_AT ARGN 0) 124 message ("** -> ${PROPERTY} = [${
VALUE}]
") 126 # check property name 127 if (PROPERTY MATCHES "^$
") # remember: STREQUAL is buggy and evil! 128 message (FATAL_ERROR "Empty
property name given!
") 130 # set target property 131 if (COMMAND _set_target_properties) # i.e. ImportTools.cmake included 132 _set_target_properties (${TARGET_UIDS} PROPERTIES ${PROPERTY} "${
VALUE}
") 134 set_target_properties (${TARGET_UIDS} PROPERTIES ${PROPERTY} "${
VALUE}
") 137 # make sure that every property had a corresponding value 139 message (FATAL_ERROR "No value given
for target
property ${ARGN}
") 143 # ---------------------------------------------------------------------------- 144 ## @brief Get value of property set on target. 146 # This function replaces CMake's 148 # get_target_properties()</a> command and extends its functionality. 149 # In particular, it maps the given @p TARGET_NAME to the corresponding target UID. 151 # @param [out] VAR Name of output variable. 152 # @param [in] TARGET_NAME Name of build target. 153 # @param [in] ARGN Remaining arguments for 154 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:get_target_properties"> 155 # get_target_properties()</a>. 157 # @returns Sets @p VAR to the value of the requested property. 159 # @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:get_target_property 164 get_target_property (
VALUE "${TARGET_UID}" ${ARGN})
165 set (${VAR}
"${VALUE}" PARENT_SCOPE)
168 # ============================================================================ 170 # ============================================================================ 172 # ---------------------------------------------------------------------------- 173 ## @brief Add compile definitions. 175 # This function replaces CMake's 176 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_definitions"> 177 # add_definitions()</a> command. 179 # @param [in] ARGN List of arguments for 180 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_definitions"> 181 # add_definitions()</a>. 183 # @returns Adds the given definitions. 185 # @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_definitions 189 add_definitions (${ARGN})
192 # ---------------------------------------------------------------------------- 193 ## @brief Remove previously added compile definitions. 195 # This function replaces CMake's 196 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:remove_definitions"> 197 # remove_definitions()</a> command. 199 # @param [in] ARGN List of arguments for 200 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:remove_definitions"> 201 # remove_definitions()</a>. 203 # @returns Removes the specified definitions. 205 # @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:remove_definition 209 remove_definitions (${ARGN})
212 # ============================================================================ 214 # ============================================================================ 216 # ---------------------------------------------------------------------------- 217 ## @brief Add directories to search path for include files. 220 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:include_directories"> 221 # include_directories()</a> command. This is required because the 222 # basis_include_directories() function is not used by other projects in their 223 # package use files. Therefore, this macro is an alias for 224 # basis_include_directories(). 226 # @param [in] ARGN List of arguments for basis_include_directories(). 228 # @returns Adds the given paths to the search path for include files. 230 # @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:include_directories 235 # ---------------------------------------------------------------------------- 236 ## @brief Add directories to search path for include files. 238 # This function replaces CMake's 239 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:include_directories"> 240 # include_directories()</a> command. Besides invoking CMake's internal command 241 # with the given arguments, it updates the @c PROJECT_INCLUDE_DIRECTORIES 242 # property on the current project (see basis_set_project_property()). This list 243 # contains a list of all include directories used by a project, regardless of 244 # the directory in which the basis_include_directories() function was used. 246 # @param ARGN List of arguments for 247 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:include_directories"> 248 # include_directories()</a> command. 252 # @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:include_directories 256 # CMake
's include_directories () 257 _include_directories (${ARGN}) 260 CMAKE_PARSE_ARGUMENTS (ARGN "AFTER;BEFORE;SYSTEM" "" "" ${ARGN}) 262 # make relative paths absolute 264 foreach (P IN LISTS ARGN_UNPARSED_ARGUMENTS) 265 if (NOT P MATCHES "^\\$<") # preserve generator expressions 266 get_filename_component (P "${P}" ABSOLUTE) 268 list (APPEND DIRS "${P}") 272 # append directories to "global" list of include directories 273 basis_get_project_property (INCLUDE_DIRS PROPERTY PROJECT_INCLUDE_DIRS) 275 list (INSERT INCLUDE_DIRS 0 ${DIRS}) 277 list (APPEND INCLUDE_DIRS ${DIRS}) 280 list (REMOVE_DUPLICATES INCLUDE_DIRS) 283 message ("** basis_include_directories():") 285 message ("** Add before: ${DIRS}") 287 message ("** Add after: ${DIRS}") 290 message ("** Directories: ${INCLUDE_DIRS}") 293 basis_set_project_property (PROPERTY PROJECT_INCLUDE_DIRS ${INCLUDE_DIRS}) 297 # ---------------------------------------------------------------------------- 298 ## @brief Add directories to search path for libraries. 301 # <a href=
"http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:link_directories">
303 # basis_link_directories() function is not used by other projects in their 304 # package use files. Therefore, this macro is an alias for 305 # basis_link_directories(). 307 # @param [in] ARGN List of arguments for basis_link_directories(). 309 # @returns Adds the given paths to the search path for libraries. 311 # @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:link_directories 316 # ---------------------------------------------------------------------------- 317 ## @brief Add directories to search path for libraries. 319 # This function replaces CMake's 320 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:link_directories"> 321 # link_directories()</a> command. Even though this function yet only invokes 322 # CMake's internal command, it should be used in BASIS projects to enable the 323 # extension of this command's functionality as part of BASIS if required. 325 # @param [in] ARGN List of arguments for 326 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:link_directories"> 327 # link_directories()</a>. 329 # @returns Adds the given paths to the search path for libraries. 331 # @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:link_directories 335 # CMake
's link_directories() command 336 _link_directories (${ARGN}) 337 # make relative paths absolute 339 foreach (P IN LISTS ARGN) 340 if (NOT P MATCHES "^\\$<") # preserve generator expressions 341 get_filename_component (P "${P}" ABSOLUTE) 343 list (APPEND DIRS "${P}") 346 # append directories to "global" list of link directories 347 basis_get_project_property (LINK_DIRS PROPERTY PROJECT_LINK_DIRS) 348 list (APPEND LINK_DIRS ${DIRS}) 350 list (REMOVE_DUPLICATES LINK_DIRS) 353 message ("** basis_link_directories():") 354 message ("** Add: [${DIRS}]") 356 message ("** Directories: [${LINK_DIRS}]") 359 basis_set_project_property (PROPERTY PROJECT_LINK_DIRS "${LINK_DIRS}") 360 # if the directories are added by an external project's <Pkg>Use.cmake
361 # file
which is part of the same superbuild as
this project, add the
362 # directories further to the list of directories that may be added to
366 list (APPEND LINK_DIRS ${DIRS})
368 list (REMOVE_DUPLICATES LINK_DIRS)
375 # ============================================================================ 377 # ============================================================================ 379 # ---------------------------------------------------------------------------- 380 ## @brief Add dependencies to build target. 382 # This function replaces CMake's 383 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_dependencies"> 384 # add_dependencies()</a> command and extends its functionality. 385 # In particular, it maps the given target names to the corresponding target UIDs. 387 # @param [in] ARGN Arguments for 388 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_dependencies"> 389 # add_dependencies()</a>. 391 # @returns Adds the given dependencies of the specified build target. 393 # @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_dependencies 396 if (BASIS_USE_TARGET_UIDS)
399 foreach (ARG ${ARGN})
402 list (APPEND
ARGS "${UID}")
404 list (APPEND ARGS
"${ARG}")
407 add_dependencies (${ARGS})
411 add_dependencies (${ARGV})
415 # ---------------------------------------------------------------------------- 416 ## @brief Add link dependencies to build target. 418 # This function replaces CMake's 419 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:target_link_libraries"> 420 # target_link_libraries()</a> command. 422 # The main reason for replacing this function is to treat libraries such as 423 # MEX-files which are supposed to be compiled into a MATLAB executable added 424 # by basis_add_executable() special. In this case, these libraries are added 425 # to the LINK_DEPENDS property of the given MATLAB Compiler target. Similarly, 426 # executable scripts and modules written in a scripting language may depend 429 # Another reason is the mapping of build target names to fully-qualified 430 # build target names as used by BASIS (see basis_get_target_uid()). 432 # Only link dependencies added with this function are considered for the setting 433 # of the INSTALL_RPATH of executable targets (see basis_set_target_install_rpath()). 437 # basis_add_library (MyMEXFunc MEX myfunc.c) 438 # basis_add_executable (MyMATLABApp main.m) 439 # basis_target_link_libraries (MyMATLABApp MyMEXFunc OtherMEXFunc.mexa64) 442 # @param [in] TARGET_NAME Name of the target. 443 # @param [in] ARGN Link libraries. 445 # @returns Adds link dependencies to the specified build target. 446 # For custom targets, the given libraries are added to the 447 # @c LINK_DEPENDS property of these targets, in particular. 449 # @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:target_link_libraries 454 if (NOT TARGET
"${TARGET_UID}")
455 message (FATAL_ERROR
"basis_target_link_libraries(): Unknown target ${TARGET_UID}.")
457 # get type of named target 458 get_target_property (BASIS_TYPE ${TARGET_UID} BASIS_TYPE)
459 # substitute non-fully qualified target names
461 foreach (ARG ${ARGN})
462 if (
"^${ARG}$" STREQUAL
"^basis$")
464 if (NOT
LANGUAGE OR
"^${LANGUAGE}$" STREQUAL
"^UNKNOWN$")
465 message (FATAL_ERROR
"Target ${TARGET_UID} is of unknown LANGUAGE! Cannot add dependency on \"basis\" utilities.")
468 list (APPEND ARGS ${BASIS_UTILITIES_TARGET})
473 if (
"^${UID}$" STREQUAL
"^${TARGET_UID}$")
474 message (FATAL_ERROR
"Cannot add link library ${UID} as dependency of itself!")
476 list (APPEND ARGS
"${UID}")
478 list (APPEND ARGS
"${ARG}")
482 # get current link libraries 483 if (BASIS_TYPE MATCHES
"^EXECUTABLE$|^(SHARED|STATIC|MODULE)_LIBRARY$")
484 get_target_property (DEPENDS ${TARGET_UID} BASIS_LINK_DEPENDS)
486 get_target_property (DEPENDS ${TARGET_UID} LINK_DEPENDS)
491 # note that MCC does itself a dependency check and in case of scripts 492 # the basis_get_target_link_libraries() function is used 493 if (BASIS_TYPE MATCHES
"MCC|SCRIPT")
494 list (APPEND DEPENDS ${ARGS})
497 list (APPEND DEPENDS ${ARGS})
498 # pull implicit dependencies (
e.g., ITK uses
this)
499 set (DEPENDENCY_ADDED 1)
500 while (DEPENDENCY_ADDED)
501 set (DEPENDENCY_ADDED 0)
502 foreach (LIB IN LISTS DEPENDS)
503 foreach (LIB_DEPEND IN LISTS ${LIB}_LIB_DEPENDS)
504 if (NOT LIB_DEPEND MATCHES
"^$|^general$")
505 string (REGEX REPLACE
"^-l" "" LIB_DEPEND
"${LIB_DEPEND}")
506 list (FIND DEPENDS ${LIB_DEPEND} IDX)
508 list (APPEND DEPENDS ${LIB_DEPEND})
509 set (DEPENDENCY_ADDED 1)
516 # update LINK_DEPENDS 517 if (BASIS_TYPE MATCHES
"^EXECUTABLE$|^(SHARED|STATIC|MODULE)_LIBRARY$")
519 target_link_libraries (${TARGET_UID} ${ARGS})
521 # FIXME cannot use LINK_DEPENDS for CMake targets as these depends are 522 # otherwise added as is to the Makefile. therefore, consider renaming 523 # LINK_DEPENDS in general to BASIS_LINK_DEPENDS. 528 # ============================================================================ 530 # ============================================================================ 532 # ---------------------------------------------------------------------------- 533 ## @brief Add custom target. 537 add_custom_target (${_UID} ${ARGN})
541 # ---------------------------------------------------------------------------- 542 ## @brief Determine language of source files. 543 # @sa basis_add_executable(), basis_add_library() 544 macro (_basis_target_source_language)
545 if (NOT ARGN_LANGUAGE)
547 if (ARGN_LANGUAGE MATCHES
"AMBIGUOUS|UNKNOWN")
549 foreach (SOURCE IN LISTS
SOURCES)
550 set (_FILES
"${_FILES}\n ${SOURCE}")
552 if (ARGN_LANGUAGE MATCHES
"AMBIGUOUS")
553 message (FATAL_ERROR
"Target ${TARGET_UID}: Ambiguous source code files! Try to set LANGUAGE manually and make sure that no unknown option was given:${_FILES}")
554 elseif (ARGN_LANGUAGE MATCHES
"UNKNOWN")
555 message (FATAL_ERROR
"Target ${TARGET_UID}: Unknown source code language! Try to set LANGUAGE manually and make sure that no unknown option was given:${_FILES}")
559 string (TOUPPER
"${ARGN_LANGUAGE}" ARGN_LANGUAGE)
563 # ---------------------------------------------------------------------------- 564 ## @brief Add executable target. 566 # This is the main function to add an executable target to the build system, 567 # where an executable can be a binary file or a script written in a scripting 568 # language. In general we refer to any output file which is part of the software 569 # (i.e., excluding configuration files) and which can be executed 570 # (e.g., a binary file in the ELF format) or interpreted (e.g., a Python script) 571 # directly, as executable file. Natively, CMake supports only executables built 572 # from C/C++ source code files. This function extends CMake's capabilities 573 # by adding custom build commands for non-natively supported programming 574 # languages and further standardizes the build of executable targets. 575 # For example, by default, it is not necessary to specify installation rules 576 # separately as these are added by this function already (see below). 578 # @par Programming languages 579 # Besides adding usual executable targets build by the set <tt>C/CXX</tt> 580 # language compiler, this function inspects the list of source files given and 581 # detects whether this list contains sources which need to be build using a 582 # different compiler. In particular, it supports the following languages: 587 # <td>The default behavior, adding an executable target build from C/C++ 588 # source code. The target is added via CMake's add_executable() command.</td> 591 # @tp <b>PYTHON</b>|<b>JYTHON</b>|<b>PERL</b>|<b>BASH</b> @endtp 592 # <td>Executables written in one of the named scripting languages are built by 593 # configuring and/or copying the script files to the build tree and 594 # installation tree, respectively. During the build step, certain strings 595 # of the form \@VARIABLE\@ are substituted by the values set during the 596 # configure step. How these CMake variables are set is specified by a 597 # so-called script configuration, which itself is either a CMake script 598 # file or a string of CMake code set as value of the @c SCRIPT_DEFINITIONS 599 # property of the executable target.</td> 602 # @tp @b MATLAB @endtp 603 # <td>Standalone application built from MATLAB sources using the 604 # MATLAB Compiler (mcc). This language option is used when the list 605 # of source files contains one or more *.m files. A custom target is 606 # added which depends on custom command(s) that build the executable.</td> 608 # Attention: The *.m file with the entry point/main function of the 609 # executable has to be given before any other *.m file. 613 # @par Helper functions 614 # If the programming language of the input source files is not specified 615 # explicitly by providing the @p LANGUAGE argument, the extensions of the 616 # source files and if necessary the first line of script files are inspected 617 # by the basis_get_source_language() function. Once the programming language is 618 # known, this function invokes the proper subcommand which adds the respective 619 # build target. In particular, it calls basis_add_executable_target() for C++ 620 # sources (.cxx), basis_add_mcc_target() for MATLAB scripts (.m), and 621 # basis_add_script() for all other source files. 623 # @note DO NOT use the mentioned subcommands directly. Always use 624 # basis_add_executable() to add an executable target to your project. 625 # Only refer to the documentation of the subcommands to learn about the 626 # available options of the particular subcommand and considered target 629 # @par Output directories 630 # The built executable file is output to the @c BINARY_RUNTIME_DIR or 631 # @c BINARY_LIBEXEC_DIR if the @p LIBEXEC option is given. 632 # If this function is used within the @c PROJECT_TESTING_DIR, however, 633 # the built executable is output to the @c TESTING_RUNTIME_DIR or 634 # @c TESTING_LIBEXEC_DIR instead. 637 # An install command for the added executable target is added by this function 638 # as well. The executable will be installed as part of the specified @p COMPONENT 639 # in the directory @c INSTALL_RUNTIME_DIR or @c INSTALL_LIBEXEC_DIR if the option 640 # @p LIBEXEC is given. Executable targets are exported by default such that they 641 # can be imported by other CMake-aware projects by including the CMake 642 # configuration file of this package (<Package>Config.cmake file). 643 # No installation rules are added, however, if this function is used within the 644 # @c PROJECT_TESTING_DIR or if "none" (case-insensitive) is given as 645 # @p DESTINATION. Test executables are further only exported as part of the 646 # build tree, but not the installation as they are by default not installed. 648 # @param [in] TARGET_NAME Name of the target. If an existing source file is given 649 # as first argument, it is added to the list of source files 650 # and the build target name is derived from the name of this file. 651 # @param [in] ARGN This argument list is parsed and the following 652 # arguments are extracted, all other arguments are passed 653 # on to add_executable() or the respective custom 654 # commands used to add an executable build target. 658 # @tp @b COMPONENT name @endtp 659 # <td>Name of component as part of which this executable will be installed 660 # if the specified @c DESTINATION is not "none". 661 # (default: @c BASIS_RUNTIME_COMPONENT)</td> 664 # @tp @b DESTINATION dir @endtp 665 # <td>Installation directory relative to @c CMAKE_INSTALL_PREFIX. 666 # If "none" (case-insensitive) is given as argument, no default 667 # installation rules are added for this executable target. 668 # (default: @c INSTALL_RUNTIME_DIR or @c INSTALL_LIBEXEC_DIR 669 # if the @p LIBEXEC option is given)</td> 672 # @tp @b LANGUAGE lang @endtp 673 # <td>Programming language in which source files are written (case-insensitive). 674 # If not specified, the programming language is derived from the file name 675 # extensions of the source files and, if applicable, the shebang directive 676 # on the first line of the script file. If the programming language could 677 # not be detected automatically, check the file name extensions of the 678 # source files and whether no unrecognized additional arguments were given 679 # or specify the programming language using this option. 680 # (default: auto-detected)</td> 683 # @tp @b LIBEXEC @endtp 684 # <td>Specifies that the built executable is an auxiliary executable which 685 # is only called by other executables. (default: @c FALSE)</td> 688 # @tp @b [NO]EXPORT @endtp 689 # <td>Whether to export this target. (default: @c TRUE)</td> 692 # @tp @b NO_BASIS_UTILITIES @endtp 693 # <td>Specify that the BASIS utilities are not used by this executable and hence 694 # no link dependency on the BASIS utilities shall be added. 695 # (default: @c NOT @c BASIS_UTILITIES)</td> 698 # @tp @b USE_BASIS_UTILITIES @endtp 699 # <td>Specify that the BASIS utilities are used and required by this executable 700 # and hence a link dependency on the BASIS utilities has to be added. 701 # (default: @c BASIS_UTILITIES)</td> 704 # @tp @b FINAL @endtp 705 # <td>Finalize custom targets immediately. Any following target property changes 706 # will have no effect. When this option is used, the custom target which 707 # executes the custom build command is added in the current working directory. 708 # Otherwise it will be added in the top-level source directory of the project. 709 # Which with the Visual Studio generators adds the corresponding Visual Studio 710 # Project files directly to the top-level build directory. This can be avoided 711 # using this option or calling basis_finalize_targets() at the end of each 712 # CMakeLists.txt file.</td> 716 # @returns Adds an executable build target. In case of an executable which is 717 # not build from C++ source files, the function basis_finalize_targets() 718 # has to be invoked to finalize the addition of the custom build target. 719 # This is done by the basis_project_end() macro. 721 # @sa basis_add_executable_target() 722 # @sa basis_add_script() 723 # @sa basis_add_mcc_target() 727 # --------------------------------------------------------------------------
729 CMAKE_PARSE_ARGUMENTS (
731 "EXECUTABLE;LIBEXEC;NO_BASIS_UTILITIES;USE_BASIS_UTILITIES;EXPORT;NOEXPORT;FINAL" 732 "COMPONENT;DESTINATION;LANGUAGE" 736 # derive target name from path
if existing source path
is given as first argument instead
737 # and
get list of library source files
739 if (IS_DIRECTORY
"${S}" AND NOT ARGN_UNPARSED_ARGUMENTS)
742 elseif (EXISTS
"${S}" AND NOT IS_DIRECTORY
"${S}" OR (NOT S MATCHES
"\\.in$" AND EXISTS
"${S}.in" AND NOT IS_DIRECTORY
"${S}.in"))
748 if (ARGN_UNPARSED_ARGUMENTS)
749 list (APPEND SOURCES ${ARGN_UNPARSED_ARGUMENTS})
752 message (FATAL_ERROR
"basis_add_executable called with only one argument which does however not" 753 " appear to be a file name. Note that the filename extension must be" 754 " included if the target name should be derived from the base filename" 755 " of the source file.")
757 # -------------------------------------------------------------------------- 761 # -------------------------------------------------------------------------- 762 # process globbing expressions to get complete list of source files 764 # --------------------------------------------------------------------------
765 # determine programming language
766 _basis_target_source_language ()
767 # -------------------------------------------------------------------------- 768 # prepare arguments for subcommand 769 foreach (ARG IN LISTS ARGN_UNPARSED_ARGUMENTS)
770 list (REMOVE_ITEM ARGN
"${ARG}")
772 list (APPEND ARGN ${SOURCES})
773 # --------------------------------------------------------------------------
775 if (ARGN_LANGUAGE MATCHES
"CXX")
777 # --------------------------------------------------------------------------
779 elseif (ARGN_LANGUAGE MATCHES
"MATLAB")
781 list (REMOVE_ITEM ARGN LIBEXEC)
784 list (REMOVE_ITEM ARGN EXECUTABLE)
787 # -------------------------------------------------------------------------- 791 list (REMOVE_ITEM ARGN LIBEXEC)
794 list (REMOVE_ITEM ARGN EXECUTABLE)
798 # -------------------------------------------------------------------------- 799 # re-glob source files before each build (if necessary) 800 if (TARGET __${TARGET_UID})
801 if (TARGET _${TARGET_UID})
802 add_dependencies (_${TARGET_UID} __${TARGET_UID})
804 add_dependencies (${TARGET_UID} __${TARGET_UID})
808 # ---------------------------------------------------------------------------- 809 ## @brief Add library target. 811 # This is the main function to add a library target to the build system, where 812 # a library can be a binary archive, shared library, a MEX-file or module(s) 813 # written in a scripting language. In general we refer to any output file which 814 # is part of the software (i.e., excluding configuration files), but cannot be 815 # executed (e.g., a binary file in the ELF format) or interpreted 816 # (e.g., a Python module) directly, as library file. Natively, CMake supports only 817 # libraries built from C/C++ source code files. This function extends CMake's 818 # capabilities by adding custom build commands for non-natively supported 819 # programming languages and further standardizes the build of library targets. 820 # For example, by default, it is not necessary to specify installation rules 821 # separately as these are added by this function already (see below). 823 # @par Programming languages 824 # Besides adding usual library targets built from C/C++ source code files, 825 # this function can also add custom build targets for libraries implemented 826 # in other programming languages. It therefore tries to detect the programming 827 # language of the given source code files and delegates the addition of the 828 # build target to the proper helper functions. It in particular supports the 829 # following languages: 834 # <td>Source files written in C/C++ are by default built into either 835 # @p STATIC, @p SHARED, or @p MODULE libraries. If the @p MEX option 836 # is given, however, a MEX-file (a shared library) is build using 837 # the MEX script instead of using the default C++ compiler directly.</td> 840 # @tp <b>PYTHON</b>|<b>JYTHON</b>|<b>PERL</b>|<b>BASH</b> @endtp 841 # <td>Modules written in one of the named scripting languages are built similar 842 # to executable scripts except that the file name extension is preserved 843 # and no executable file permission is set on Unix. These modules are 844 # intended for import/inclusion in other modules or executables written 845 # in the particular scripting language only.</td> 848 # @tp @b MATLAB @endtp 849 # <td>Libraries of M-files or shared libraries built using the MATLAB Compiler (mcc). 850 # This language option is used when the list of source files contains one or 851 # more *.m files. A custom target is added which depends on custom command(s) 852 # that build the library. If the type of the library is @c SHARED, a shared 853 # library is build using the MATLAB Compiler. Otherwise, the M-files are 854 # configured and installed such that they can be used in MATLAB.</td> 858 # @par Helper functions 859 # If the programming language of the input source files is not specified 860 # explicitly by providing the @p LANGUAGE argument, the extensions of the 861 # source files are inspected using basis_get_source_language(). Once the 862 # programming language is known, this function invokes the proper subcommand. 863 # In particular, it calls basis_add_library_target() for C++ sources (.cxx) 864 # if the target is not a MEX-file target, basis_add_mex_file() for C++ sources 865 # if the @p MEX option is given, basis_add_mcc_target() for MATLAB scripts (.m), 866 # and basis_add_script_library() for all other source files. 868 # @note DO NOT use the mentioned subcommands directly. Always use 869 # basis_add_library() to add a library target to your project. Only refer 870 # to the documentation of the subcommands to learn about the available 871 # options of the particular subcommand and the considered target properties. 873 # @par Output directories 874 # In case of modules written in a scripting language, the libraries are output to 875 # the <tt>BINARY_<LANGUAGE>_LIBRARY_DIR</tt> if defined. Otherwise, 876 # the built libraries are output to the @c BINARY_RUNTIME_DIR, @c BINARY_LIBRARY_DIR, 877 # and/or @c BINARY_ARCHIVE_DIR. If this command is used within the @c PROJECT_TESTING_DIR, 878 # however, the files are output to the corresponding directories in the testing tree, 882 # An installation rule for the added library target is added by this function 883 # if the destination is not "none" (case-insensitive). Runtime libraries are 884 # installed as part of the @p RUNTIME_COMPONENT to the @p RUNTIME_DESTINATION. 885 # Library components are installed as part of the @p LIBRARY_COMPONENT to the 886 # @p LIBRARY_DESTINATION. Library targets are further exported such that they 887 # can be imported by other CMake-aware projects by including the CMake 888 # configuration file of this package (<Package>Config.cmake file). 889 # If this function is used within the @c PROJECT_TESTING_DIR, however, no 890 # installation rules are added. Test library targets are further only exported 891 # as part of the build tree. 895 # basis_add_library (MyLib1 STATIC mylib.cxx) 896 # basis_add_library (MyLib2 STATIC mylib.cxx COMPONENT dev) 898 # basis_add_library ( 899 # MyLib3 SHARED mylib.cxx 900 # RUNTIME_COMPONENT bin 901 # LIBRARY_COMPONENT dev 904 # basis_add_library (MyMex MEX mymex.cxx) 905 # basis_add_library (PythonModule MyModule.py.in) 906 # basis_add_library (ShellModule MODULE MyModule.sh.in) 909 # @param [in] TARGET_NAME Name of build target. If an existing file is given as 910 # argument, it is added to the list of source files and 911 # the target name is derived from the name of this file. 912 # @param [in] ARGN This argument list is parsed and the following 913 # arguments are extracted. All unparsed arguments are 914 # treated as source files. 918 # @tp <b>STATIC</b>|<b>SHARED</b>|<b>MODULE</b>|<b>MEX</b> @endtp 919 # <td>Type of the library. (default: @c SHARED for C++ libraries if 920 # @c BUILD_SHARED_LIBS evaluates to true or @c STATIC otherwise, 921 # and @c MODULE in all other cases)</td> 924 # @tp @b COMPONENT name @endtp 925 # <td>Name of component as part of which this library will be installed 926 # if the @c RUNTIME_DESTINATION or @c LIBRARY_DESTINATION is not "none". 927 # Used only if @p RUNTIME_COMPONENT or @p LIBRARY_COMPONENT not specified. 928 # (default: see @p RUNTIME_COMPONENT and @p LIBRARY_COMPONENT)</td> 931 # @tp @b DESTINATION dir @endtp 932 # <td>Installation directory for runtime and library component relative 933 # to @c CMAKE_INSTALL_PREFIX. Used only if @p RUNTIME_DESTINATION or 934 # @p LIBRARY_DESTINATION not specified. If "none" (case-insensitive) 935 # is given as argument, no default installation rules are added. 936 # (default: see @p RUNTIME_DESTINATION and @p LIBRARY_DESTINATION)</td> 939 # @tp @b LANGUAGE lang @endtp 940 # <td>Programming language in which source files are written (case-insensitive). 941 # If not specified, the programming language is derived from the file name 942 # extensions of the source files and, if applicable, the shebang directive 943 # on the first line of the script file. If the programming language could 944 # not be detected automatically, check the file name extensions of the 945 # source files and whether no unrecognized additional arguments were given 946 # or specify the programming language using this option. 947 # (default: auto-detected)</td> 950 # @tp @b LIBRARY_COMPONENT name @endtp 951 # <td>Name of component as part of which import/static library will be intalled 952 # if @c LIBRARY_DESTINATION is not "none". 953 # (default: @c COMPONENT if specified or @c BASIS_LIBRARY_COMPONENT otherwise)</td> 956 # @tp @b LIBRARY_DESTINATION dir @endtp 957 # <td>Installation directory of the library component relative to 958 # @c CMAKE_INSTALL_PREFIX. If "none" (case-insensitive) is given as argument, 959 # no installation rule for the library component is added. 960 # (default: @c INSTALL_ARCHIVE_DIR)</td> 963 # @tp @b RUNTIME_COMPONENT name @endtp 964 # <td>Name of component as part of which runtime library will be installed 965 # if @c RUNTIME_DESTINATION is not "none". 966 # (default: @c COMPONENT if specified or @c BASIS_RUNTIME_COMPONENT otherwise)</td> 969 # @tp @b RUNTIME_DESTINATION dir @endtp 970 # <td>Installation directory of the runtime component relative to 971 # @c CMAKE_INSTALL_PREFIX. If "none" (case-insensitive) is given as argument, 972 # no installation rule for the runtime library is added. 973 # (default: @c INSTALL_LIBRARY_DIR on Unix or @c INSTALL_RUNTIME_DIR Windows)</td> 976 # @tp @b [NO]EXPORT @endtp 977 # <td>Whether to export this target. (default: @c TRUE)</td> 980 # @tp @b NO_BASIS_UTILITIES @endtp 981 # <td>Specify that the BASIS utilities are not used by this executable and hence 982 # no link dependency on the BASIS utilities shall be added. 983 # (default: @c NOT @c BASIS_UTILITIES)</td> 986 # @tp @b USE_BASIS_UTILITIES @endtp 987 # <td>Specify that the BASIS utilities are used and required by this executable 988 # and hence a link dependency on the BASIS utilities has to be added. 989 # (default: @c BASIS_UTILITIES)</td> 992 # @tp @b FINAL @endtp 993 # <td>Finalize custom targets immediately. Any following target property changes 994 # will have no effect. When this option is used, the custom target which 995 # executes the custom build command is added in the current working directory. 996 # Otherwise it will be added in the top-level source directory of the project. 997 # Which with the Visual Studio generators adds the corresponding Visual Studio 998 # Project files directly to the top-level build directory. This can be avoided 999 # using this option or calling basis_finalize_targets() at the end of each 1000 # CMakeLists.txt file.</td> 1004 # @returns Adds a library build target. In case of a library not written in C++ 1005 # or MEX-file targets, basis_finalize_targets() has to be invoked 1006 # to finalize the addition of the build target(s). This is done 1007 # by the basis_project_end() macro. 1009 # @sa basis_add_library_target() 1010 # @sa basis_add_script_library() 1011 # @sa basis_add_mex_file() 1012 # @sa basis_add_mcc_target() 1016 # --------------------------------------------------------------------------
1018 CMAKE_PARSE_ARGUMENTS (
1020 "STATIC;SHARED;MODULE;MEX;USE_BASIS_UTILITIES;NO_BASIS_UTILITIES;EXPORT;NOEXPORT;FINAL" 1021 "COMPONENT;RUNTIME_COMPONENT;LIBRARY_COMPONENT;DESTINATION;RUNTIME_DESTINATION;LIBRARY_DESTINATION;LANGUAGE" 1025 # derive target name from path
if existing source path
is given as first argument instead
1026 # and
get list of library source files
1028 if (IS_DIRECTORY
"${S}" AND NOT ARGN_UNPARSED_ARGUMENTS)
1029 set (SOURCES
"${S}")
1031 elseif (EXISTS
"${S}" AND NOT IS_DIRECTORY
"${S}" OR (NOT S MATCHES
"\\.in$" AND EXISTS
"${S}.in" AND NOT IS_DIRECTORY
"${S}.in"))
1032 set (SOURCES
"${S}")
1036 _basis_target_source_language ()
1037 if (
"$${ARGN_LANGUAGE}" STREQUAL
"$CXX")
1046 if (ARGN_UNPARSED_ARGUMENTS)
1047 list (APPEND SOURCES ${ARGN_UNPARSED_ARGUMENTS})
1049 # -------------------------------------------------------------------------- 1053 # -------------------------------------------------------------------------- 1054 # process globbing expressions to get complete list of source files 1056 # --------------------------------------------------------------------------
1057 # determine programming language
1058 _basis_target_source_language ()
1059 # -------------------------------------------------------------------------- 1060 # prepare arguments for subcommand 1061 foreach (ARG IN LISTS ARGN_UNPARSED_ARGUMENTS)
1062 list (REMOVE_ITEM ARGN
"${ARG}")
1064 list (APPEND ARGN ${SOURCES})
1065 # --------------------------------------------------------------------------
1067 if (ARGN_LANGUAGE MATCHES
"CXX")
1071 message (FATAL_ERROR
"Target ${TARGET_UID}: Invalid library type! Only modules or shared libraries can be built by the MEX script.")
1073 list (REMOVE_ITEM ARGN MODULE)
1074 list (REMOVE_ITEM ARGN SHARED)
1075 list (REMOVE_ITEM ARGN MEX)
1081 # -------------------------------------------------------------------------- 1083 elseif (ARGN_LANGUAGE MATCHES
"MATLAB")
1084 if (ARGN_STATIC OR ARGN_MEX)
1085 message (FATAL_ERROR
"Target ${TARGET_UID}: Invalid library type! Only shared libraries can be built by the MATLAB Compiler.")
1088 list (REMOVE_ITEM ARGN SHARED)
1091 list (REMOVE_ITEM ARGN MODULE)
# optional 1094 # -------------------------------------------------------------------------- 1097 if (ARGN_STATIC OR ARGN_SHARED OR ARGN_MEX)
1098 message (FATAL_ERROR
"Target ${TARGET_UID}: Invalid library type! Only modules can be built from scripts.")
1100 list (REMOVE_ITEM ARGN MODULE)
1103 # -------------------------------------------------------------------------- 1104 # re-glob source files before each build (if necessary) 1105 if (TARGET __${TARGET_UID})
1106 if (TARGET _${TARGET_UID})
1107 add_dependencies (_${TARGET_UID} __${TARGET_UID})
1109 add_dependencies (${TARGET_UID} __${TARGET_UID})
1113 # ---------------------------------------------------------------------------- 1114 ## @brief Add single arbitrary or executable script. 1116 # @note This function should not be used directly for executable scripts or 1117 # module libraries. Use basis_add_executable() or basis_add_library() 1118 # in such (most) cases instead. 1120 # This function can be used to add a single arbitrary script file (i.e., any 1121 # text file which is input to a program), such as a CTest script for example, 1122 # to the build if neither basis_add_executable() nor basis_add_library() are 1123 # appropriate choices. In all other cases, either basis_add_executable() or 1124 # basis_add_library() should be used. Note that the script file is by default 1125 # not considered to be an executable. Instead it is assumed that the program 1126 # which interprets/processes the script must be executed explicitly with this 1127 # script as argument. Only scripts built with the @p EXECUTABLE or @p LIBEXEC 1128 # type option are treated as executable files, where in case of Unix a shebang 1129 # directive implicitly states the program used by the shell to interpret the 1130 # script and on Windows a Windows Command which imitates the behavior of Unix 1131 # shells is generated by BASIS. Do not use these type options, however, but 1132 # only use the default @p MODULE option. The basis_add_executable() function 1133 # should be used instead to add an executable script. The basis_add_script() 1134 # function shall only be used for none-executable arbitrary script files which 1135 # cannot be built by basis_add_executable() or basis_add_library(). 1137 # If the script name ends in <tt>.in</tt>, the <tt>.in</tt> suffix is removed 1138 # from the output name. Further, in case of executable scripts, the file name 1139 # extension is removed from the output file name. Instead, a shebang directive 1140 # is added on Unix to the built script. In order to enable the convenient 1141 # execution of Python and Perl scripts also on Windows without requiring the 1142 # user to setup a proper associate between the filename extension with the 1143 # corresponding interpreter executable, a few lines of Batch code are added at 1144 # the top and bottom of executable Python and Perl scripts. This Batch code 1145 # invokes the configured interpreter with the script file and the given script 1146 # arguments as command-line arguments. Note that both the original script source 1147 # code and the Batch code are stored within the single file. The file name 1148 # extension of such modified scripts is by default set to <tt>.cmd</tt>, the 1149 # common extension for Windows NT Command Scripts. Scripts in other languages 1150 # are not modified and the extension of the original scripts script file is 1151 # preserved on Windows in this case. In case of non-executable scripts, the 1152 # file name extension is kept in any case. 1154 # Certain CMake variables within the source file are replaced during the 1155 # built of the script. See the 1156 # <a href="https://cmake-basis.github.io/scripttargets/> 1157 # Build System Standard</a> for details. 1158 # Note, however, that source files are only configured if the file name 1159 # ends in the <tt>.in</tt> suffix. 1161 # A custom CMake build target with the following properties is added by this 1162 # function to the build system. These properties are used by basis_build_script() 1163 # to generate a build script written in CMake code which is executed by a custom 1164 # CMake command. Before the invokation of basis_build_script(), the target 1165 # properties can be modified using basis_set_target_properties(). 1167 # @note Custom BASIS build targets are finalized by BASIS using basis_project_end(), 1168 # i.e., the end of the root CMake configuration file of the (sub-)project. 1170 # @par Properties on script targets 1173 # @tp @b BASIS_TYPE @endtp 1174 # <td>Read-only property with value "SCRIPT_FILE" for arbitrary scripts, 1175 # "SCRIPT_EXECUTABLE" for executable scripts, and "SCRIPT_LIBEXEC" for 1176 # auxiliary executable scripts. 1177 # (default: see @p MODULE, @p EXECUTABLE, @p LIBEXEC options)</td> 1180 # @tp @b BASIS_UTILITIES @endtp 1181 # <td>Whether the BASIS utilities are used by this script. For the supported 1182 # scripting languages for which BASIS utilities are implemented, BASIS 1183 # will in most cases automatically detect whether these utilities are 1184 # used by a script or not. Otherwise, set this property manually or use 1185 # either the @p USE_BASIS_UTILITIES or the @p NO_BASIS_UTILITIES option 1186 # when adding the script target. (default: auto-detected or @c UNKNOWN)</td> 1189 # @tp @b BINARY_DIRECTORY @endtp 1190 # <td>Build tree directory of this target. (default: @c CMAKE_CURRENT_BINARY_DIR)</td> 1193 # @tp @b COMPILE @endtp 1194 # <td>Whether to compile the script if the programming language allows such 1195 # pre-compilation as in case of Python, for example. If @c TRUE, only the 1196 # compiled file is installed. (default: @c BASIS_COMPILE_SCRIPTS)</td> 1199 # @tp @b SCRIPT_DEFINITIONS @endtp 1200 # <td>CMake code which is evaluated after the inclusion of the default script 1201 # configuration files. This code can be used to set the replacement text of the 1202 # CMake variables ("@VAR@" patterns) used in the source file. 1203 # See <a href="https://cmake-basis.github.io/standard/scripttargets.html#script-configuration"> 1204 # Build System Standard</a> for details. (default: "")</td> 1207 # @tp @b SCRIPT_DEFINITIONS_FILE @endtp 1208 # <td>CMake script file with compile definitions, also referred to as script 1209 # configuration file. The named files are included after the default BASIS 1210 # script configuration and before the @c SCRIPT_DEFINITIONS code is being 1211 # evaluated. (default: @c BINARY_CONFIG_DIR/ScriptConfig.cmake)</td> 1214 # @tp @b COMPONENT @endtp 1215 # <td>Name of component as part of which this script is installed if 1216 # @c INSTALL_DIRECTORY is not set to "none". 1217 # (default: see @p COMPONENT argument)</td> 1220 # @tp @b EXPORT @endtp 1221 # <td>Whether to export this build target in which case an import library 1222 # target is added to the custom exports file with the path to the 1223 # built/installed script set as @c IMPORT_LOCATION. (default: @c TRUE)</td> 1226 # @tp @b INSTALL_DIRECTORY @endtp 1227 # <td>Installation directory of script file configured for use in installation tree 1228 # relative to @c CMAKE_INSTALL_PREFIX. Set to "none" (case-insensitive) to skip the 1229 # addition of an installation rule. (default: see @p DESTINATION argument)</td> 1232 # @tp @b LANGUAGE @endtp 1233 # <td>Read-only property of programming language of script file in uppercase letters. 1234 # (default: see @p LANGUAGE argument)</td> 1237 # @tp @b LINK_DEPENDS @endtp 1238 # <td>Paths or target names of script modules and libraries used by this script. 1239 # In case of an (auxiliary) executable script, the directories of these modules 1240 # are added to the search path for modules of the given programming language 1241 # if such search paths are supported by the language and BASIS knows how to set 1242 # these (as in case of Python/Jython, Perl, and MATLAB, in particular). 1243 # Moreover, for each listed build target a dependency is added between this 1244 # script target and the named build targets. Use basis_target_link_libraries() 1245 # to add additional link dependencies. 1246 # (default: BASIS utilities module if used or empty list otherwise)</td> 1249 # @tp @b OUTPUT_DIRECTORY @endtp 1250 # <td>Output directory for built script file configured for use in build tree. 1251 # (default: @c BINARY_LIBRARY_DIR for arbitrary scripts, @c BINARY_RUNTIME_DIR 1252 # for executable scripts, and @c BINARY_LIBEXEC_DIR for auxiliary executables)</td> 1255 # @tp @b OUTPUT_NAME @endtp 1256 # <td>Name of built script file including file name extension (if any). 1257 # (default: basename of script file for arbitrary scripts, without extension 1258 # for executable scripts on Unix, and <tt>.cmd</tt> extension on Windows 1259 # in case of executable Python/Jython or Perl script)</td> 1262 # @tp @b SOURCE_DIRECTORY @endtp 1263 # <td>Source directory of this target. (default: @c CMAKE_CURRENT_SOURCE_DIR)</td> 1266 # @tp @b SOURCES @endtp 1267 # <td>Read-only property which lists the source file of this script target. 1268 # Note that the first element in this list actually names a directory 1269 # in the build, the one where the build script for this target is located 1270 # instead of a source file and thus should be ignored. The second entry 1271 # corresponds to the source file of this script target.</td> 1275 # @attention Properties documented as read-only must not be modified. 1277 # @note If this function is used within the @c PROJECT_TESTING_DIR, the built 1278 # executable is output to the @c BINARY_TESTING_DIR directory tree instead. 1279 # Moreover, no installation rules are added. Test executables are further 1280 # not exported, regardless of the @c EXPORT property. 1282 # @param [in] TARGET_NAME Name of build target. If an existing file is given as 1283 # argument, it is added to the list of source files and 1284 # the target name is derived from the name of this file. 1285 # @param [in] ARGN The remaining arguments are parsed and the following arguments 1286 # recognized. All unparsed arguments are treated as source files, 1287 # where in particular exactly one source file is required if the 1288 # @p TARGET_NAME argument does not name an existing source file. 1292 # @tp <b>MODULE</b>|<b>EXECUTABLE</b>|<b>LIBEXEC</b> @endtp 1293 # <td>Type of script to built, i.e., either arbitrary module script which 1294 # cannot be executed directly, an executable script with proper shebang 1295 # directive and execute permissions on Unix or Windows Command on Windows, 1296 # or an auxiliary executable. The type of the script mainly changes the 1297 # default values of the target properties such as the output and installation 1298 # directories. To add an (auxiliary) executable script, use 1299 # basis_add_executable(), however, instead of this function. 1300 # The @c EXECUTABLE and @c LIBEXEC options are only intended for 1301 # internal use by BASIS. (default: MODULE)</td> 1304 # @tp @b COMPONENT name @endtp 1305 # <td>Name of installation component as part of which this script is being 1306 # installed if the @c INSTALL_DIRECTORY property is not "none". 1307 # (default: @c BASIS_LIBRARY_COMPONENT for arbitrary scripts or 1308 # @c BASIS_RUNTIME_COMPONENT for executable scripts)</td> 1311 # @tp @b DESTINATION dir @endtp 1312 # <td>Installation directory for script file relative to @c CMAKE_INSTALL_PREFIX. 1313 # If an absolute path is given as argument, it is made relative to the 1314 # configured installation prefix. 1315 # (default: @c INSTALL_LIBRARY_DIR for arbitrary scripts, 1316 # @c INSTALL_RUNTIME_DIR for executable scripts, and @c INSTALL_LIBEXEC_DIR 1317 # for auxiliary executable scripts)</td> 1320 # @tp @b LANGUAGE lang @endtp 1321 # <td>Programming language in which script file is written (case-insensitive). 1322 # If not specified, the programming language is derived from the file name 1323 # extension of the source file and the shebang directive on the first line 1324 # of the script if any. If the programming language could not be detected 1325 # automatically, the @c LANGUAGE property is set to @c UNKNOWN. Note that 1326 # for arbitrary script targets, the script file will still be built correctly 1327 # even if the scripting language was not recognized. The automatic detection 1328 # whether the BASIS utilities are used and required will fail, however. 1329 # In this case, specify the programming language using this option. 1330 # (default: auto-detected or @c UNKNOWN)</td> 1333 # @tp @b [NO]EXPORT @endtp 1334 # <td>Whether to export this target. (default: @c TRUE)</td> 1337 # @tp @b NO_BASIS_UTILITIES @endtp 1338 # <td>Specify that the BASIS utilities are not used by this script. If the 1339 # programming language of the script is known and BASIS utilities are 1340 # available for this language, BASIS will in most cases automatically 1341 # detect whether these utilities are used by a script or not. Use this 1342 # option to skip this check because the script does not make use of the 1343 # BASIS utilities.</td> 1346 # @tp @b USE_BASIS_UTILITIES @endtp 1347 # <td>Specify that the BASIS utilities are used and thus required by this script. 1348 # If the programming language of the script is known and BASIS utilities are 1349 # available for this language, BASIS will in most cases automatically 1350 # detect whether these utilities are used by a script or not. Use this option 1351 # to skip this check because it is already known that the script makes use of 1352 # the BASIS utilities. Note that an error is raised if this option is given, 1353 # but no BASIS utilities are available for the programming language of this 1354 # script or if the programming language is unknown, respectively, not detected 1355 # correctly. In this case, consider the use of the @p LANGUAGE argument.</td> 1358 # @tp @b FINAL @endtp 1359 # <td>Finalize custom targets immediately. Any following target property changes 1360 # will have no effect. When this option is used, the custom target which 1361 # executes the custom build command is added in the current working directory. 1362 # Otherwise it will be added in the top-level source directory of the project. 1363 # Which with the Visual Studio generators adds the corresponding Visual Studio 1364 # Project files directly to the top-level build directory. This can be avoided 1365 # using this option or calling basis_finalize_targets() at the end of each 1366 # CMakeLists.txt file.</td> 1370 # @returns Adds a custom CMake target with the documented properties. The actual custom 1371 # command to build the script is added by basis_build_script(). 1376 CMAKE_PARSE_ARGUMENTS (
1378 "MODULE;EXECUTABLE;LIBEXEC;NO_BASIS_UTILITIES;USE_BASIS_UTILITIES;EXPORT;NOEXPORT;FINAL" 1379 "COMPONENT;DESTINATION;LANGUAGE" 1383 if (NOT ARGN_MODULE AND NOT ARGN_EXECUTABLE AND NOT ARGN_LIBEXEC)
1384 set (ARGN_MODULE TRUE)
1389 set (TYPE EXECUTABLE)
1391 string (TOLOWER
"${TYPE}" type)
1392 # derive target name from file name if existing source file given as first argument 1394 if (EXISTS
"${S}" AND NOT IS_DIRECTORY
"${S}" OR (NOT S MATCHES
"\\.in$" AND EXISTS
"${S}.in" AND NOT IS_DIRECTORY
"${S}.in"))
1395 set (SOURCES
"${S}")
1401 set (SET_OUTPUT_NAME_TO_TARGET_NAMEE FALSE)
1404 set (SET_OUTPUT_NAME_TO_TARGET_NAME TRUE)
1409 message (STATUS
"Adding ${type} script ${TARGET_UID}...")
1410 if (ARGN_MODULE AND TYPE MATCHES
"EXECUTABLE")
1411 message (FATAL_ERROR
"Target ${TARGET_UID}: MODULE and EXECUTABLE or LIBEXEC options are mutually exclusive!")
1413 # check/set parsed arguments 1415 if (ARGN_USE_BASIS_UTILITIES AND ARGN_NO_BASIS_UTILITIES)
1416 message (FATAL_ERROR
"Options USE_BASIS_UTILITIES and NO_BASIS_UTILITIES are mutually exclusive!")
1418 list (LENGTH ARGN_UNPARSED_ARGUMENTS N)
1420 math (EXPR N
"${N} + 1")
1424 list (REMOVE_AT ARGN_UNPARSED_ARGUMENTS 0)
1426 message (FATAL_ERROR
"Target ${TARGET_UID}: Too many or unrecognized arguments: ${ARGN_UNPARSED_ARGUMENTS}!\n" 1427 " Only one script can be built by each script target.")
1428 elseif (NOT SOURCES)
1429 set (SOURCES
"${ARGN_UNPARSED_ARGUMENTS}")
1432 if (NOT EXISTS
"${SOURCES}" AND NOT SOURCES MATCHES
"\\.in$" AND EXISTS
"${SOURCES}.in")
1433 set (SOURCES
"${SOURCES}.in")
1435 if (NOT EXISTS
"${SOURCES}")
1436 string (REGEX REPLACE
"\\.in$" "" SOURCES
"${SOURCES}")
1437 message (FATAL_ERROR
"Target ${TARGET_UID}: Source file ${SOURCES}[.in] does not exist!")
1440 add_custom_target (${TARGET_UID} ALL SOURCES ${SOURCES})
1441 # dump CMake variables
for configuration of script
1442 set (BUILD_DIR
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TARGET_UID}")
1444 # auto-detect programming language (may be as well UNKNOWN) 1446 string (TOUPPER
"${ARGN_LANGUAGE}" ARGN_LANGUAGE)
1452 if (CMAKE_CURRENT_SOURCE_DIR MATCHES
"^${RE}")
1457 # default directory infix used below 1459 set (TYPE_INFIX
"LIBRARY")
1460 elseif (ARGN_LIBEXEC)
1461 set (TYPE_INFIX
"LIBEXEC")
1463 set (TYPE_INFIX
"RUNTIME")
1466 string (REGEX REPLACE
"\\.in$" "" SOURCE_NAME
"${SOURCES}")
1467 if (SET_OUTPUT_NAME_TO_TARGET_NAME)
1476 if (ARGN_LANGUAGE MATCHES
"[JP]YTHON|PERL")
1487 set (OUTPUT_DIRECTORY
"${TESTING_${TYPE_INFIX}_DIR}")
1489 set (OUTPUT_DIRECTORY
"${BINARY_${TYPE_INFIX}_DIR}")
1491 # installation component 1492 if (NOT ARGN_COMPONENT)
1494 set (ARGN_COMPONENT
"${BASIS_LIBRARY_COMPONENT}")
1496 set (ARGN_COMPONENT
"${BASIS_RUNTIME_COMPONENT}")
1499 if (NOT ARGN_COMPONENT)
1500 set (ARGN_COMPONENT
"Unspecified")
1502 # installation directory 1503 if (ARGN_DESTINATION)
1504 if (ARGN_DESTINATION MATCHES
"^[nN][oO][nN][eE]$")
1505 set (ARGN_DESTINATION)
1506 elseif (IS_ABSOLUTE
"${ARGN_DESTINATION}")
1507 file (RELATIVE_PATH ARGN_DESTINATION
"${CMAKE_INSTALL_PREFIX}" "${ARGN_DESTINATION}")
1510 set (ARGN_DESTINATION) #
do not install
1512 set (ARGN_DESTINATION
"${INSTALL_${TYPE_INFIX}_DIR}")
1514 # script configuration ("compile definitions") 1515 if (EXISTS
"${BINARY_CONFIG_DIR}/ScriptConfig.cmake")
1516 set (
CONFIG_FILE "${BINARY_CONFIG_DIR}/ScriptConfig.cmake")
1520 # auto-detect use of BASIS utilities 1522 if (ARGN_LANGUAGE MATCHES
"[JP]YTHON")
1523 set (UTILITIES_LANGUAGE
"PYTHON")
1525 set (UTILITIES_LANGUAGE
"${ARGN_LANGUAGE}")
1527 if (ARGN_USE_BASIS_UTILITIES)
1529 message (FATAL_ERROR
"Target ${TARGET_UID} requires the BASIS utilities for ${UTILITIES_LANGUAGE}" 1530 " but BASIS was either build without the build of these utilities enabled" 1531 " or no utilities for this programming language are implemented. Remove the" 1532 " USE_BASIS_UTILITIES option if no BASIS utilities are used by the script" 1533 " ${SOURCES} or specify the correct programming language if it was not" 1534 " detected correctly.")
1536 set (USES_BASIS_UTILITIES TRUE)
1537 elseif (NOT ARGN_NO_BASIS_UTILITIES AND NOT UTILITIES_LANGUAGE MATCHES
"UNKNOWN")
1540 set (USES_BASIS_UTILITIES FALSE)
1542 if (USES_BASIS_UTILITIES)
1545 message (
"** Target ${TARGET_UID} uses the BASIS utilities for ${UTILITIES_LANGUAGE}.")
1548 # set properties of custom build target 1553 BASIS_TYPE SCRIPT_${TYPE}
1555 BUILD_DIRECTORY
"${BUILD_DIR}" 1556 SOURCE_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}" 1557 BINARY_DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}" 1558 OUTPUT_DIRECTORY
"${OUTPUT_DIRECTORY}" 1559 INSTALL_DIRECTORY
"${ARGN_DESTINATION}" 1560 COMPONENT
"${ARGN_COMPONENT}" 1561 OUTPUT_NAME
"${OUTPUT_NAME}" 1564 SCRIPT_DEFINITIONS
"" 1565 SCRIPT_DEFINITIONS_FILE
"${CONFIG_FILE}" 1566 LINK_DEPENDS
"${LINK_DEPENDS}" 1570 LIBEXEC ${ARGN_LIBEXEC}
1576 # add target to list of targets 1578 message (STATUS
"Adding ${type} script ${TARGET_UID}... - done")
1581 # ---------------------------------------------------------------------------- 1582 ## @brief Finalize custom targets by adding the missing build commands. 1584 # This function is called by basis_project_end() in order to finalize the 1585 # addition of the custom build targets such as, for example, build targets 1586 # for the build of executable scripts, Python packages, MATLAB Compiler 1587 # executables and shared libraries, and MEX-files. It can, however, also 1588 # be called explicitly either at the end of each CMakeLists.txt file that 1589 # adds new build targets or with the name of the target(s) to finalize in 1590 # some of the CMakeLists.txt files. This is to ensure that the custom target 1591 # which executes the actual build command is added in the same directory as 1592 # the original custom target with the respective target properties. 1594 # @param[in] ARGN List of targets to finalize. If none specified, all custom 1595 # targets that were added before and are not finalized already 1596 # will be finalized using the current binary directory. 1598 # @returns Generates the CMake build scripts and adds custom build commands 1599 # and corresponding targets for the execution of these scripts. 1601 # @sa basis_build_script() 1602 # @sa basis_build_script_library() 1603 # @sa basis_build_mcc_target() 1604 # @sa basis_build_mex_file() 1608 foreach (TARGET_NAME ${ARGN})
1610 list (APPEND TARGETS ${TARGET_UID})
1617 # targets of BASIS utilities are finalized separately 1618 # because some properties still have to be set by 1619 # basis_configure_utilities, see UtilitiesTools module 1623 list (REMOVE_ITEM TARGETS
1624 ${TARGET_UID_basis_sh}
1625 ${TARGET_UID_basis_py}
1626 ${TARGET_UID_Basis_pm}
1630 if (FINALIZED_TARGETS)
1631 list (REMOVE_ITEM TARGETS ${FINALIZED_TARGETS})
1635 "** basis_finalize_targets:" 1636 "\n TARGETS: [${TARGETS}]" 1637 "\n FINALIZED: [${FINALIZED_TARGETS}]" 1640 foreach (TARGET_UID ${TARGETS})
1641 get_target_property (BASIS_TYPE ${TARGET_UID} BASIS_TYPE)
1642 if (BASIS_TYPE MATCHES
"^EXECUTABLE$|^(SHARED|MODULE)_LIBRARY$")
1644 # Only if BASIS is allowed to take care of the INSTALL_RPATH property 1645 # and the use of this property was not disabled by the project 1648 elseif (BASIS_TYPE MATCHES
"SCRIPT_LIBRARY")
1650 elseif (BASIS_TYPE MATCHES
"SCRIPT")
1652 elseif (BASIS_TYPE MATCHES
"MEX")
1654 elseif (BASIS_TYPE MATCHES
"MCC")
1657 list (APPEND FINALIZED_TARGETS ${TARGET_UID})
1662 # ============================================================================ 1664 # ============================================================================ 1666 # ---------------------------------------------------------------------------- 1667 ## @brief Add executable target. 1669 # This BASIS function overwrites CMake's 1670 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_executable"> 1671 # add_executable()</a> command in order to store information of imported targets 1672 # which is in particular used to generate the source code of the ExecutableTargetInfo 1673 # modules which are part of the BASIS utilities. 1675 # @note Use basis_add_executable() instead where possible! 1677 # @param [in] TARGET_UID Name of the target. 1678 # @param [in] ARGN Further arguments of CMake's add_executable(). 1680 # @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_executable 1682 _add_executable (${TARGET_UID} ${ARGN})
1683 list (FIND ARGN IMPORTED IDX)
1693 # ---------------------------------------------------------------------------- 1694 ## @brief Add library target. 1696 # This BASIS function overwrites CMake's 1697 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_library"> 1698 # add_library()</a> command in order to store information of imported targets. 1700 # @note Use basis_add_library() instead where possible! 1702 # @param [in] TARGET_UID Name of the target. 1703 # @param [in] ARGN Further arguments of CMake's add_library(). 1705 # @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_library 1707 _add_library (${TARGET_UID} ${ARGN})
1708 list (FIND ARGN IMPORTED IDX)
1710 if (
COMMAND basis_add_imported_target)
1718 # ---------------------------------------------------------------------------- 1719 ## @brief Add executable built from C++ source code. 1721 # @note This function should not be used directly. Instead, it is called 1722 # by basis_add_executable() if the (detected) programming language 1723 # of the given source code files is @c CXX (i.e., C/C++). 1725 # This function adds an executable target for the build of an executable from 1726 # C++ source code files. Refer to the documentation of basis_add_executable() 1727 # for a description of general options for adding an executable target. 1729 # By default, the BASIS C++ utilities library is added as link dependency. 1730 # If none of the BASIS C++ utilities are used by this target, the option 1731 # NO_BASIS_UTILITIES can be given. To enable this option by default, set the 1732 # variable @c BASIS_UTILITIES to @c FALSE, best in the <tt>Settings.cmake</tt> 1733 # file located in the @c PROJECT_CONFIG_DIR (add such file if missing). 1734 # If the use of the BASIS C++ utilities is disabled by default, the 1735 # @c USE_BASIS_UTILITIES option can be used to enable them for this target 1736 # only. Note that the utilities library is a static library and thus the linker 1737 # would simply not include any of the BASIS utility functions in the final 1738 # binary file if not used. The only advantage of setting @c BASIS_UTILITIES to 1739 # @c FALSE or to always specify @c NO_BASIS_UTILITIES if no target uses the 1740 # utilities is that the BASIS utilities library will not be build in this case. 1742 # @param [in] TARGET_NAME Name of build target. 1743 # @param [in] ARGN This argument list is parsed and the following 1744 # arguments are extracted, all other arguments are 1745 # considered to be source code files and simply passed 1746 # on to CMake's add_executable() command. 1750 # @tp @b COMPONENT name @endtp 1751 # <td>Name of component as part of which this executable will be installed 1752 # if the specified @c DESTINATION is not "none". 1753 # (default: @c BASIS_RUNTIME_COMPONENT)</td> 1756 # @tp @b DESTINATION dir @endtp 1757 # <td>Installation directory relative to @c CMAKE_INSTALL_PREFIX. 1758 # If "none" (case-insensitive) is given as argument, no default 1759 # installation rules are added for this executable target. 1760 # (default: @c INSTALL_RUNTIME_DIR or @c INSTALL_LIBEXEC_DIR 1761 # if @p LIBEXEC is given)</td> 1764 # @tp @b LIBEXEC @endtp 1765 # <td>Specifies that the built executable is an auxiliary executable which 1766 # is only called by other executables. (default: @c FALSE)</td> 1769 # @tp @b [NO]EXPORT @endtp 1770 # <td>Whether to export this target. (default: @c TRUE)</td> 1773 # @tp @b NO_BASIS_UTILITIES @endtp 1774 # <td>Specify that the BASIS utilities are not used by this executable and hence 1775 # no link dependency on the BASIS utilities library shall be added. 1776 # (default: @c NOT @c BASIS_UTILITIES)</td> 1779 # @tp @b USE_BASIS_UTILITIES @endtp 1780 # <td>Specify that the BASIS utilities are used and required by this executable 1781 # and hence a link dependency on the BASIS utilities library has to be added. 1782 # (default: @c BASIS_UTILITIES)</td> 1786 # @returns Adds executable target using CMake's add_executable() command. 1788 # @sa basis_add_executable() 1793 message (STATUS
"Adding executable ${TARGET_UID}...")
1795 CMAKE_PARSE_ARGUMENTS (
1797 "USE_BASIS_UTILITIES;NO_BASIS_UTILITIES;EXPORT;NOEXPORT;LIBEXEC" 1798 "COMPONENT;DESTINATION" 1802 set (SOURCES ${ARGN_UNPARSED_ARGUMENTS})
1804 if (ARGN_USE_BASIS_UTILITIES AND ARGN_NO_BASIS_UTILITIES)
1805 message (FATAL_ERROR
"Target ${TARGET_UID}: Options USE_BASIS_UTILITIES and NO_BASIS_UTILITIES are mutually exclusive!")
1807 if (ARGN_USE_BASIS_UTILITIES)
1808 set (USES_BASIS_UTILITIES TRUE)
1809 elseif (ARGN_NO_BASIS_UTILITIES)
1810 set (USES_BASIS_UTILITIES FALSE)
1816 if (CMAKE_CURRENT_SOURCE_DIR MATCHES
"^${RE}")
1821 # installation component 1822 if (NOT ARGN_COMPONENT)
1823 set (ARGN_COMPONENT
"${BASIS_RUNTIME_COMPONENT}")
1825 if (NOT ARGN_COMPONENT)
1826 set (ARGN_COMPONENT
"Unspecified")
1828 # installation directory 1829 if (ARGN_DESTINATION)
1830 if (ARGN_DESTINATION MATCHES
"^[nN][oO][nN][eE]$")
1831 set (ARGN_DESTINATION)
1832 elseif (IS_ABSOLUTE
"${ARGN_DESTINATION}")
1833 file (RELATIVE_PATH ARGN_DESTINATION
"${CMAKE_INSTALL_PREFIX}" "${ARGN_DESTINATION}")
1835 elseif (ARGN_LIBEXEC)
1836 set (ARGN_DESTINATION
"${INSTALL_LIBEXEC_DIR}")
1838 set (ARGN_DESTINATION
"${INSTALL_RUNTIME_DIR}")
1840 # configure (.in) source files 1842 # add executable target
1845 if (TARGET
"${HEADERS_TARGET}")
1846 add_dependencies (${TARGET_UID} ${HEADERS_TARGET})
1851 set_target_properties (${TARGET_UID} PROPERTIES LIBEXEC 1 COMPILE_DEFINITIONS LIBEXEC SCRIPT_DEFINITIONS LIBEXEC)
1863 elseif (ARGN_LIBEXEC)
1868 # installation directory 1870 # link to BASIS utilities
1871 if (USES_BASIS_UTILITIES)
1882 if (ARGN_DESTINATION)
1884 # TODO install (selected?) tests 1887 TARGETS ${TARGET_UID} ${EXPORT_OPT}
1888 DESTINATION
"${ARGN_DESTINATION}" 1889 COMPONENT
"${ARGN_COMPONENT}" 1894 message (STATUS
"Adding executable ${TARGET_UID}... - done")
1897 # ---------------------------------------------------------------------------- 1898 ## @brief Add library built from C++ source code. 1900 # @note This function should not be used directly. Instead, it is called 1901 # by basis_add_library() if the (detected) programming language 1902 # of the given source code files is @c CXX (i.e., C/C++) and the 1903 # option @c MEX is not given. 1905 # This function adds a library target which builds a library from C++ source 1906 # code files. Refer to the documentation of basis_add_library() for a 1907 # description of the general options for adding a library target. 1909 # By default, the BASIS C++ utilities library is added as link dependency. 1910 # If none of the BASIS C++ utilities are used by this target, the option 1911 # NO_BASIS_UTILITIES can be given. To enable this option by default, set the 1912 # variable @c BASIS_UTILITIES to @c FALSE, best in the <tt>Settings.cmake</tt> 1913 # file located in the @c PROJECT_CONFIG_DIR (add such file if missing). 1914 # If the use of the BASIS C++ utilities is disabled by default, the 1915 # @c USE_BASIS_UTILITIES option can be used to enable them for this target 1916 # only. Note that the utilities library is a static library and thus the linker 1917 # would simply not include any of the BASIS utility functions in the final 1918 # binary file if not used. The only advantage of setting @c BASIS_UTILITIES to 1919 # @c FALSE or to always specify @c NO_BASIS_UTILITIES if no target uses the 1920 # utilities is that the BASIS utilities library will not be build in this case. 1922 # @param [in] TARGET_NAME Name of build target. 1923 # @param [in] ARGN This argument list is parsed and the following 1924 # arguments are extracted. All other arguments are 1925 # considered to be source code files and simply 1926 # passed on to CMake's add_library() command. 1930 # @tp <b>STATIC</b>|<b>SHARED</b>|<b>MODULE</b> @endtp 1931 # <td>Type of the library. (default: @c SHARED if @c BUILD_SHARED_LIBS 1932 # evaluates to true or @c STATIC otherwise)</td> 1935 # @tp @b COMPONENT name @endtp 1936 # <td>Name of component as part of which this library will be installed 1937 # if either the @c RUNTIME_INSTALL_DIRECTORY or 1938 # @c LIBRARY_INSTALL_DIRECTORY property is not "none". Used only if 1939 # either @p RUNTIME_COMPONENT or @p LIBRARY_COMPONENT not specified. 1940 # (default: see @p RUNTIME_COMPONENT and @p LIBRARY_COMPONENT)</td> 1943 # @tp @b DESTINATION dir @endtp 1944 # <td>Installation directory for runtime and library component relative 1945 # to @c CMAKE_INSTALL_PREFIX. Used only if either @p RUNTIME_DESTINATION 1946 # or @p LIBRARY_DESTINATION not specified. If "none" (case-insensitive) 1947 # is given as argument, no default installation rules are added. 1948 # (default: see @p RUNTIME_DESTINATION and @p LIBRARY_DESTINATION)</td> 1951 # @tp @b LIBRARY_COMPONENT name @endtp 1952 # <td>Name of component as part of which import/static library will be intalled 1953 # if @c LIBRARY_INSTALL_DIRECTORY property is not "none". 1954 # (default: @c COMPONENT if specified or @c BASIS_LIBRARY_COMPONENT otherwise)</td> 1957 # @tp @b LIBRARY_DESTINATION dir @endtp 1958 # <td>Installation directory of the library component relative to 1959 # @c CMAKE_INSTALL_PREFIX. If "none" (case-insensitive) is given as argument, 1960 # no installation rule for the library component is added. 1961 # (default: @c INSTALL_ARCHIVE_DIR)</td> 1964 # @tp @b RUNTIME_COMPONENT name @endtp 1965 # <td>Name of component as part of which runtime library will be installed 1966 # if @c RUNTIME_INSTALL_DIRECTORY property is not "none". 1967 # (default: @c COMPONENT if specified or @c BASIS_RUNTIME_COMPONENT otherwise)</td> 1970 # @tp @b RUNTIME_DESTINATION dir @endtp 1971 # <td>Installation directory of the runtime component relative to 1972 # @c CMAKE_INSTALL_PREFIX. If "none" (case-insensitive) is given as argument, 1973 # no installation rule for the runtime library is added. 1974 # (default: @c INSTALL_LIBRARY_DIR on Unix or @c INSTALL_RUNTIME_DIR Windows)</td> 1977 # @tp @b [NO]EXPORT @endtp 1978 # <td>Whether to export this target. (default: @c TRUE)</td> 1981 # @tp @b NO_BASIS_UTILITIES @endtp 1982 # <td>Specify that the BASIS utilities are not used by this executable and hence 1983 # no link dependency on the BASIS utilities library shall be added. 1984 # (default: @c NOT BASIS_UTILITIES)</td> 1987 # @tp @b USE_BASIS_UTILITIES @endtp 1988 # <td>Specify that the BASIS utilities are used and required by this executable 1989 # and hence a link dependency on the BASIS utilities library shall be added. 1990 # (default: @c BASIS_UTILITIES)</td> 1994 # @returns Adds library target using CMake's add_library() command. 1996 # @sa basis_add_library() 1998 # On
UNIX-based systems setting the
VERSION property only creates
1999 # annoying files with the version
string as suffix.
2000 # Moreover, MEX-files may NEVER have a suffix after the MEX extension!
2001 # Otherwise, the MATLAB Compiler when
using the symbolic link
2002 # without
this suffix will create code that fails on runtime
2003 # with an .auth file missing error.
2005 # Thus,
do NOT
set VERSION and SOVERSION properties on library targets!
2011 CMAKE_PARSE_ARGUMENTS (
2013 "STATIC;SHARED;MODULE;USE_BASIS_UTILITIES;NO_BASIS_UTILITIES;EXPORT;NOEXPORT" 2014 "COMPONENT;RUNTIME_COMPONENT;LIBRARY_COMPONENT;DESTINATION;RUNTIME_DESTINATION;LIBRARY_DESTINATION" 2018 set (SOURCES ${ARGN_UNPARSED_ARGUMENTS})
2020 if (ARGN_USE_BASIS_UTILITIES AND ARGN_NO_BASIS_UTILITIES)
2021 message (FATAL_ERROR
"Target ${TARGET_UID}: Options USE_BASIS_UTILITIES and NO_BASIS_UTILITIES are mutually exclusive!")
2023 if (ARGN_USE_BASIS_UTILITIES)
2024 set (USES_BASIS_UTILITIES TRUE)
2025 elseif (ARGN_NO_BASIS_UTILITIES)
2026 set (USES_BASIS_UTILITIES FALSE)
2032 if (CMAKE_CURRENT_SOURCE_DIR MATCHES
"^${RE}")
2038 if (NOT ARGN_SHARED AND NOT ARGN_STATIC AND NOT ARGN_MODULE)
2039 if (BUILD_SHARED_LIBS)
2040 set (ARGN_SHARED TRUE)
2042 set (ARGN_STATIC TRUE)
2048 message (FATAL_ERROR
"More than one library type specified for target ${TARGET_UID}!")
2054 message (FATAL_ERROR
"More than one library type specified for target ${TARGET_UID}!")
2060 message (FATAL_ERROR
"More than one library type specified for target ${TARGET_UID}!")
2064 string (TOLOWER
"${TYPE}" type)
2066 message (STATUS
"Adding ${type} library ${TARGET_UID}...")
2067 # installation component 2069 if (NOT ARGN_RUNTIME_COMPONENT)
2070 set (ARGN_RUNTIME_COMPONENT
"${ARGN_COMPONENT}")
2072 if (NOT ARGN_LIBRARY_COMPONENT)
2073 set (ARGN_LIBRARY_COMPONENT
"${ARGN_COMPONENT}")
2076 if (NOT ARGN_RUNTIME_COMPONENT)
2077 set (ARGN_RUNTIME_COMPONENT
"${BASIS_RUNTIME_COMPONENT}")
2079 if (NOT ARGN_RUNTIME_COMPONENT)
2080 set (ARGN_RUNTIME_COMPONENT
"Unspecified")
2082 if (NOT ARGN_LIBRARY_COMPONENT)
2083 set (ARGN_LIBRARY_COMPONENT
"${BASIS_LIBRARY_COMPONENT}")
2085 if (NOT ARGN_LIBRARY_COMPONENT)
2086 set (ARGN_LIBRARY_COMPONENT
"Unspecified")
2088 # installation directories 2089 if (ARGN_DESTINATION)
2090 if (NOT ARGN_STATIC AND NOT ARGN_RUNTIME_DESTINATION)
2091 set (ARGN_RUNTIME_DESTINATION
"${ARGN_DESTINATION}")
2093 if (NOT ARGN_LIBRARY_DESTINATION)
2094 set (ARGN_LIBRARY_DESTINATION
"${ARGN_DESTINATION}")
2097 if (NOT ARGN_RUNTIME_DESTINATION)
2098 set (ARGN_RUNTIME_DESTINATION
"${INSTALL_RUNTIME_DIR}")
2100 if (NOT ARGN_LIBRARY_DESTINATION)
2101 set (ARGN_LIBRARY_DESTINATION
"${INSTALL_LIBRARY_DIR}")
2103 if (ARGN_STATIC OR ARGN_RUNTIME_DESTINATION MATCHES
"^[nN][oO][nN][eE]$")
2104 set (ARGN_RUNTIME_DESTINATION)
2106 if (ARGN_LIBRARY_DESTINATION MATCHES
"^[nN][oO][nN][eE]$")
2107 set (ARGN_LIBRARY_DESTINATION)
2109 # configure (.in) source files 2111 # add library target
2114 if (TARGET ${HEADERS_TARGET})
2115 add_dependencies (${TARGET_UID} ${HEADERS_TARGET})
2124 RUNTIME_OUTPUT_DIRECTORY
"${TESTING_RUNTIME_DIR}" 2125 LIBRARY_OUTPUT_DIRECTORY
"${TESTING_LIBRARY_DIR}" 2126 ARCHIVE_OUTPUT_DIRECTORY
"${TESTING_ARCHIVE_DIR}" 2132 RUNTIME_OUTPUT_DIRECTORY
"${BINARY_RUNTIME_DIR}" 2133 LIBRARY_OUTPUT_DIRECTORY
"${BINARY_LIBRARY_DIR}" 2134 ARCHIVE_OUTPUT_DIRECTORY
"${BINARY_ARCHIVE_DIR}" 2137 # installation directory 2138 # these properties are used by basis_get_target_location() in particular 2142 RUNTIME_INSTALL_DIRECTORY
"${ARGN_RUNTIME_DESTINATION}" 2143 LIBRARY_INSTALL_DIRECTORY
"${ARGN_LIBRARY_DESTINATION}" 2144 ARCHIVE_INSTALL_DIRECTORY
"${ARGN_LIBRARY_DESTINATION}" 2146 # link to BASIS utilities
2147 if (USES_BASIS_UTILITIES)
2155 basis_add_export_target (EXPORT_OPT ${TARGET_UID}
"${IS_TEST}" ${ARGN_RUNTIME_DESTINATION} ${ARGN_LIBRARY_DESTINATION})
2158 set (DESTINATION_OPTS)
2160 # TODO At the moment, no tests are installed. Once there is a way to 2161 # install selected tests, the shared libraries they depend on 2162 # need to be installed as well. 2164 if (ARGN_RUNTIME_DESTINATION)
2165 list (APPEND DESTINATION_OPTS
2167 DESTINATION
"${ARGN_RUNTIME_DESTINATION}" 2168 COMPONENT
"${ARGN_RUNTIME_COMPONENT}" 2171 if (ARGN_LIBRARY_DESTINATION)
2172 list (APPEND DESTINATION_OPTS
2174 DESTINATION
"${ARGN_LIBRARY_DESTINATION}" 2175 COMPONENT
"${ARGN_LIBRARY_COMPONENT}" 2177 DESTINATION
"${ARGN_LIBRARY_DESTINATION}" 2178 COMPONENT
"${ARGN_LIBRARY_COMPONENT}" 2182 if (DESTINATION_OPTS)
2183 install (TARGETS ${TARGET_UID} ${EXPORT_OPT} ${DESTINATION_OPTS})
2186 message (STATUS
"Adding ${type} library ${TARGET_UID}... - done")
2189 # ---------------------------------------------------------------------------- 2190 ## @brief Add script library target. 2192 # @note This function should not be used directly. Instead, it is called 2193 # by basis_add_library() if the (detected) programming language 2194 # of the given source code files is neither @c CXX (i.e., C/C++) nor 2197 # This function adds a build target for libraries which are a collection of 2198 # one or more modules written in a scripting language. The relative paths 2199 # of the modules relative to the library's @p SOURCE_DIRECTORY property are 2200 # preserved. This is important for the most widely used scripting languages 2201 # such as Python, Perl, or MATLAB, where the file path relative to the 2202 # package root directory defines the package namespace. 2204 # A custom CMake build target with the following properties is added by this 2205 # function to the build system. These properties are used by 2206 # basis_build_script_library() to generate a build script written in CMake 2207 # code which is executed by a custom CMake command. Before the invokation of 2208 # basis_build_script_library(), the target properties can be modified using 2209 # basis_set_target_properties(). 2211 # @note Custom BASIS build targets are finalized by BASIS using basis_project_end(), 2212 # i.e., the end of the root CMake configuration file of the (sub-)project. 2214 # @par Properties on script library targets 2217 # @tp @b BASIS_TYPE @endtp 2218 # <td>Read-only property with value "SCRIPT_LIBRARY" for script library targets.</td> 2221 # @tp @b BASIS_UTILITIES @endtp 2222 # <td>Whether the BASIS utilities are used by any module of this library. 2223 # For the supported scripting languages for which BASIS utilities are 2224 # implemented, BASIS will in most cases automatically detect whether 2225 # these utilities are used by a module or not. Otherwise, set this 2226 # property manually or use either the @p USE_BASIS_UTILITIES or the 2227 # @p NO_BASIS_UTILITIES option when adding the library target. 2228 # (default: auto-detected or @c UNKNOWN)</td> 2231 # @tp @b BINARY_DIRECTORY @endtp 2232 # <td>Build tree directory of this target. (default: @c CMAKE_CURRENT_BINARY_DIR)</td> 2235 # @tp @b COMPILE @endtp 2236 # <td>Whether to compile the library, respectively, it's modules if the 2237 # programming language allows such pre-compilation as in case of Python, 2238 # for example. If @c TRUE, only the compiled files are installed. 2239 # (default: @c BASIS_COMPILE_SCRIPTS)</td> 2242 # @tp @b SCRIPT_DEFINITIONS @endtp 2243 # <td>CMake code which is evaluated after the inclusion of the default script 2244 # configuration files. This code can be used to set the replacement text of the 2245 # CMake variables ("@VAR@" patterns) used in the source files. 2246 # See <a href="https://cmake-basis.github.io/standard/scripttargets.html#script-configuration"> 2247 # Build System Standard</a> for details. (default: "")</td> 2250 # @tp @b SCRIPT_DEFINITIONS_FILE @endtp 2251 # <td>CMake script file with compile definitions, also referred to as script 2252 # configuration file. The named files are included after the default BASIS 2253 # script configuration and before the @c SCRIPT_DEFINITIONS code is being 2254 # evaluated. (default: @c BINARY_CONFIG_DIR/ScriptConfig.cmake)</td> 2257 # @tp @b EXPORT @endtp 2258 # <td>Whether to export this build target in which case an import library 2259 # target is added to the custom exports file with the path to the 2260 # built/installed modules set as @c IMPORT_LOCATION. (default: @c TRUE)</td> 2263 # @tp @b LANGUAGE @endtp 2264 # <td>Read-only property of programming language of modules in uppercase letters. 2265 # (default: see @p LANGUAGE argument)</td> 2268 # @tp @b LIBRARY_COMPONENT @endtp 2269 # <td>Name of component as part of which this library is installed if 2270 # @c LIBRARY_INSTALL_DIRECTORY is not set to "none". 2271 # (default: see @p COMPONENT argument)</td> 2274 # @tp @b LIBRARY_INSTALL_DIRECTORY @endtp 2275 # <td>Installation directory of library configured for use in installation tree 2276 # relative to @c CMAKE_INSTALL_PREFIX. Set to "none" (case-insensitive) to skip the 2277 # addition of an installation rule. 2278 # (default: <tt>INSTALL_<LANGUAGE>_LIBRARY_DIR</tt> if defined or 2279 # @c INSTALL_LIBRARY_DIR otherwise)</td> 2282 # @tp @b LIBRARY_OUTPUT_DIRECTORY @endtp 2283 # <td>Output directory of library configured for use within the build tree. 2284 # (default: <tt>BINARY_<LANGUAGE>_LIBRARY_DIR</tt> if defined or 2285 # @c BINARY_LIBRARY_DIR otherwise)</td> 2288 # @tp @b LINK_DEPENDS @endtp 2289 # <td>Paths or target names of script modules and libraries used by this script. 2290 # For each listed build target, a dependency is added between this 2291 # library target and the named build targets. Use basis_target_link_libraries() 2292 # to add additional link dependencies. Further note that if this library is 2293 # a link dependency of an executable script added by basis_add_executable() 2294 # (i.e., basis_add_script() actually), the link dependencies of this library 2295 # are inherited by the executable script. 2296 # (default: BASIS utilities module if used or empty list otherwise)</td> 2299 # @tp @b PREFIX @endtp 2300 # <td>Common module prefix. The given directory path is appended to both 2301 # @c LIBRAR_OUTPUT_DIRECTORY and @c LIBRARY_INSTALL_DIRECTORY and can, 2302 # for example, be used to install modules of a Python package as part of 2303 # another Python package, where @c LIBRARY_OUTPUT_DIRECTORY or 2304 # @c LIBRARY_INSTALL_DIRECTORY, respectively, is the directory of the 2305 # main package which is added to the @c PYTHONPATH. Possibly missing 2306 # __init__.py files in case of Python are generated by the _initpy target 2307 # which is automatically added by BASIS in that case and further added to 2308 # the dependencies of this library target. 2309 # (default: @c PROJECT_NAMESPACE_PYTHON if @c LANGUAGE is @c PYTHON with 2310 # periods (.) replaced by slashes (/), @c PROJECT_NAMESPACE_PERL if 2311 # @c LANGUAGE is @c PERL with <tt>::</tt> replaced by slashes (/), 2312 # and "" otherwise)</td> 2315 # @tp @b SOURCE_DIRECTORY @endtp 2316 # <td>Source directory of this target. This directory is in particular 2317 # used to convert the paths of the given source files to relative paths. 2318 # The built modules within the build and installation tree will have the 2319 # same relative path (relative to the @c LIBRARY_OUTPUT_DIRECTORY or 2320 # @c LIBRARY_INSTALL_DIRECTORY, respectively). 2321 # (default: @c CMAKE_CURRENT_SOURCE_DIR)</td> 2324 # @tp @b SOURCES @endtp 2325 # <td>Read-only property which lists the source files of this library. 2326 # Note that the first element in this list actually names a directory 2327 # in the build, the one where the build script for this target is located 2328 # instead of a source file and thus should be ignored.</td> 2332 # @attention Properties documented as read-only must not be modified. 2334 # @param [in] TARGET_NAME Name of build target. 2335 # @param [in] ARGN The remaining arguments are parsed and the following 2336 # arguments extracted. All unparsed arguments are treated 2337 # as the module files of the script library. 2341 # @tp @b COMPONENT name @endtp 2342 # <td>Name of installation component as part of which this library is being 2343 # installed if the @c LIBRARY_INSTALL_DIRECTORY property is not "none". 2344 # (default: @c BASIS_LIBRARY_COMPONENT)</td> 2347 # @tp @b DESTINATION dir @endtp 2348 # <td>Installation directory for library relative to @c CMAKE_INSTALL_PREFIX. 2349 # If an absolute path is given as argument, it is made relative to the 2350 # configured installation prefix. (default: @c INSTALL_LIBRARY_DIR)</td> 2353 # @tp @b LANGUAGE lang @endtp 2354 # <td>Programming language in which modules are written (case-insensitive). 2355 # If not specified, the programming language is derived from the file name 2356 # extensions of the source files and the shebang directive on the first line 2357 # of each module if any. If the programming language could not be detected 2358 # automatically, the @c LANGUAGE property is set to @c UNKNOWN. Note that 2359 # for script library targets, the library may still be built correctly 2360 # even if the scripting language was not recognized. The automatic detection 2361 # whether the BASIS utilities are used and required will fail, however. 2362 # In this case, specify the programming language using this option. 2363 # (default: auto-detected or @c UNKNOWN)</td> 2366 # @tp @b [NO]EXPORT @endtp 2367 # <td>Whether to export this target. (default: @c TRUE)</td> 2370 # @tp @b NO_BASIS_UTILITIES @endtp 2371 # <td>Specify that the BASIS utilities are not used by this library. If the 2372 # programming language of the modules is known and BASIS utilities are 2373 # available for this language, BASIS will in most cases automatically 2374 # detect whether these utilities are used by any module of this library. 2375 # Use this option to skip this check in the case that no module makes 2376 # use of the BASIS utilities.</td> 2379 # @tp @b USE_BASIS_UTILITIES @endtp 2380 # <td>Specify that the BASIS utilities are used and thus required by this library. 2381 # If the programming language of the modules is known and BASIS utilities are 2382 # available for this language, BASIS will in most cases automatically 2383 # detect whether these utilities are used by any module of this library. 2384 # Use this option to skip this check when it is already known that no module 2385 # makes use of the BASIS utilities. Note that an error is raised if this option 2386 # is given, but no BASIS utilities are available for the programming language 2387 # of this script or if the programming language is unknown, respectively, not 2388 # detected correctly. In this case, consider the use of the @p LANGUAGE argument.</td> 2391 # @tp @b FINAL @endtp 2392 # <td>Finalize custom targets immediately. Any following target property changes 2393 # will have no effect. When this option is used, the custom target which 2394 # executes the custom build command is added in the current working directory. 2395 # Otherwise it will be added in the top-level source directory of the project. 2396 # Which with the Visual Studio generators adds the corresponding Visual Studio 2397 # Project files directly to the top-level build directory. This can be avoided 2398 # using this option or calling basis_finalize_targets() at the end of each 2399 # CMakeLists.txt file.</td> 2403 # @returns Adds a custom CMake target with the documented properties. The actual custom 2404 # command to build the library is added by basis_build_script_library(). 2406 # @sa basis_add_library() 2411 message (STATUS
"Adding script library ${TARGET_UID}...")
2412 # dump CMake variables for configuration of script 2413 set (BUILD_DIR
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TARGET_UID}")
2416 CMAKE_PARSE_ARGUMENTS (
2418 "NO_BASIS_UTILITIES;USE_BASIS_UTILITIES;EXPORT;NOEXPORT;FINAL" 2419 "COMPONENT;DESTINATION;LANGUAGE" 2424 set (SOURCES
"${ARGN_UNPARSED_ARGUMENTS}")
2427 if (CMAKE_CURRENT_SOURCE_DIR MATCHES
"^${RE}")
2432 # check source files 2434 foreach (S IN LISTS SOURCES)
2436 if (NOT EXISTS
"${S}" AND NOT S MATCHES
"\\.in$" AND EXISTS
"${S}.in" AND NOT IS_DIRECTORY
"${S}.in")
2438 elseif (IS_DIRECTORY
"${S}")
2439 message (FATAL_ERROR
"Target ${TARGET_UID}: Directory ${S} given where file name expected!")
2441 if (NOT EXISTS
"${S}")
2442 string (REGEX REPLACE
"\\.in$" "" S
"${S}")
2443 message (FATAL_ERROR
"Target ${TARGET_UID}: Source file ${S}[.in] does not exist!")
2445 list (APPEND _SOURCES
"${S}")
2448 message (FATAL_ERROR
"Target ${TARGET_UID}: No source files specified!")
2450 set (SOURCES
"${_SOURCES}")
2452 # auto-detect programming language (may be as well UNKNOWN) 2453 string (TOUPPER
"${ARGN_LANGUAGE}" ARGN_LANGUAGE)
2454 if (NOT ARGN_LANGUAGE)
2456 if (ARGN_LANGUAGE MATCHES
"AMBIGUOUS|UNKNOWN")
2457 message (FATAL_ERROR
"Target ${TARGET_UID}: Failed to determine programming" 2458 " language of modules! Make sure that all modules are" 2459 " written in the same language and that the used programming" 2460 " language is supported by BASIS, i.e., either Python (Jython)," 2461 " Perl, Bash, or MATLAB. Otherwise, try to specify the language" 2462 " explicitly using the LANGUAGE option.")
2467 if (DEFINED TESTING_${ARGN_LANGUAGE}_LIBRARY_DIR)
2468 set (OUTPUT_DIRECTORY
"${TESTING_${ARGN_LANGUAGE}_LIBRARY_DIR}")
2470 set (OUTPUT_DIRECTORY
"${TESTING_LIBRARY_DIR}")
2473 if (DEFINED BINARY_${ARGN_LANGUAGE}_LIBRARY_DIR)
2474 set (OUTPUT_DIRECTORY
"${BINARY_${ARGN_LANGUAGE}_LIBRARY_DIR}")
2476 set (OUTPUT_DIRECTORY
"${BINARY_LIBRARY_DIR}")
2479 # installation component 2480 if (NOT ARGN_COMPONENT)
2481 set (ARGN_COMPONENT
"${BASIS_LIBRARY_COMPONENT}")
2483 if (NOT ARGN_COMPONENT)
2484 set (ARGN_COMPONENT
"Unspecified")
2486 # installation directory 2488 if (ARGN_DESTINATION)
2489 message (WARNING
"Target ${TARGET_UID} is a library used for testing only." 2490 " Installation to the specified directory will be skipped.")
2491 set (ARGN_DESTINATION)
2494 if (ARGN_DESTINATION)
2495 if (IS_ABSOLUTE
"${ARGN_DESTINATION}")
2496 file (RELATIVE_PATH ARGN_DESTINATION
"${CMAKE_INSTALL_PREFIX}" "${ARGN_DESTINATION}")
2499 if (DEFINED INSTALL_${ARGN_LANGUAGE}_LIBRARY_DIR)
2500 set (ARGN_DESTINATION
"${INSTALL_${ARGN_LANGUAGE}_LIBRARY_DIR}")
2502 set (ARGN_DESTINATION
"${INSTALL_LIBRARY_DIR}")
2506 # common module prefix 2507 if (ARGN_LANGUAGE MATCHES
"^([JP]YTHON|PERL|MATLAB|BASH)$")
2512 # script configuration ("compile definitions") 2513 if (EXISTS
"${BINARY_CONFIG_DIR}/ScriptConfig.cmake")
2514 set (
CONFIG_FILE "${BINARY_CONFIG_DIR}/ScriptConfig.cmake")
2518 # auto-detect use of BASIS utilities 2519 if (ARGN_LANGUAGE MATCHES
"[JP]YTHON")
2520 set (UTILITIES_LANGUAGE
"PYTHON")
2522 set (UTILITIES_LANGUAGE
"${ARGN_LANGUAGE}")
2524 if (ARGN_USE_BASIS_UTILITIES)
2526 message (FATAL_ERROR
"Target ${TARGET_UID} requires the BASIS utilities for ${UTILITIES_LANGUAGE}" 2527 " but BASIS was either build without the build of these utilities enabled" 2528 " or no utilities for this programming language are implemented. Remove the" 2529 " USE_BASIS_UTILITIES option if no BASIS utilities are used by the modules" 2530 " of the library or specify the correct programming language if it was not" 2531 " detected correctly.")
2533 set (USES_BASIS_UTILITIES TRUE)
2534 elseif (
BASIS_UTILITIES AND NOT ARGN_NO_BASIS_UTILITIES AND NOT UTILITIES_LANGUAGE MATCHES
"UNKNOWN")
2535 set (USES_BASIS_UTILITIES FALSE)
2536 foreach (M IN LISTS SOURCES)
2538 if (USES_BASIS_UTILITIES)
2543 set (USES_BASIS_UTILITIES FALSE)
2546 add_custom_target (${TARGET_UID} ALL SOURCES ${SOURCES})
2551 BASIS_TYPE
"SCRIPT_LIBRARY" 2553 BUILD_DIRECTORY
"${BUILD_DIR}" 2554 SOURCE_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}" 2555 BINARY_DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}" 2556 LIBRARY_OUTPUT_DIRECTORY
"${OUTPUT_DIRECTORY}" 2557 LIBRARY_INSTALL_DIRECTORY
"${ARGN_DESTINATION}" 2558 LIBRARY_COMPONENT
"${BASIS_LIBRARY_COMPONENT}" 2560 SCRIPT_DEFINITIONS
"" 2561 SCRIPT_DEFINITIONS_FILE
"${CONFIG_FILE}" 2564 COMPILE
"${BASIS_COMPILE_SCRIPTS}" 2567 # link to BASIS utilities
2568 if (USES_BASIS_UTILITIES)
2571 message (
"** Target ${TARGET_UID} uses the BASIS utilities for ${UTILITIES_LANGUAGE}.")
2578 # add target to list of targets 2580 message (STATUS
"Adding script library ${TARGET_UID}... - done")
2583 # ============================================================================ 2584 # custom build commands 2585 # ============================================================================ 2587 # ---------------------------------------------------------------------------- 2588 ## @brief Set INSTALL_RPATH property of executable or shared library target. 2590 # This function sets the @c INSTALL_RPATH property of a specified executable or 2591 # shared library target using the @c LINK_DEPENDS obtained using the 2592 # basis_get_target_link_libraries() function. It determines the installation 2593 # location of each dependency using the basis_get_target_location() function. 2595 # @returns Sets the @c INSTALL_RPATH property of the specified target. 2597 # @sa basis_get_target_link_libraries() 2601 message (STATUS
"Setting INSTALL_RPATH property of ${TARGET_UID}...")
2603 if (NOT TARGET
"${TARGET_UID}")
2604 message (FATAL_ERROR
"Unknown target: ${TARGET_UID}")
2607 message (
"** basis_set_target_install_rpath():")
2608 message (
"** TARGET_NAME: ${TARGET_UID}")
2610 if (CMAKE_HOST_APPLE)
2611 set (ORIGIN
"@loader_path")
2613 set (ORIGIN
"\$ORIGIN")
2615 # always prefer libraries located within the same directory 2616 set (INSTALL_RPATH
"${ORIGIN}/.")
2617 # common
default RPATH (rarely used)
2618 if (CMAKE_INSTALL_RPATH)
2619 set (INSTALL_RPATH
"${INSTALL_RPATH};${CMAKE_INSTALL_RPATH}")
2621 # get location of target used to make paths relative to this $ORIGIN 2623 # directories of external projects belonging to same bundle
which 2626 foreach (
LINK_DIR ${BUNDLE_LINK_DIRS})
2627 list (FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
"${LINK_DIR}" IDX)
2630 message (
"** BUNDLE_LINK_DIR: ${LINK_DIR}")
2633 list (APPEND INSTALL_RPATH
"${ORIGIN}/${RPATH}")
2636 # directories of link libraries 2638 # only the libraries of this project and targets imported 2639 # from other projects which are part of the same bundle 2642 message (
"** LINK_DEPENDS: [${LINK_DEPENDS}]")
2644 foreach (LINK_DEPEND ${LINK_DEPENDS})
2645 set (DEPEND_LOCATION)
2646 if (TARGET
"${LINK_DEPEND}")
2648 if (
"^${LINK_TYPE}$" STREQUAL
"^SHARED_LIBRARY$")
2651 if (NOT IMPORTED OR BUNDLED)
2654 message (
"** LOCATION(${LINK_DEPEND}): ${DEPEND_LOCATION}")
2658 elseif (IS_ABSOLUTE
"${LINK_DEPEND}")
2659 if (IS_DIRECTORY
"${LINK_DEPEND}")
2660 set (DEPEND_LOCATION
"${LINK_DEPEND}")
2664 list (FIND BUNDLE_LINK_DIRS
"${DEPEND_LOCATION}" IDX)
2666 set (DEPEND_LOCATION)
2669 if (DEPEND_LOCATION)
2670 list (FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
"${DEPEND_LOCATION}" IDX)
2673 list (APPEND INSTALL_RPATH
"${ORIGIN}/${RPATH}")
2679 list (REMOVE_DUPLICATES INSTALL_RPATH)
2681 # set INSTALL_RPATH property 2684 message (
"** INSTALL_RPATH: [${INSTALL_RPATH}]")
2687 message (STATUS
"Setting INSTALL_RPATH property of ${TARGET_UID}... - done")
2691 # ---------------------------------------------------------------------------- 2692 ## @brief Add custom command for build of single script. 2694 # This function is called by basis_finalize_targets() which in turn is called 2695 # by basis_project_end(), i.e., the end of the root CMake configuration file 2696 # of the (sub-)project. 2698 # @param [in] TARGET_UID Name/UID of custom target added by basis_add_script(). 2700 # @sa basis_add_script() 2702 # does
this target exist ?
2704 if (NOT TARGET
"${TARGET_UID}")
2705 message (FATAL_ERROR
"Unknown build target: ${TARGET_UID}")
2708 message (STATUS
"Adding build command for target ${TARGET_UID}...")
2710 # get target properties 2712 # including BASIS utilities
if used
2715 LANGUAGE # programming language of script
2716 BASIS_TYPE # must
match "^SCRIPT_(EXECUTABLE|LIBEXEC|MODULE)$" 2717 BUILD_DIRECTORY # CMakeFiles build directory
2718 SOURCE_DIRECTORY # CMake source directory
2719 BINARY_DIRECTORY # CMake binary directory
2720 OUTPUT_DIRECTORY # output directory
for built script
2721 INSTALL_DIRECTORY # installation directory
for built script
2722 COMPONENT # installation component
2723 OUTPUT_NAME # name of built script including extension (
if any)
2724 PREFIX # name prefix
2725 SUFFIX # name suffix (
e.g., extension
for executable script)
2726 SCRIPT_DEFINITIONS # CMake code to
set variables used to configure script
2727 SCRIPT_DEFINITIONS_FILE # script configuration file
2728 EXPORT # whether
this target shall be exported
2729 COMPILE # whether to compile script
if applicable
2730 SOURCES # path of script source file
2732 get_target_property (IS_TEST ${TARGET_UID} TEST) # whether
this script
is used
for testing only
2733 foreach (PROPERTY ${PROPERTIES})
2734 get_target_property (${PROPERTY} ${TARGET_UID} ${PROPERTY})
2736 set (EXECUTABLE FALSE)
2739 if (BASIS_TYPE MATCHES
"^SCRIPT_(EXECUTABLE|LIBEXEC|MODULE)$")
2740 set (${CMAKE_MATCH_1} TRUE)
2742 set (EXECUTABLE TRUE)
2745 message (FATAL_ERROR
"Target ${TARGET_UID}: Unexpected BASIS_TYPE: ${BASIS_TYPE}")
2747 if (NOT BINARY_DIRECTORY)
2748 message (FATAL_ERROR
"Target ${TARGET_UID}: Missing BINARY_DIRECTORY property!")
2750 file (RELATIVE_PATH _relpath
"${CMAKE_BINARY_DIR}" "${BINARY_DIRECTORY}")
2751 if (_relpath MATCHES
"^\\.\\./")
2752 message (FATAL_ERROR
"Target ${TARGET_UID}: BINARY_DIRECTORY must be inside of build tree!")
2755 if (INSTALL_DIRECTORY AND NOT COMPONENT)
2756 set (COMPONENT
"Unspecified")
2758 list (GET SOURCES 0 BUILD_DIR)
# CMake <3.1 stores path to internal build directory here 2759 if (BUILD_DIR MATCHES
"CMakeFiles")
2760 list (REMOVE_AT SOURCES 0)
2762 list (LENGTH SOURCES L)
2764 message (FATAL_ERROR
"Target ${TARGET_UID}: Expected one element in SOURCES list!" 2765 " Have you modified this (read-only) property or is your" 2766 " (newer) CMake version not compatible with BASIS?")
2768 set (SOURCE_FILE
"${SOURCES}")
2769 set (BUILD_DIR
"${BUILD_DIRECTORY}.dir")
2770 # output directory and name 2771 if (NOT OUTPUT_NAME)
2775 set (OUTPUT_NAME
"${PREFIX}${OUTPUT_NAME}")
2778 set (OUTPUT_NAME
"${OUTPUT_NAME}${SUFFIX}")
2780 if (CMAKE_GENERATOR MATCHES
"Visual Studio|Xcode")
2781 set (OUTPUT_FILE
"${BUILD_DIR}/build/${OUTPUT_NAME}")
2782 set (OUTPUT_DIR
"${OUTPUT_DIRECTORY}/$<${BASIS_GE_CONFIG}>")
2783 elseif (MODULE AND COMPILE)
2784 set (OUTPUT_FILE
"${BUILD_DIR}/build/${OUTPUT_NAME}")
2785 set (OUTPUT_DIR
"${OUTPUT_DIRECTORY}")
2787 set (OUTPUT_FILE
"${OUTPUT_DIRECTORY}/${OUTPUT_NAME}")
2790 # arguments of build script 2791 if (INSTALL_DIRECTORY)
2794 set (INSTALL_FILE
"${BUILD_DIR}/install/${SOURCE_NAME}")
2795 string (REGEX REPLACE
"\\.in$" "" INSTALL_FILE
"${INSTALL_FILE}")
2797 set (INSTALL_FILE
"${BUILD_DIR}/install/${OUTPUT_NAME}")
2799 set (DESTINATION
"${INSTALL_DIRECTORY}")
2800 if (NOT IS_ABSOLUTE
"${DESTINATION}")
2801 set (DESTINATION
"${CMAKE_INSTALL_PREFIX}/${DESTINATION}")
2808 if (EXISTS
"${BASIS_SCRIPT_CONFIG_FILE}")
2809 list (APPEND CONFIG_FILES
"${BASIS_SCRIPT_CONFIG_FILE}")
2811 if (SCRIPT_DEFINITIONS_FILE)
2812 list (APPEND CONFIG_FILES
"${SCRIPT_DEFINITIONS_FILE}")
2814 if (SCRIPT_DEFINITIONS)
2815 set (SCRIPT_CONFIG_FILE
"${BUILD_DIR}/ScriptConfig.cmake")
2816 file (WRITE
"${SCRIPT_CONFIG_FILE}.tmp" "# DO NOT edit. Automatically generated by BASIS.\n${SCRIPT_DEFINITIONS}\n")
2817 execute_process (
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${SCRIPT_CONFIG_FILE}.tmp" "${SCRIPT_CONFIG_FILE}")
2818 file (REMOVE
"${SCRIPT_CONFIG_FILE}.tmp")
2819 list (APPEND CONFIG_FILES
"${SCRIPT_CONFIG_FILE}")
2821 set (CACHE_FILE
"${BUILD_DIR}/cache.cmake")
2822 execute_process (
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${CACHE_FILE}.tmp" "${CACHE_FILE}")
2823 file (REMOVE
"${CACHE_FILE}.tmp")
2825 foreach (FLAG IN ITEMS COMPILE EXECUTABLE)
2827 list (APPEND OPTIONS ${FLAG})
2830 # link dependencies - module search paths 2831 set (BUILD_LINK_DEPENDS)
2832 set (INSTALL_LINK_DEPENDS)
2833 foreach (LINK_DEPEND IN LISTS LINK_DEPENDS)
2835 if (TARGET
"${UID}")
2836 get_target_property (IMPORTED ${UID} IMPORTED)
2837 get_target_property (BUNDLED ${UID} BUNDLED)
2838 if (IMPORTED AND NOT BUNDLED)
2841 list (APPEND BUILD_LINK_DEPENDS
"${LOCATION}")
2842 list (APPEND INSTALL_LINK_DEPENDS
"${LOCATION}")
2844 message (WARNING
"Could not determine build tree location of file corresponding to target ${UID}")
2849 list (APPEND BUILD_LINK_DEPENDS
"${LOCATION}")
2851 message (WARNING
"Could not determine build tree location of file corresponding to target ${UID}")
2854 if (NOT LINK_DEPEND_IS_TEST)
2857 list (APPEND INSTALL_LINK_DEPENDS
"relative ${LOCATION}")
2859 message (WARNING
"Could not determine installation location of file corresponding to target ${UID}")
2864 list (APPEND BUILD_LINK_DEPENDS
"${LINK_DEPEND}")
2865 list (APPEND INSTALL_LINK_DEPENDS
"${LINK_DEPEND}")
2868 # prepend own module search paths - if dependencies among own modules 2869 # not specified or to ensure that 2870 # these are preferred 2873 list (INSERT BUILD_LINK_DEPENDS 0
"${BINARY_PYTHON_LIBRARY_DIR}")
2876 list (INSERT INSTALL_LINK_DEPENDS 0
"relative ${CMAKE_INSTALL_PREFIX}/${INSTALL_PYTHON_LIBRARY_DIR}")
2879 if (BINARY_${
LANGUAGE}_LIBRARY_DIR)
2880 list (INSERT BUILD_LINK_DEPENDS 0
"${BINARY_${LANGUAGE}_LIBRARY_DIR}")
2882 if (INSTALL_${
LANGUAGE}_LIBRARY_DIR)
2883 list (INSERT INSTALL_LINK_DEPENDS 0
"relative ${CMAKE_INSTALL_PREFIX}/${INSTALL_${LANGUAGE}_LIBRARY_DIR}")
2885 list (INSERT BUILD_LINK_DEPENDS 0
"${BINARY_LIBRARY_DIR}")
2886 list (INSERT INSTALL_LINK_DEPENDS 0
"relative ${CMAKE_INSTALL_PREFIX}/${INSTALL_LIBRARY_DIR}")
2888 list (INSERT BUILD_LINK_DEPENDS 0
"${TESTING_LIBRARY_DIR}")
2890 if (BUILD_LINK_DEPENDS)
2891 list (REMOVE_DUPLICATES BUILD_LINK_DEPENDS)
2893 if (INSTALL_LINK_DEPENDS)
2894 list (REMOVE_DUPLICATES INSTALL_LINK_DEPENDS)
2896 # remove default site-packages directories 2897 if (
LANGUAGE MATCHES
"[JP]YTHON|PERL")
2898 list (REMOVE_ITEM BUILD_LINK_DEPENDS
"${${LANGUAGE}_SITELIB}")
2899 list (REMOVE_ITEM INSTALL_LINK_DEPENDS
"${${LANGUAGE}_SITELIB}")
2901 # configure build script 2903 configure_file (
"${BASIS_MODULE_PATH}/configure_script.cmake.in" "${BUILD_SCRIPT}" @ONLY)
2904 # list of all output files 2905 set (OUTPUT_FILES
"${OUTPUT_FILE}")
2907 list (APPEND OUTPUT_FILES
"${INSTALL_FILE}")
2909 if (MODULE AND COMPILE)
2913 list (APPEND OUTPUT_FILES
"${OUTPUT_CFILE}")
2916 list (APPEND OUTPUT_FILES
"${INSTALL_CFILE}")
2923 if (JYTHON_OUTPUT_CFILE)
2924 list (APPEND OUTPUT_FILES
"${JYTHON_OUTPUT_CFILE}")
2926 if (JYTHON_INSTALL_CFILE)
2927 list (APPEND OUTPUT_FILES
"${JYTHON_INSTALL_CFILE}")
2932 # add build command for script 2934 file (RELATIVE_PATH REL
"${CMAKE_BINARY_DIR}" "${OUTPUT_CFILE}")
2936 file (RELATIVE_PATH REL
"${CMAKE_BINARY_DIR}" "${OUTPUT_FILE}")
2939 set (COMMENT
"Building script ${REL}...")
2941 set (COMMENT
"Building ${LANGUAGE} module ${REL}...")
2943 set (COMMENT
"Building ${LANGUAGE} executable ${REL}...")
2945 add_custom_command (
2946 OUTPUT ${OUTPUT_FILES}
2947 COMMAND "${CMAKE_COMMAND}" -D
"CONFIGURATION:STRING=$<${BASIS_GE_CONFIG}>" -P
"${BUILD_SCRIPT}" 2948 MAIN_DEPENDENCY
"${SOURCE_FILE}" 2950 COMMENT
"${COMMENT}" 2954 add_custom_target (_${TARGET_UID} DEPENDS ${OUTPUT_FILES})
2955 foreach (T IN LISTS LINK_DEPENDS)
2957 add_dependencies (_${TARGET_UID} ${T})
2960 add_dependencies (${TARGET_UID} _${TARGET_UID})
2961 # cleanup on
"make clean" - including compiled files regardless of COMPILE flag
2962 set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${OUTPUT_FILES})
2963 foreach (OUTPUT_FILE IN LISTS OUTPUT_FILES)
2966 list (FIND OUTPUT_FILES
"${CFILE}" IDX)
2968 set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
"${CFILE}")
2972 # copy configured (and compiled) script to (configuration specific) output directory 2976 add_custom_command (
2977 TARGET _${TARGET_UID} POST_BUILD
2978 COMMAND "${CMAKE_COMMAND}" -E copy
"${OUTPUT_CFILE}" "${OUTPUT_DIR}/${OUTPUT_CNAME}" 2980 set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
"${OUTPUT_DIR}/${OUTPUT_CNAME}")
2981 if (JYTHON_OUTPUT_CFILE)
2983 add_custom_command (
2984 TARGET _${TARGET_UID} POST_BUILD
2985 COMMAND "${CMAKE_COMMAND}" -E copy
"${JYTHON_OUTPUT_CFILE}" "${OUTPUT_DIR}/${OUTPUT_CNAME}" 2987 set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
"${OUTPUT_DIR}/${OUTPUT_CNAME}")
2990 add_custom_command (
2991 TARGET _${TARGET_UID} POST_BUILD
2992 COMMAND "${CMAKE_COMMAND}" -E copy
"${OUTPUT_FILE}" "${OUTPUT_DIR}/${OUTPUT_NAME}" 2994 set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
"${OUTPUT_DIR}/${OUTPUT_NAME}")
3002 if (INSTALL_DIRECTORY)
3004 if (MODULE AND
LANGUAGE MATCHES
"PYTHON")
3007 basis_get_compiled_script (INSTALL_JYTHON_CFILE
"${INSTALL_FILE}" JYTHON)
3011 string (REGEX REPLACE
"^${LIBRE}/" "${INSTALL_JYTHON_LIBRARY_DIR}/" INSTALL_DIRECTORY_JYTHON
"${INSTALL_DIRECTORY}")
3013 string (REGEX REPLACE
"^${SITERE}/" "${INSTALL_JYTHON_SITE_DIR}/" INSTALL_DIRECTORY_JYTHON
"${INSTALL_DIRECTORY}")
3015 set (INSTALL_DIRECTORY_JYTHON
"${INSTALL_DIRECTORY}")
3018 FILES
"${INSTALL_JYTHON_CFILE}" 3019 DESTINATION
"${INSTALL_DIRECTORY_JYTHON}" 3020 COMPONENT
"${COMPONENT}" 3024 set (INSTALL_FILE
"${INSTALL_CFILE}")
3025 elseif (NOT INSTALL_FILE)
3026 set (INSTALL_FILE
"${OUTPUT_FILE}")
3029 set (INSTALLTYPE FILES)
3031 set (INSTALLTYPE PROGRAMS)
3034 ${INSTALLTYPE}
"${INSTALL_FILE}" 3035 DESTINATION
"${INSTALL_DIRECTORY}" 3036 COMPONENT
"${COMPONENT}" 3037 RENAME
"${OUTPUT_NAME}" 3042 message (STATUS
"Adding build command for target ${TARGET_UID}... - done")
3046 # ---------------------------------------------------------------------------- 3047 ## @brief Add custom command for build of script library. 3049 # This function is called by basis_finalize_targets() which in turn is called 3050 # by basis_project_end(), i.e., the end of the root CMake configuration file 3051 # of the (sub-)project. 3053 # @param [in] TARGET_UID Name/UID of custom target added by basis_add_script_library(). 3055 # @sa basis_add_script_library() 3057 # does
this target exist ?
3059 if (NOT TARGET
"${TARGET_UID}")
3060 message (FATAL_ERROR
"Unknown target: ${TARGET_UID}")
3063 message (STATUS
"Adding build command for target ${TARGET_UID}...")
3065 # get target properties 3067 # including BASIS utilities
if used
3070 LANGUAGE # programming language of modules
3071 BASIS_TYPE # must be
"SCRIPT_LIBRARY" 3073 BUILD_DIRECTORY # CMakeFiles build directory
3074 SOURCE_DIRECTORY # CMake source directory
3075 BINARY_DIRECTORY # CMake binary directory
3076 LIBRARY_OUTPUT_DIRECTORY # output directory
for built modules
3077 LIBRARY_INSTALL_DIRECTORY # installation directory
for built modules
3078 LIBRARY_COMPONENT # installation component
3079 PREFIX # common prefix
for modules
3080 SCRIPT_DEFINITIONS # CMake code to
set variables used to configure modules
3081 SCRIPT_DEFINITIONS_FILE # script configuration file
3082 LINK_DEPENDS # paths of script modules/packages used by the modules of
this library
3083 EXPORT # whether to export
this target
3084 COMPILE # whether to compile the modules/library
if applicable
3085 SOURCES # source files of module scripts
3087 get_target_property (IS_TEST ${TARGET_UID} TEST) # whether
this script
is used
for testing only
3088 foreach (PROPERTY ${PROPERTIES})
3089 get_target_property (${PROPERTY} ${TARGET_UID} ${PROPERTY})
3091 if (NOT BASIS_TYPE MATCHES
"^SCRIPT_LIBRARY$")
3092 message (FATAL_ERROR
"Target ${TARGET_UID}: Unexpected BASIS_TYPE: ${BASIS_TYPE}")
3094 if (NOT SOURCE_DIRECTORY)
3095 message (FATAL_ERROR
"Missing SOURCE_DIRECTORY property!")
3097 if (NOT LIBRARY_OUTPUT_DIRECTORY)
3098 message (FATAL_ERROR
"Missing LIBRARY_OUTPUT_DIRECTORY property!")
3100 if (NOT IS_ABSOLUTE
"${LIBRARY_OUTPUT_DIRECTORY}")
3101 set (LIBRARY_OUTPUT_DIRECTORY
"${TOPLEVEL_PROJECT_BINARY_DIR}/${LIBRARY_OUTPUT_DIRECTORY}")
3103 file (RELATIVE_PATH _relpath
"${CMAKE_BINARY_DIR}" "${LIBRARY_OUTPUT_DIRECTORY}")
3104 if (_relpath MATCHES
"^\\.\\./")
3105 message (FATAL_ERROR
"Output directory LIBRARY_OUTPUT_DIRECTORY is outside the build tree!")
3108 if (NOT LIBRARY_COMPONENT)
3109 set (LIBRARY_COMPONENT
"Unspecified")
3111 list (GET SOURCES 0 BUILD_DIR)
# CMake <3.1 stores path to internal build directory here 3112 if (BUILD_DIR MATCHES
"CMakeFiles")
3113 list (REMOVE_AT SOURCES 0)
3116 message (FATAL_ERROR
"Target ${TARGET_UID}: Expected at least one element in SOURCES list!" 3117 " Have you incorrectly modified this (read-only) property or" 3118 " is your (newer) CMake version not compatible with BASIS?")
3120 set (BUILD_DIR
"${BUILD_DIRECTORY}.dir")
3121 # common arguments of build script
3123 if (EXISTS
"${BASIS_SCRIPT_CONFIG_FILE}")
3124 list (APPEND CONFIG_FILES
"${BASIS_SCRIPT_CONFIG_FILE}")
3126 if (SCRIPT_DEFINITIONS_FILE)
3127 list (APPEND CONFIG_FILES ${SCRIPT_DEFINITIONS_FILE})
3129 if (SCRIPT_DEFINITIONS)
3130 set (SCRIPT_CONFIG_FILE
"${BUILD_DIR}/ScriptConfig.cmake")
3131 file (WRITE
"${SCRIPT_CONFIG_FILE}.tmp" "# DO NOT edit. Automatically generated by BASIS.\n${SCRIPT_DEFINITIONS}\n")
3132 execute_process (
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${SCRIPT_CONFIG_FILE}.tmp" "${SCRIPT_CONFIG_FILE}")
3133 file (REMOVE
"${SCRIPT_CONFIG_FILE}.tmp")
3134 list (APPEND CONFIG_FILES
"${SCRIPT_CONFIG_FILE}")
3136 set (CACHE_FILE
"${BUILD_DIR}/cache.cmake")
3137 execute_process (
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${CACHE_FILE}.tmp" "${CACHE_FILE}")
3138 file (REMOVE
"${CACHE_FILE}.tmp")
3139 set (OPTIONS) # no additional options
3141 list (APPEND OPTIONS COMPILE)
3143 # add build command for each module 3144 set (OUTPUT_FILES) # list of all output files
3145 set (FILES_TO_COPY) # relative paths of build tree modules
3146 set (FILES_TO_INSTALL) # list of output files
for installation
3147 set (BINARY_INSTALL_DIRECTORY
"${BUILD_DIR}/install") # common base directory
for files to install
3148 if (COMPILE OR CMAKE_GENERATOR MATCHES
"Visual Studio|Xcode") # post-build copy to <libdir>/<config>/
3149 set (BINARY_OUTPUT_DIRECTORY
"${BUILD_DIR}/build") # common base directory
for build tree files
3150 set (POST_BUILD_COPY TRUE)
3152 set (BINARY_OUTPUT_DIRECTORY
"${LIBRARY_OUTPUT_DIRECTORY}")
3153 set (POST_BUILD_COPY FALSE)
3155 foreach (SOURCE_FILE IN LISTS SOURCES)
3156 file (RELATIVE_PATH S
"${SOURCE_DIRECTORY}" "${SOURCE_FILE}")
3157 string (REGEX REPLACE
"\\.in$" "" S
"${S}")
3159 # arguments of build script 3161 set (S
"${PREFIX}${S}")
3163 set (OUTPUT_FILE
"${BINARY_OUTPUT_DIRECTORY}/${S}")
3165 if (LIBRARY_INSTALL_DIRECTORY)
3166 set (INSTALL_FILE
"${BINARY_INSTALL_DIRECTORY}/${S}")
3167 set (DESTINATION
"${LIBRARY_INSTALL_DIRECTORY}/${S}")
3168 if (NOT IS_ABSOLUTE
"${DESTINATION}")
3169 set (DESTINATION
"${CMAKE_INSTALL_PREFIX}/${DESTINATION}")
3176 # configure build script 3177 set (
BUILD_SCRIPT "${BUILD_DIR}/${BUILD_SCRIPT_NAME}.cmake")
3178 configure_file (
"${BASIS_MODULE_PATH}/configure_script.cmake.in" "${BUILD_SCRIPT}" @ONLY)
3179 # output files of this command 3180 set (_OUTPUT_FILES
"${OUTPUT_FILE}")
3182 list (APPEND _OUTPUT_FILES
"${INSTALL_FILE}")
3188 list (APPEND _OUTPUT_FILES
"${OUTPUT_CFILE}")
3191 list (APPEND _OUTPUT_FILES
"${INSTALL_CFILE}")
3198 if (JYTHON_OUTPUT_CFILE)
3199 list (APPEND _OUTPUT_FILES
"${JYTHON_OUTPUT_CFILE}")
3201 if (JYTHON_INSTALL_CFILE)
3202 list (APPEND _OUTPUT_FILES
"${JYTHON_INSTALL_CFILE}")
3207 if (POST_BUILD_COPY)
3209 file (RELATIVE_PATH _file
"${BINARY_OUTPUT_DIRECTORY}" "${OUTPUT_CFILE}")
3210 list (APPEND FILES_TO_COPY
"${_file}")
3211 if (JYTHON_OUTPUT_CFILE)
3212 file (RELATIVE_PATH _file
"${BINARY_OUTPUT_DIRECTORY}" "${JYTHON_OUTPUT_CFILE}")
3213 list (APPEND FILES_TO_COPY
"${_file}")
3216 list (APPEND FILES_TO_COPY
"${S}")
3220 list (APPEND FILES_TO_INSTALL
"${INSTALL_CFILE}")
3221 elseif (INSTALL_FILE)
3222 list (APPEND FILES_TO_INSTALL
"${INSTALL_FILE}")
3226 file (RELATIVE_PATH REL
"${CMAKE_BINARY_DIR}" "${OUTPUT_CFILE}")
3228 file (RELATIVE_PATH REL
"${CMAKE_BINARY_DIR}" "${OUTPUT_FILE}")
3230 set (COMMENT
"Building ${LANGUAGE} module ${REL}...")
3231 add_custom_command (
3232 OUTPUT ${_OUTPUT_FILES}
3233 COMMAND "${CMAKE_COMMAND}" -D
"CONFIGURATION=$<${BASIS_GE_CONFIG}>" -P
"${BUILD_SCRIPT}" 3234 MAIN_DEPENDENCY
"${SOURCE_FILE}" 3236 COMMENT
"${COMMENT}" 3239 # add output files of command to list of all output files
3240 list (APPEND OUTPUT_FILES ${_OUTPUT_FILES})
3242 # add custom target to build modules 3243 add_custom_target (_${TARGET_UID} DEPENDS ${OUTPUT_FILES})
3244 foreach (T IN LISTS LINK_DEPENDS)
3246 add_dependencies (_${TARGET_UID} ${T})
3249 add_dependencies (${TARGET_UID} _${TARGET_UID})
3250 # copy configured modules to output directory
3251 foreach (OUTPUT_FILE IN LISTS FILES_TO_COPY)
3252 add_custom_command (
3253 TARGET _${TARGET_UID} POST_BUILD
3254 COMMAND "${CMAKE_COMMAND}" -E copy
"${BINARY_OUTPUT_DIRECTORY}/${OUTPUT_FILE}" "${LIBRARY_OUTPUT_DIRECTORY}/${OUTPUT_FILE}" 3257 # cleanup on "make clean" - including compiled files regardless of COMPILE flag 3258 set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${OUTPUT_FILES})
3259 foreach (OUTPUT_FILE IN LISTS OUTPUT_FILES)
3262 list (FIND OUTPUT_FILES
"${CFILE}" IDX)
3264 set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
"${CFILE}")
3272 # add installation rule 3273 foreach (INSTALL_FILE IN LISTS FILES_TO_INSTALL)
3275 file (RELATIVE_PATH D
"${BINARY_INSTALL_DIRECTORY}" "${D}")
3277 FILES
"${INSTALL_FILE}" 3278 DESTINATION
"${LIBRARY_INSTALL_DIRECTORY}/${D}" 3279 COMPONENT
"${LIBRARY_COMPONENT}" 3281 if (
LANGUAGE MATCHES
"PYTHON" AND INSTALL_FILE MATCHES
"\\.pyc$")
3286 if (LIBRARY_INSTALL_DIRECTORY MATCHES
"^${LIBRE}/*$")
3287 set (JYTHON_INSTALL_DIRECTORY
"${INSTALL_JYTHON_LIBRARY_DIR}")
3288 elseif (LIBRARY_INSTALL_DIRECTORY MATCHES
"^${SITERE}/*$")
3289 set (JYTHON_INSTALL_DIRECTORY
"${INSTALL_JYTHON_SITE_DIR}")
3291 set (JYTHON_INSTALL_DIRECTORY
"${LIBRARY_INSTALL_DIRECTORY}")
3293 string (REGEX REPLACE
"c$" "" SOURCE_FILE
"${INSTALL_FILE}")
3296 FILES
"${INSTALL_JYTHON_CFILE}" 3297 DESTINATION
"${JYTHON_INSTALL_DIRECTORY}/${D}" 3298 COMPONENT
"${LIBRARY_COMPONENT}" 3305 message (STATUS
"Adding build command for target ${TARGET_UID}... - done")
3309 # ---------------------------------------------------------------------------- 3310 # @brief Add target to build/install __init__.py files. 3312 if (NOT BASIS_PYTHON_TEMPLATES_DIR)
3313 message (WARNING
"BASIS_PYTHON_TEMPLATES_DIR not set, skipping basis_add_init_py_target")
3317 set (BUILD_DIR
"${PROJECT_BINARY_DIR}/CMakeFiles/_initpy.dir")
3324 # collect directories requiring a __init__.py file 3325 set (DEPENDENTS) # targets
which generate Python/Jython modules and depend on _initpy
3326 set (PYTHON_DIRS) # Python library directories requiring a __init__.py file
3327 set (JYTHON_DIRS) # Jython library directories requiring a __init__.py file
3328 set (EXCLUDE) # exclude these directories
3329 set (INSTALL_EXCLUDE) # exclude these directories upon installation
3330 set (COMPONENTS) # installation components
3332 foreach (TARGET_UID IN LISTS TARGETS)
3333 get_target_property (BASIS_TYPE ${TARGET_UID} BASIS_TYPE)
3335 if (BASIS_TYPE MATCHES
"MODULE|LIBRARY" AND
LANGUAGE MATCHES
"^[JP]YTHON$")
3336 # get path of built Python modules 3339 if (BASIS_TYPE MATCHES
"^SCRIPT_LIBRARY$")
3340 get_target_property (PREFIX ${TARGET_UID} PREFIX)
3341 get_target_property (SOURCES ${TARGET_UID}
SOURCES)
3342 get_target_property (SOURCE_DIRECTORY ${TARGET_UID} SOURCE_DIRECTORY)
3343 string (REGEX REPLACE
"/+$" "" PREFIX
"${PREFIX}")
3345 set (LOCATION
"${LOCATION}/${PREFIX}")
3346 set (INSTALL_LOCATION
"${INSTALL_LOCATION}/${PREFIX}")
3348 list (GET SOURCES 0 BINARY_DIR)
# CMake <3.1 stores path to internal build directory here 3349 if (BINARY_DIR MATCHES
"CMakeFiles")
3350 list (REMOVE_AT SOURCES 0)
3352 foreach (SOURCE IN LISTS SOURCES)
3353 file (RELATIVE_PATH SOURCE
"${SOURCE_DIRECTORY}" "${SOURCE}")
3354 list (APPEND _LOCATION
"${LOCATION}/${SOURCE}")
3355 list (APPEND _INSTALL_LOCATION
"${INSTALL_LOCATION}/${SOURCE}")
3357 set (LOCATION
"${_LOCATION}")
3358 set (INSTALL_LOCATION
"${_INSTALL_LOCATION}")
3360 # get component (used by installation rule) 3361 get_target_property (COMPONENT ${TARGET_UID}
"LIBRARY_COMPONENT")
3362 list (FIND COMPONENTS
"${COMPONENT}" IDX)
3364 list (APPEND COMPONENTS
"${COMPONENT}")
3365 set (INSTALL_${
LANGUAGE}_DIRS_${COMPONENT}) # list of directories
for which to install
3366 # __init__.py
for this component
3368 # directories for which to build a __init__.py file 3369 foreach (L IN LISTS LOCATION)
3371 if (L MATCHES
"/__init__\\.py$")
3372 list (APPEND EXCLUDE
"${DIR}")
3374 list (APPEND DEPENDENTS ${TARGET_UID}) # depends on _initpy
3375 if (BINARY_${
LANGUAGE}_LIBRARY_DIR_RE AND
DIR MATCHES
"^${BINARY_${LANGUAGE}_LIBRARY_DIR_RE}/.+")
3376 while (NOT
"${DIR}" MATCHES
"^${BINARY_${LANGUAGE}_LIBRARY_DIR_RE}$")
3377 list (APPEND ${
LANGUAGE}_DIRS
"${DIR}")
3380 elseif (TESTING_${
LANGUAGE}_LIBRARY_DIR_RE AND
DIR MATCHES
"^${TESTING_${LANGUAGE}_LIBRARY_DIR_RE}/.+")
3381 while (NOT
"${DIR}" MATCHES
"^${TESTING_${LANGUAGE}_LIBRARY_DIR_RE}$")
3382 list (APPEND ${
LANGUAGE}_DIRS
"${DIR}")
3388 # directories for which to install a __init__.py file 3389 foreach (L IN LISTS INSTALL_LOCATION)
3391 if (L MATCHES
"/__init__\\.py$")
3392 list (APPEND INSTALL_EXCLUDE
"${DIR}")
3394 list (APPEND DEPENDENTS ${TARGET_UID}) # depends on _initpy
3395 if (INSTALL_${
LANGUAGE}_LIBRARY_DIR_RE AND
DIR MATCHES
"^${INSTALL_${LANGUAGE}_LIBRARY_DIR_RE}/.+")
3396 while (NOT
"${DIR}" MATCHES
"^${INSTALL_${LANGUAGE}_LIBRARY_DIR_RE}$")
3397 list (APPEND INSTALL_${
LANGUAGE}_DIRS_${COMPONENT}
"${DIR}")
3401 if (INSTALL_JYTHON_LIBRARY_DIR)
3402 file (RELATIVE_PATH REL
"${CMAKE_INSTALL_PREFIX}/${INSTALL_PYTHON_LIBRARY_DIR}" "${CMAKE_INSTALL_PREFIX}/${DIR}")
3406 if (NOT REL MATCHES
"^$|^\\.\\./")
3407 list (APPEND INSTALL_JYTHON_DIRS_${COMPONENT}
"${INSTALL_JYTHON_LIBRARY_DIR}/${REL}")
3419 list (REMOVE_DUPLICATES DEPENDENTS)
3421 # return if nothing to do 3422 if (NOT PYTHON_DIRS AND NOT JYTHON_DIRS)
3426 list (REMOVE_DUPLICATES PYTHON_DIRS)
3429 list (REMOVE_DUPLICATES JYTHON_DIRS)
3432 list (REMOVE_DUPLICATES EXCLUDE)
3434 if (INSTALL_EXCLUDE)
3435 list (REMOVE_DUPLICATES INSTALL_EXCLUDE)
3437 # generate build script 3438 set (PYTHON_COMPILED_FILES
"${CFILE}")
3439 set (JYTHON_COMPILED_FILES
"${CFILE}")
3440 set (C
"configure_file (\"${BASIS_PYTHON_TEMPLATES_DIR}/__init__.py.in\" \"${BUILD_DIR}/__init__.py\" @ONLY)\n")
3441 foreach (
LANGUAGE IN ITEMS PYTHON JYTHON) # Python *must* come first. See JYTHON_COMPILED_FILES list.
3443 set (${
LANGUAGE}_INSTALL_FILE
"${BUILD_DIR}/__init__.py")
3444 set (C
"${C}\nset (${LANGUAGE}_EXECUTABLE \"${${LANGUAGE}_EXECUTABLE}\")\n\n")
3446 list (FIND EXCLUDE
"${DIR}" IDX)
3448 set (C
"${C}configure_file (\"${BASIS_PYTHON_TEMPLATES_DIR}/__init__.py.in\" \"${DIR}/__init__.py\" @ONLY)\n")
3449 list (APPEND ${
LANGUAGE}_OUTPUT_FILES
"${DIR}/__init__.py")
3454 string (TOLOWER
"${LANGUAGE}" language)
3456 set (C
"${C}file (MAKE_DIRECTORY \"${BUILD_DIR}/${language}\")\n")
3457 set (C
"${C}execute_process (COMMAND \"${${LANGUAGE}_EXECUTABLE}\" -c \"import py_compile; py_compile.compile('${BUILD_DIR}/__init__.py', '${CFILE}')\")\n")
3458 set (${
LANGUAGE}_INSTALL_FILE
"${CFILE}")
3460 foreach (SFILE IN LISTS ${
LANGUAGE}_OUTPUT_FILES)
3462 set (C
"${C}execute_process (COMMAND \"${${LANGUAGE}_EXECUTABLE}\" -c \"import py_compile; py_compile.compile('${SFILE}', '${CFILE}')\")\n")
3463 list (APPEND ${
LANGUAGE}_COMPILED_FILES
"${CFILE}")
3468 file (RELATIVE_PATH REL
"${BINARY_PYTHON_LIBRARY_DIR}" "${SFILE}")
3472 if (NOT REL MATCHES
"^$|^\\.\\./")
3478 set (C
"${C}file (MAKE_DIRECTORY \"${CDIR}\")\n")
3479 set (C
"${C}execute_process (COMMAND \"${JYTHON_EXECUTABLE}\" -c \"import py_compile; py_compile.compile('${SFILE}', '${CFILE}')\")\n")
3480 list (APPEND JYTHON_COMPILED_FILES
"${CFILE}")
3487 # write/update build script 3489 if (EXISTS
"${BUILD_SCRIPT}")
3490 file (WRITE
"${BUILD_SCRIPT}.tmp" "${C}")
3491 execute_process (
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${BUILD_SCRIPT}.tmp" "${BUILD_SCRIPT}")
3492 file (REMOVE
"${BUILD_SCRIPT}.tmp")
3494 file (WRITE
"${BUILD_SCRIPT}" "${C}")
3496 # add custom build command 3497 add_custom_command (
3498 OUTPUT
"${BUILD_DIR}/__init__.py" ${PYTHON_OUTPUT_FILES} ${JYTHON_OUTPUT_FILES}
3499 COMMAND "${CMAKE_COMMAND}" -P
"${BUILD_SCRIPT}" 3500 MAIN_DEPENDENCY
"${BASIS_PYTHON_TEMPLATES_DIR}/__init__.py.in" 3501 COMMENT
"Building PYTHON modules */__init__.py..." 3503 # add custom target
which triggers execution of build script
3504 add_custom_target (_initpy ALL DEPENDS
"${BUILD_DIR}/__init__.py" ${PYTHON_OUTPUT_FILES} ${JYTHON_OUTPUT_FILES})
3506 message (
"** basis_add_init_py_target():")
3508 foreach (DEPENDENT IN LISTS DEPENDENTS)
3510 message (
"** Adding dependency on _initpy target to ${DEPENDENT}")
3512 add_dependencies (${DEPENDENT} _initpy)
3514 # cleanup on "make clean" - including compiled modules regardless of COMPILE flag 3515 set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
"${BUILD_DIR}/__init__.py" ${PYTHON_OUTPUT_FILES} ${JYTHON_OUTPUT_FILES})
3517 foreach (
LANGUAGE IN ITEMS PYTHON JYTHON)
3518 foreach (COMPONENT IN LISTS COMPONENTS)
3519 if (INSTALL_${
LANGUAGE}_DIRS_${COMPONENT})
3520 list (REMOVE_DUPLICATES INSTALL_${
LANGUAGE}_DIRS_${COMPONENT})
3522 foreach (
DIR IN LISTS INSTALL_${
LANGUAGE}_DIRS_${COMPONENT})
3523 list (FIND INSTALL_EXCLUDE
"${DIR}" IDX)
3526 message(
"** Copy ${${LANGUAGE}_INSTALL_FILE} to ${DIR} upon installation of ${COMPONENT} component")
3529 FILES
"${${LANGUAGE}_INSTALL_FILE}" 3530 DESTINATION
"${DIR}" 3531 COMPONENT
"${COMPONENT}" 3541 # end of Doxygen group function basis_build_mex_file(in TARGET_UID)
Add custom command for build of MEX-file.
function basis_get_source_target_name(out TARGET_NAME, in SOURCE_FILE, in ARGN)
Derive target name from source file name.
function basis_get_target_uid(out TARGET_UID, in TARGET_NAME)
Get "global" target name, i.e., actual CMake target name.
function basis_build_script_library(in TARGET_UID)
Add custom command for build of script library.
cmake BASIS_UTILITIES
Enable the automatic detection of the use of the BASIS utilities.
function set_target_properties(in ARGN)
Set target property.
cmake INSTALL_JYTHON_LIBRARY_DIR
Path of installation directory of private Jython modules relative to CMAKE_INSTALL_PREFIX.
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.
macro basis_get_compiled_jython_file_of_python_module(out CFILE, in MODULE)
Get file path of Jython file compiled from the given Python module.
function is(in result, in expected, in name)
Test whether a given result is equal to the expected result.
macro basis_add_custom_target(in TARGET_NAME)
Add custom target.
def which(command, path=None, verbose=0, exts=None)
function basis_get_project_property(out VARIABLE, in ARGN)
Get project-global property value.
function basis_build_script(in TARGET_UID)
Add custom command for build of single script.
function basis_finalize_targets(in ARGN)
Finalize custom targets by adding the missing build commands.
macro basis_compile_python_modules_for_jython(out FLAG)
Whether to compile Python modules for Jython interpreter.
function basis_check_target_name(in TARGET_NAME)
Checks whether a given name is a valid target name.
cmake INSTALL_JYTHON_SITE_DIR
Path of installation directory of public Jython modules relative to CMAKE_INSTALL_PREFIX.
function basis_add_glob_target(in TARGET_UID, out SOURCES, in ARGN)
Glob source files.
cmake BINARY_JYTHON_LIBRARY_DIR
Absolute path to output directory for Jython modules.
function basis_add_export_target(out EXPORT_OPTION, in TARGET_UID, in IS_TEST, in ARGN)
Add target to export set.
function add_library(in TARGET_UID, in ARGN)
Add library target.
macro basis_sanitize_for_regex(out OUT, in STR)
Sanitize string variable for use in regular expression.
option BASIS_COMPILE_SCRIPTS
Enable compilation of scripts if supported by the language.
function basis_get_source_language(out LANGUAGE, in ARGN)
Detect programming language of given source code files.
function basis_remove_definitions(in ARGN)
Remove previously added compile definitions.
function basis_add_mcc_target(in TARGET_NAME, in ARGN)
Add MATLAB Compiler target.
function basis_set_project_property()
Set project-global property.
function basis_add_init_py_target()
function basis_add_library_target(in TARGET_NAME, in ARGN)
Add library built from C++ source code.
macro include_directories(in ARGN)
Add directories to search path for include files.
function basis_get_target_link_libraries(out LINK_DEPENDS, in TARGET_NAME)
Get link libraries/dependencies of (imported) target.
cmake BASIS_EXPORT_DEFAULT
Whether to export targets by default.
macro basis_add_utilities_library(out UID, in LANGUAGE)
Add build target for BASIS utilities library.
macro basis_get_filename_component()
Alias for the overwritten get_filename_component() function.
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_add_script(in TARGET_NAME, in ARGN)
Add single arbitrary or executable script.
function basis_utilities_check(out VAR, in SOURCE_FILE, in ARGN)
Check whether the BASIS utilities are used within a given source file.
function basis_add_executable_target(in TARGET_NAME, in ARGN)
Add executable built from C++ source code.
macro link_directories(in ARGN)
Add directories to search path for libraries.
function basis_get_target_type(out TYPE, in TARGET_NAME)
Get type name of target.
function basis_add_mex_file(in TARGET_NAME, in ARGN)
Add MEX-file target.
cmake BINARY_PYTHON_LIBRARY_DIR
Absolute path to output directory for Python modules.
function basis_link_directories(in ARGN)
Add directories to search path for libraries.
function basis_get_compiled_file(out CFILE, in SOURCE, in ARGV2)
Get file name of compiled script.
function add_executable(in TARGET_UID, in ARGN)
Add executable target.
function basis_add_definitions(in ARGN)
Add compile definitions.
function basis_make_target_uid(out TARGET_UID, in TARGET_NAME)
Make target UID from given target name.
cmake CONFIG_FILE
Name of the CMake package configuration file.
function basis_configure_sources(out LIST_NAME, in ARGN)
Configure .in source files.
macro basis_use_package(in PACKAGE)
Use found package.
function match(in value, in pattern)
This function implements a more portable way to do pattern matching.
#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_add_script_library(in TARGET_NAME, in ARGN)
Add script library target.
function basis_get_target_property(out VAR, in TARGET_NAME, in ARGN)
Get value of property set on target.
function basis_dump_variables(in RESULT_FILE)
Output current CMake variables to file.
option BASIS_DEBUG
Request debugging messages from BASIS functions.
function basis_configure_script(in INPUT, in OUTPUT, in ARGN)
Configure and optionally compile script file.
cmake INSTALL_PYTHON_LIBRARY_DIR
Path of installation directory of private Python modules relative to CMAKE_INSTALL_PREFIX.
function basis_build_mcc_target(in TARGET_UID)
Add custom command for build of MATLAB Compiler target.
function basis_set_target_install_rpath(in TARGET_NAME)
Set INSTALL_RPATH property of executable or shared library target.
macro basis_library_prefix(out PREFIX, in LANGUAGE)
Get default subdirectory prefix of scripted library modules.
option BASIS_VERBOSE
Default Sphinx theme options.
cmake LANGUAGE
Detected scripting language or UNKNOWN.
function basis_set_target_properties(in ARGN)
Set properties on a target.
function basis_add_imported_target(in TARGET, in TYPE)
Add imported target.
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 basis_add_executable(in TARGET_NAME, in ARGN)
Add executable target.
function basis_add_library(in TARGET_NAME, in ARGN)
Add library target.
function basis_include_directories(in ARGN)
Add directories to search path for include files.
function get_filename_component(inout ARGN)
Fixes CMake's get_filename_component() command.
function basis_add_dependencies(in ARGN)
Add dependencies to build target.
cmake BASIS_UTILITIES_ENABLED
function basis_get_target_location(out VAR, in TARGET_NAME, in PART)
Get location of build target output file(s).