diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CMakeCUDAInformation.cmake | 18 | ||||
-rw-r--r-- | Modules/CMakeDetermineCSharpCompiler.cmake | 2 | ||||
-rw-r--r-- | Modules/CMakeDetermineCUDACompiler.cmake | 2 | ||||
-rw-r--r-- | Modules/CMakeFortranCompiler.cmake.in | 2 | ||||
-rw-r--r-- | Modules/CTest.cmake | 2 | ||||
-rw-r--r-- | Modules/FindCUDA.cmake | 24 | ||||
-rw-r--r-- | Modules/FindDCMTK.cmake | 12 | ||||
-rw-r--r-- | Modules/FindMatlab.cmake | 2 | ||||
-rw-r--r-- | Modules/FindPython.cmake | 15 | ||||
-rw-r--r-- | Modules/FindPython/Support.cmake | 9 | ||||
-rw-r--r-- | Modules/FindVulkan.cmake | 2 | ||||
-rw-r--r-- | Modules/Platform/Windows-NVIDIA-CUDA.cmake | 19 | ||||
-rw-r--r-- | Modules/Platform/Windows-df.cmake | 3 | ||||
-rw-r--r-- | Modules/UseSWIG.cmake | 155 |
14 files changed, 188 insertions, 79 deletions
diff --git a/Modules/CMakeCUDAInformation.cmake b/Modules/CMakeCUDAInformation.cmake index 167e177..4788cbf 100644 --- a/Modules/CMakeCUDAInformation.cmake +++ b/Modules/CMakeCUDAInformation.cmake @@ -177,17 +177,31 @@ else() set(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS "") endif() +# Add implicit host link directories that contain device libraries +# to the device link line. +set(__IMPLICT_DLINK_DIRS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) +if(__IMPLICT_DLINK_DIRS) + list(REMOVE_ITEM __IMPLICT_DLINK_DIRS ${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES}) +endif() +set(__IMPLICT_DLINK_FLAGS ) +foreach(dir ${__IMPLICT_DLINK_DIRS}) + if(EXISTS "${dir}/libcublas_device.a") + string(APPEND __IMPLICT_DLINK_FLAGS " -L\"${dir}\"") + endif() +endforeach() +unset(__IMPLICT_DLINK_DIRS) #These are used when linking relocatable (dc) cuda code if(NOT CMAKE_CUDA_DEVICE_LINK_LIBRARY) set(CMAKE_CUDA_DEVICE_LINK_LIBRARY - "<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <CMAKE_CUDA_LINK_FLAGS> <LANGUAGE_COMPILE_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <CMAKE_CUDA_LINK_FLAGS> <LANGUAGE_COMPILE_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_DLINK_FLAGS}") endif() if(NOT CMAKE_CUDA_DEVICE_LINK_EXECUTABLE) set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE - "<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <FLAGS> <CMAKE_CUDA_LINK_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <FLAGS> <CMAKE_CUDA_LINK_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_DLINK_FLAGS}") endif() unset(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS) +unset(__IMPLICT_DLINK_FLAGS) set(CMAKE_CUDA_INFORMATION_LOADED 1) diff --git a/Modules/CMakeDetermineCSharpCompiler.cmake b/Modules/CMakeDetermineCSharpCompiler.cmake index eb825a5..5802b15 100644 --- a/Modules/CMakeDetermineCSharpCompiler.cmake +++ b/Modules/CMakeDetermineCSharpCompiler.cmake @@ -1,7 +1,7 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -if(NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio ([^89]|[89][0-9])") +if(NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio ([^9]|[9][0-9])") message(FATAL_ERROR "C# is currently only supported for Microsoft Visual Studio 2010 and later.") endif() diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index f5a3ebd..0b8fff6 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -6,7 +6,7 @@ include(${CMAKE_ROOT}/Modules//CMakeParseImplicitLinkInfo.cmake) if( NOT ( ("${CMAKE_GENERATOR}" MATCHES "Make") OR ("${CMAKE_GENERATOR}" MATCHES "Ninja") OR - ("${CMAKE_GENERATOR}" MATCHES "Visual Studio (1|[89][0-9])") ) ) + ("${CMAKE_GENERATOR}" MATCHES "Visual Studio (1|[9][0-9])") ) ) message(FATAL_ERROR "CUDA language not currently supported by \"${CMAKE_GENERATOR}\" generator") endif() diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in index 2e34cbb..9b951fc 100644 --- a/Modules/CMakeFortranCompiler.cmake.in +++ b/Modules/CMakeFortranCompiler.cmake.in @@ -31,7 +31,7 @@ if(CMAKE_COMPILER_IS_MINGW) set(MINGW 1) endif() set(CMAKE_Fortran_COMPILER_ID_RUN 1) -set(CMAKE_Fortran_SOURCE_FILE_EXTENSIONS f;F;f77;F77;f90;F90;for;For;FOR;f95;F95) +set(CMAKE_Fortran_SOURCE_FILE_EXTENSIONS f;F;fpp;FPP;f77;F77;f90;F90;for;For;FOR;f95;F95) set(CMAKE_Fortran_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) set(CMAKE_Fortran_LINKER_PREFERENCE 20) if(UNIX) diff --git a/Modules/CTest.cmake b/Modules/CTest.cmake index a08282e..2ea931d 100644 --- a/Modules/CTest.cmake +++ b/Modules/CTest.cmake @@ -54,7 +54,7 @@ in the ``CTestConfig.cmake`` file. option(BUILD_TESTING "Build the testing tree." ON) # function to turn generator name into a version string -# like vs8 vs9 +# like vs9 or vs10 function(GET_VS_VERSION_STRING generator var) string(REGEX REPLACE "Visual Studio ([0-9][0-9]?)($|.*)" "\\1" NUMBER "${generator}") diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index 119fc13..6f6f349 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -733,16 +733,20 @@ endif() # CUDA_NVCC_EXECUTABLE -cuda_find_host_program(CUDA_NVCC_EXECUTABLE - NAMES nvcc - PATHS "${CUDA_TOOLKIT_ROOT_DIR}" - ENV CUDA_PATH - ENV CUDA_BIN_PATH - PATH_SUFFIXES bin bin64 - NO_DEFAULT_PATH - ) -# Search default search paths, after we search our own set of paths. -cuda_find_host_program(CUDA_NVCC_EXECUTABLE nvcc) +if(DEFINED ENV{CUDA_NVCC_EXECUTABLE}) + set(CUDA_NVCC_EXECUTABLE "$ENV{CUDA_NVCC_EXECUTABLE}" CACHE FILEPATH "The CUDA compiler") +else() + cuda_find_host_program(CUDA_NVCC_EXECUTABLE + NAMES nvcc + PATHS "${CUDA_TOOLKIT_ROOT_DIR}" + ENV CUDA_PATH + ENV CUDA_BIN_PATH + PATH_SUFFIXES bin bin64 + NO_DEFAULT_PATH + ) + # Search default search paths, after we search our own set of paths. + cuda_find_host_program(CUDA_NVCC_EXECUTABLE nvcc) +endif() mark_as_advanced(CUDA_NVCC_EXECUTABLE) if(CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION) diff --git a/Modules/FindDCMTK.cmake b/Modules/FindDCMTK.cmake index f348d3a..39c1a5b 100644 --- a/Modules/FindDCMTK.cmake +++ b/Modules/FindDCMTK.cmake @@ -301,7 +301,7 @@ endif() # Compatibility: This variable is deprecated set(DCMTK_INCLUDE_DIR ${DCMTK_INCLUDE_DIRS}) -include(FindPackageHandleStandardArgs) +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(DCMTK REQUIRED_VARS ${DCMTK_INCLUDE_DIR_NAMES} DCMTK_LIBRARIES FAIL_MESSAGE "Please set DCMTK_DIR and re-run configure") @@ -309,20 +309,14 @@ find_package_handle_standard_args(DCMTK # Workaround bug in packaging of DCMTK 3.6.0 on Debian. # See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=637687 if(DCMTK_FOUND AND UNIX AND NOT APPLE) - include(CheckCXXSourceCompiles) + include(${CMAKE_CURRENT_LIST_DIR}/CheckIncludeFiles.cmake) set(CMAKE_REQUIRED_FLAGS ) set(CMAKE_REQUIRED_DEFINITIONS ) set(CMAKE_REQUIRED_INCLUDES ${DCMTK_INCLUDE_DIRS}) set(CMAKE_REQUIRED_LIBRARIES ${DCMTK_LIBRARIES}) set(CMAKE_REQUIRED_QUIET ${DCMTK_FIND_QUIETLY}) - check_cxx_source_compiles("#include <dcmtk/config/osconfig.h>\n#include <dcmtk/ofstd/ofstream.h>\nint main(int,char*[]){return 0;}" - DCMTK_HAVE_CONFIG_H_OPTIONAL - ) + check_include_files("dcmtk/config/osconfig.h;dcmtk/ofstd/ofstream.h" DCMTK_HAVE_CONFIG_H_OPTIONAL LANGUAGE CXX) if(NOT DCMTK_HAVE_CONFIG_H_OPTIONAL) set(DCMTK_DEFINITIONS "HAVE_CONFIG_H") endif() endif() - -if(NOT DCMTK_FIND_QUIETLY) - message(STATUS "Trying to find DCMTK relying on FindDCMTK.cmake - ok") -endif() diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 8402b23..33b755a 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -213,7 +213,7 @@ set(_FindMatlab_SELF_DIR "${CMAKE_CURRENT_LIST_DIR}") -include(FindPackageHandleStandardArgs) +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) include(CheckCXXCompilerFlag) include(CheckCCompilerFlag) diff --git a/Modules/FindPython.cmake b/Modules/FindPython.cmake index c87f784..8139e53 100644 --- a/Modules/FindPython.cmake +++ b/Modules/FindPython.cmake @@ -144,18 +144,19 @@ else() set (Python_FIND_QUIETLY TRUE) set (Python_FIND_REQUIRED FALSE) - foreach (_Python_REQUIRED_VERSION_MAJOR IN ITEMS 3 2) + set (_Python_REQUIRED_VERSIONS 3 2) + set (_Python_REQUIRED_VERSION_LAST 2) + + foreach (_Python_REQUIRED_VERSION_MAJOR IN LISTS _Python_REQUIRED_VERSIONS) set (Python_FIND_VERSION ${_Python_REQUIRED_VERSION_MAJOR}) include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake) - if (Python_FOUND) + if (Python_FOUND OR + _Python_REQUIRED_VERSION_MAJOR EQUAL _Python_REQUIRED_VERSION_LAST) break() endif() # clean-up some CACHE variables to ensure look-up restart from scratch - foreach (_Python_ITEM IN ITEMS EXECUTABLE COMPILER - LIBRARY_RELEASE RUNTIME_LIBRARY_RELEASE - LIBRARY_DEBUG RUNTIME_LIBRARY_DEBUG - INCLUDE_DIR) - unset (Python_${_Python_ITEM} CACHE) + foreach (_Python_ITEM IN LISTS _Python_CACHED_VARS) + unset (${_Python_ITEM} CACHE) endforeach() endforeach() diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index be34624..179b394 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -162,12 +162,14 @@ unset (${_PYTHON_PREFIX}_VERSION_MINOR) unset (${_PYTHON_PREFIX}_VERSION_PATCH) unset (_${_PYTHON_PREFIX}_REQUIRED_VARS) +unset (_${_PYTHON_PREFIX}_CACHED_VARS) # first step, search for the interpreter if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) if (${_PYTHON_PREFIX}_FIND_REQUIRED_Interpreter) list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_EXECUTABLE) + list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS ${_PYTHON_PREFIX}_EXECUTABLE) endif() set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR) @@ -305,6 +307,7 @@ endif() if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) if (${_PYTHON_PREFIX}_FIND_REQUIRED_Compiler) list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_COMPILER) + list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS ${_PYTHON_PREFIX}_COMPILER) endif() # IronPython specific artifacts @@ -393,6 +396,12 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS if (${_PYTHON_PREFIX}_FIND_REQUIRED_Development) list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_LIBRARY ${_PYTHON_PREFIX}_INCLUDE_DIR) + list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS ${_PYTHON_PREFIX}_LIBRARY + ${_PYTHON_PREFIX}_LIBRARY_RELEASE + ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE + ${_PYTHON_PREFIX}_LIBRARY_DEBUG + ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG + ${_PYTHON_PREFIX}_INCLUDE_DIR) endif() # Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES diff --git a/Modules/FindVulkan.cmake b/Modules/FindVulkan.cmake index 1f4c8ad..4c60ed7 100644 --- a/Modules/FindVulkan.cmake +++ b/Modules/FindVulkan.cmake @@ -65,7 +65,7 @@ endif() set(Vulkan_LIBRARIES ${Vulkan_LIBRARY}) set(Vulkan_INCLUDE_DIRS ${Vulkan_INCLUDE_DIR}) -include(FindPackageHandleStandardArgs) +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(Vulkan DEFAULT_MSG Vulkan_LIBRARY Vulkan_INCLUDE_DIR) diff --git a/Modules/Platform/Windows-NVIDIA-CUDA.cmake b/Modules/Platform/Windows-NVIDIA-CUDA.cmake index 970c2c6..0c11e55 100644 --- a/Modules/Platform/Windows-NVIDIA-CUDA.cmake +++ b/Modules/Platform/Windows-NVIDIA-CUDA.cmake @@ -36,12 +36,27 @@ else() set(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS "") endif() +# Add implicit host link directories that contain device libraries +# to the device link line. +set(__IMPLICT_DLINK_DIRS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) +if(__IMPLICT_DLINK_DIRS) + list(REMOVE_ITEM __IMPLICT_DLINK_DIRS ${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES}) +endif() +set(__IMPLICT_DLINK_FLAGS ) +foreach(dir ${__IMPLICT_DLINK_DIRS}) + if(EXISTS "${dir}/cublas_device.lib") + string(APPEND __IMPLICT_DLINK_FLAGS " -L\"${dir}\"") + endif() +endforeach() +unset(__IMPLICT_DLINK_DIRS) + set(CMAKE_CUDA_DEVICE_LINK_LIBRARY - "<CMAKE_CUDA_COMPILER> <CMAKE_CUDA_LINK_FLAGS> <LANGUAGE_COMPILE_FLAGS> ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS") + "<CMAKE_CUDA_COMPILER> <CMAKE_CUDA_LINK_FLAGS> <LANGUAGE_COMPILE_FLAGS> ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS${__IMPLICT_DLINK_FLAGS}") set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE - "<CMAKE_CUDA_COMPILER> <FLAGS> <CMAKE_CUDA_LINK_FLAGS> ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS") + "<CMAKE_CUDA_COMPILER> <FLAGS> <CMAKE_CUDA_LINK_FLAGS> ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS${__IMPLICT_DLINK_FLAGS}") unset(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS) +unset(__IMPLICT_DLINK_FLAGS) string(REPLACE "/D" "-D" _PLATFORM_DEFINES_CUDA "${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_CXX}") diff --git a/Modules/Platform/Windows-df.cmake b/Modules/Platform/Windows-df.cmake index c59be45..f948914 100644 --- a/Modules/Platform/Windows-df.cmake +++ b/Modules/Platform/Windows-df.cmake @@ -30,9 +30,6 @@ set(CMAKE_Fortran_LINK_EXECUTABLE set(CMAKE_CREATE_WIN32_EXE /winapp) set(CMAKE_CREATE_CONSOLE_EXE ) -if(CMAKE_GENERATOR MATCHES "Visual Studio 8") - set (CMAKE_NO_BUILD_TYPE 1) -endif() # does the compiler support pdbtype and is it the newer compiler set(CMAKE_BUILD_TYPE_INIT Debug) diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index 8e7ca41..5f9afc1 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -5,7 +5,10 @@ UseSWIG ------- -Defines the following command for use with SWIG: +This file provides support for ``SWIG``. It is assumed that :module:`FindSWIG` +module has already been loaded. + +Defines the following command for use with ``SWIG``: .. command:: swig_add_library @@ -20,17 +23,19 @@ Defines the following command for use with SWIG: SOURCES <file>... ) - Targets created with command ``swig_add_library`` have the same capabilities as targets - created with command :command:`add_library`, so can be used with any command accepting a target - especially command :command:`target_link_libraries`. + Targets created with the ``swig_add_library`` command have the same + capabilities as targets created with the :command:`add_library` command, so + those targets can be used with any command expecting a target (e.g. + :command:`target_link_libraries`). The arguments are: ``TYPE`` - ``SHARED``, ``MODULE`` and ``STATIC`` have same semantic as command :command:`add_library`. - if ``USE_BUILD_SHARED_LIBS`` is specified, library type will be ``STATIC`` or ``SHARED`` - based on whether the current value of the variable :variable:`BUILD_SHARED_LIBS` is ``ON``. - If none is specified, ``MODULE`` will be used. + ``SHARED``, ``MODULE`` and ``STATIC`` have the same semantic as for the + :command:`add_library` command. If ``USE_BUILD_SHARED_LIBS`` is specified, + the library type will be ``STATIC`` or ``SHARED`` based on whether the + current value of the :variable:`BUILD_SHARED_LIBS` variable is ``ON``. If + no type is specified, ``MODULE`` will be used. ``LANGUAGE`` Specify the target language. @@ -39,22 +44,40 @@ Defines the following command for use with SWIG: Prevent the generation of the wrapper layer (swig ``-noproxy`` option). ``OUTPUT_DIR`` - Specify where to write the language specific files (swig ``-outdir`` option). - If not specified, variable ``CMAKE_SWIG_OUTDIR`` will be used. If none is specified, - :variable:`CMAKE_CURRENT_BINARY_DIR` is used. + Specify where to write the language specific files (swig ``-outdir`` + option). If not given, the ``CMAKE_SWIG_OUTDIR`` variable will be used. + If neither is specified, the default depends on the value of the + ``UseSWIG_MODULE_VERSION`` variable as follows: + + * If ``UseSWIG_MODULE_VERSION`` is 1 or is undefined, output is written to + the :variable:`CMAKE_CURRENT_BINARY_DIR` directory. + * If ``UseSWIG_MODULE_VERSION`` is 2, a dedicated directory will be used. + The path of this directory can be retrieved from the + ``SWIG_SUPPORT_FILES_DIRECTORY`` target property. ``OUTFILE_DIR`` - Specify an output directory name where the generated source file will be placed - (swig -o option). If not specified, variable ``SWIG_OUTFILE_DIR`` will be used. - If none is specified, option ``OUTPUT_DIR`` or variable ``CMAKE_SWIG_OUTDIR`` is used. + Specify an output directory name where the generated source file will be + placed (swig -o option). If not specified, the ``SWIG_OUTFILE_DIR`` variable + will be used. If neither is specified, ``OUTPUT_DIR`` or + ``CMAKE_SWIG_OUTDIR`` is used instead. ``SOURCES`` - List of sources for the library. Files with extension ``.i`` will be identified as sources - for ``SWIG`` tool. Other files will be handled in the standard way. + List of sources for the library. Files with extension ``.i`` will be + identified as sources for the ``SWIG`` tool. Other files will be handled in + the standard way. + +.. note:: -Source files properties on module files **must** be set before the invocation -of the ``swig_add_library`` command to specify special behavior of SWIG and ensure -generated files will receive required settings. + If ``UseSWIG_MODULE_VERSION`` is set to 2, it is **strongly** recommended + to use a dedicated directory unique to the target when either the + ``OUTPUT_DIR`` option or the ``CMAKE_SWIG_OUTDIR`` variable are specified. + The output directory contents are erased as part of the target build, so + to prevent interference between targets or losing other important files, each + target should have its own dedicated output directory. + +Source file properties on module files **must** be set before the invocation +of the ``swig_add_library`` command to specify special behavior of SWIG and +ensure generated files will receive the required settings. ``CPLUSPLUS`` Call SWIG in c++ mode. For example: @@ -66,7 +89,8 @@ generated files will receive required settings. ``INCLUDE_DIRECTORIES``, ``COMPILE_DEFINITIONS`` and ``COMPILE_OPTIONS`` Add custom flags to SWIG compiler and have same semantic as properties - :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and :prop_sf:`COMPILE_OPTIONS`. + :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and + :prop_sf:`COMPILE_OPTIONS`. ``GENERATED_INCLUDE_DIRECTORIES``, ``GENERATED_COMPILE_DEFINITIONS`` and ``GENERATED_COMPILE_OPTIONS`` Add custom flags to the C/C++ generated source. They will fill, respectively, @@ -85,12 +109,13 @@ generated files will receive required settings. set_property(SOURCE mymod.i PROPERTY SWIG_MODULE_NAME mymod_realname) -Target library properties can be set to apply same configuration to all SWIG input files. +Target library properties can be set to apply same configuration to all SWIG +input files. ``SWIG_INCLUDE_DIRECTORIES``, ``SWIG_COMPILE_DEFINITIONS`` and ``SWIG_COMPILE_OPTIONS`` - These properties will be applied to all SWIG input files and have same semantic as - target properties :prop_tgt:`INCLUDE_DIRECTORIES`, :prop_tgt:`COMPILE_DEFINITIONS` and - :prop_tgt:`COMPILE_OPTIONS`. + These properties will be applied to all SWIG input files and have same + semantic as target properties :prop_tgt:`INCLUDE_DIRECTORIES`, + :prop_tgt:`COMPILE_DEFINITIONS` and :prop_tgt:`COMPILE_OPTIONS`. .. code-block:: cmake @@ -99,12 +124,16 @@ Target library properties can be set to apply same configuration to all SWIG inp set_property(TARGET mymod PROPERTY SWIG_COMPILE_OPTIONS -bla -blb) ``SWIG_GENERATED_INCLUDE_DIRECTORIES``, ``SWIG_GENERATED_COMPILE_DEFINITIONS`` and ``SWIG_GENERATED_COMPILE_OPTIONS`` - These properties will populate, respectively, properties :prop_sf:`INCLUDE_DIRECTORIES`, - :prop_sf:`COMPILE_DEFINITIONS` and :prop_sf:`COMPILE_FLAGS` of all generated C/C++ files. + These properties will populate, respectively, properties + :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and + :prop_sf:`COMPILE_FLAGS` of all generated C/C++ files. ``SWIG_DEPENDS`` Add dependencies to all SWIG input files. +The following target properties are output properties and can be used to get +information about support files generated by ``SWIG`` interface compilation. + ``SWIG_SUPPORT_FILES`` This output property list of wrapper files generated during SWIG compilation. @@ -113,7 +142,26 @@ Target library properties can be set to apply same configuration to all SWIG inp swig_add_library(mymod LANGUAGE python SOURCES mymod.i) get_property(support_files TARGET mymod PROPERTY SWIG_SUPPORT_FILES) -Some variables can be set to specify special behavior of SWIG: + .. note:: + + Only most principal support files are listed. In case some advanced + features of ``SWIG`` are used (for example ``%template``), associated + support files may not be listed. Prefer to use the + ``SWIG_SUPPORT_FILES_DIRECTORY`` property to handle support files. + +``SWIG_SUPPORT_FILES_DIRECTORY`` + This output property specifies the directory where support files will be + generated. + +Some variables can be set to customize the behavior of ``swig_add_library`` +as well as ``SWIG``: + +``UseSWIG_MODULE_VERSION`` + Specify different behaviors for ``UseSWIG`` module. + + * Set to 1 or undefined: Legacy behavior is applied. + * Set to 2: A new strategy is applied regarding support files: the output + directory of support files is erased before ``SWIG`` interface compilation. ``CMAKE_SWIG_FLAGS`` Add flags to all swig calls. @@ -158,7 +206,6 @@ macro(SWIG_MODULE_INITIALIZE name language) string(TOUPPER "${language}" SWIG_MODULE_${name}_LANGUAGE) string(TOLOWER "${language}" SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG) - set(SWIG_MODULE_${name}_NAME "${name}") set(SWIG_MODULE_${name}_EXTRA_FLAGS) if (NOT DEFINED SWIG_MODULE_${name}_NOPROXY) set (SWIG_MODULE_${name}_NOPROXY FALSE) @@ -172,11 +219,6 @@ macro(SWIG_MODULE_INITIALIZE name language) endif() if(SWIG_MODULE_${name}_LANGUAGE STREQUAL "UNKNOWN") message(FATAL_ERROR "SWIG Error: Language \"${language}\" not found") - elseif(SWIG_MODULE_${name}_LANGUAGE STREQUAL "PYTHON" AND NOT SWIG_MODULE_${name}_NOPROXY) - # swig will produce a module.py containing an 'import _modulename' statement, - # which implies having a corresponding _modulename.so (*NIX), _modulename.pyd (Win32), - # unless the -noproxy flag is used - set(SWIG_MODULE_${name}_NAME "_${name}") elseif(SWIG_MODULE_${name}_LANGUAGE STREQUAL "PERL") list(APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow") endif() @@ -332,6 +374,14 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) list (APPEND swig_dependencies ${file_depends}) endif() + if (UseSWIG_MODULE_VERSION VERSION_EQUAL 2) + # as part of custom command, start by removing old generated files + # to ensure obsolete files do not stay + set (swig_cleanup_command COMMAND "${CMAKE_COMMAND}" -E remove_directory "${outdir}") + else() + unset (swig_cleanup_command) + endif() + # IMPLICIT_DEPENDS below can not handle situations where a dependent file is # removed. We need an extra step with timestamp and custom target, see #16830 # As this is needed only for Makefile generator do it conditionally @@ -352,10 +402,11 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) add_custom_command( OUTPUT ${swig_custom_output} ${swig_custom_products} + ${swig_cleanup_command} # Let's create the ${outdir} at execution time, in case dir contains $(OutDir) COMMAND "${CMAKE_COMMAND}" -E make_directory ${outdir} ${outfiledir} ${swig_timestamp_command} - COMMAND "${SWIG_EXECUTABLE}" + COMMAND "${CMAKE_COMMAND}" -E env "SWIG_LIB=${SWIG_DIR}" "${SWIG_EXECUTABLE}" "-${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}" "${swig_source_file_flags}" -outdir "${outdir}" @@ -434,6 +485,12 @@ function(SWIG_ADD_LIBRARY name) unset(_SAM_TYPE) endif() + if (NOT DEFINED UseSWIG_MODULE_VERSION) + set (UseSWIG_MODULE_VERSION 1) + elseif (NOT UseSWIG_MODULE_VERSION MATCHES "^(1|2)$") + message (FATAL_ERROR "UseSWIG_MODULE_VERSION: ${UseSWIG_MODULE_VERSION}: invalid value. 1 or 2 is expected.") + endif() + set (workingdir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${name}.dir") # set special variable to pass extra information to command SWIG_ADD_SOURCE_TO_MODULE # which cannot be changed due to legacy compatibility @@ -444,7 +501,11 @@ function(SWIG_ADD_LIBRARY name) if (CMAKE_SWIG_OUTDIR) set (outputdir "${CMAKE_SWIG_OUTDIR}") else() - set (outputdir "${CMAKE_CURRENT_BINARY_DIR}") + if (UseSWIG_MODULE_VERSION VERSION_EQUAL 2) + set (outputdir "${workingdir}/${_SAM_LANGUAGE}.files") + else() + set (outputdir "${CMAKE_CURRENT_BINARY_DIR}") + endif() endif() endif() @@ -470,6 +531,9 @@ function(SWIG_ADD_LIBRARY name) set(swig_dot_i_sources ${_SAM_SOURCES}) list(FILTER swig_dot_i_sources INCLUDE REGEX "\\.i$") + if (NOT swig_dot_i_sources) + message(FATAL_ERROR "SWIG_ADD_LIBRARY: no SWIG interface files specified") + endif() set(swig_other_sources ${_SAM_SOURCES}) list(REMOVE_ITEM swig_other_sources ${swig_dot_i_sources}) @@ -486,12 +550,14 @@ function(SWIG_ADD_LIBRARY name) endforeach() set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${swig_generated_sources} ${swig_generated_timestamps}) + if (UseSWIG_MODULE_VERSION VERSION_EQUAL 2) + set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${outputdir}") + endif() add_library(${name} ${_SAM_TYPE} ${swig_generated_sources} ${swig_other_sources}) - set_target_properties(${name} PROPERTIES OUTPUT_NAME "${SWIG_MODULE_${name}_NAME}") if(CMAKE_GENERATOR MATCHES "Make") # see IMPLICIT_DEPENDS above add_custom_target(${name}_swig_compilation DEPENDS ${swig_generated_timestamps}) @@ -524,8 +590,14 @@ function(SWIG_ADD_LIBRARY name) set_target_properties(${name} PROPERTIES PREFIX "") endif() elseif (swig_lowercase_language STREQUAL "python") - # this is only needed for the python case where a _modulename.so is generated - set_target_properties(${name} PROPERTIES PREFIX "") + if (SWIG_MODULE_${name}_NOPROXY) + set_target_properties(${name} PROPERTIES PREFIX "") + else() + # swig will produce a module.py containing an 'import _modulename' statement, + # which implies having a corresponding _modulename.so (*NIX), _modulename.pyd (Win32), + # unless the -noproxy flag is used + set_target_properties(${name} PROPERTIES PREFIX "_") + endif() # Python extension modules on Windows must have the extension ".pyd" # instead of ".dll" as of Python 2.5. Older python versions do support # this suffix. @@ -560,7 +632,10 @@ function(SWIG_ADD_LIBRARY name) # assume empty prefix because we expect the module to be dynamically loaded set_target_properties (${name} PROPERTIES PREFIX "") endif () - # target property SWIG_SUPPORT_FILES lists proxy support files + + # target property SWIG_SUPPORT_FILES_DIRECTORY specify output directory of support files + set_property (TARGET ${name} PROPERTY SWIG_SUPPORT_FILES_DIRECTORY "${outputdir}") + # target property SWIG_SUPPORT_FILES lists principal proxy support files if (NOT SWIG_MODULE_${name}_NOPROXY) string(TOUPPER "${_SAM_LANGUAGE}" swig_uppercase_language) set(swig_all_support_files) @@ -572,7 +647,7 @@ function(SWIG_ADD_LIBRARY name) if (swig_all_support_files) list(REMOVE_DUPLICATES swig_all_support_files) endif() - set_property (TARGET ${name} APPEND PROPERTY SWIG_SUPPORT_FILES ${swig_all_support_files}) + set_property (TARGET ${name} PROPERTY SWIG_SUPPORT_FILES ${swig_all_support_files}) endif() # to ensure legacy behavior, export some variables |