diff --git a/CMake/mitkSwigAddLibraryDependencies.cmake b/CMake/mitkSwigAddLibraryDependencies.cmake index 534d77ed80..bdcf1bffa9 100644 --- a/CMake/mitkSwigAddLibraryDependencies.cmake +++ b/CMake/mitkSwigAddLibraryDependencies.cmake @@ -1,43 +1,30 @@ #! This CMake macro adds the necessary library and incllude #! directories to a swig-project. #! #! params: #! swig_module : Name of the SWIG module, for example pyMITK #! library_names : Semicolon separated list of the libraries that are included, for example "MitkCore;mbilog" #! # function inspired by # https://stackoverflow.com/questions/37205274/swig-and-cmake-make-use-of-information-provided-by-target-include-directories # This function tells cmake which additional dependencies are existing # especially with respect to the linker dependencies. function(mitkSwigAddLibraryDependencies swig_module library_names) foreach(library_name ${library_names}) # Adding each library as a linker dependency: swig_link_libraries(${swig_module} ${library_name}) # Extracting all include directories from each given project and # then including these directories to the newly created swig project. get_property(LIBRARY_INCLUDES TARGET ${library_name} PROPERTY INTERFACE_INCLUDE_DIRECTORIES) # Checking each given librarie to include all includes from this library. - foreach(INCLUDE_PATH ${LIBRARY_INCLUDES}) - file(GLOB_RECURSE header_files "${INCLUDE_PATH}/*.h") - list(APPEND SWIG_MODULE_${swig_module}_EXTRA_DEPS ${header_files}) - # export variable to parent scope - set(SWIG_MODULE_${swig_module}_EXTRA_DEPS - ${SWIG_MODULE_${swig_module}_EXTRA_DEPS} PARENT_SCOPE) - endforeach() + endforeach() # In addition include python dependencies: include_directories( ${PYTHON_INCLUDE_DIR}) - list(APPEND SWIG_MODULE_${swig_module}_EXTRA_DEPS ${PYTHON_INCLUDE_DIR}) - #swig_link_libraries(${swig_module} ${PYTHON_LIBRARIES} ) - - # Add additional include paths, for example to the common files: - list(APPEND SWIG_MODULE_${swig_module}_EXTRA_DEPS ${SWIG_EXTRA_DEPS}) - set(SWIG_MODULE_${swig_module}_EXTRA_DEPS - ${SWIG_MODULE_${swig_module}_EXTRA_DEPS} PARENT_SCOPE) endfunction() diff --git a/CMake/mitkSwigPrepareFiles.cmake b/CMake/mitkSwigPrepareFiles.cmake index 8408f7e9f6..7e74d24aff 100644 --- a/CMake/mitkSwigPrepareFiles.cmake +++ b/CMake/mitkSwigPrepareFiles.cmake @@ -1,39 +1,56 @@ # This function is used to prepare all includes and files # that are necessary for a general swig project. -function(mitkSwigPrepareFiles swig_file library_names) +function(mitkSwigPrepareFiles swig_module swig_file library_names) # Ensure that the input file is parsed as a c++ file. This is done via # an additional source file property. set_source_files_properties ( ${swig_file} PROPERTIES CPLUSPLUS ON ) # This variable is used to add additional parameters to SWIG. # Using a list is necessary in order to be able to pass multiple parameters # which are given as optional parameters to the input file. set(ADDITIONAL_TMP_SWIG_INCLUDES "") foreach(library_name ${library_names}) # Extracting all include directories from each given project and # then including these directories to the newly created swig project. get_property(LIBRARY_INCLUDES TARGET ${library_name} PROPERTY INTERFACE_INCLUDE_DIRECTORIES) # Adding each include path as an additional swig parameter using # the swig-option "-I": foreach(INCLUDE_PATH ${LIBRARY_INCLUDES}) list(APPEND ADDITIONAL_TMP_SWIG_INCLUDES -I${INCLUDE_PATH} ) + + file(GLOB_RECURSE header_files "${INCLUDE_PATH}/*.h") + list(APPEND SWIG_MODULE_${swig_module}_EXTRA_DEPS ${header_files}) + # export variable to parent scope + set(SWIG_MODULE_${swig_module}_EXTRA_DEPS + ${SWIG_MODULE_${swig_module}_EXTRA_DEPS} PARENT_SCOPE) + endforeach() endforeach() # Add the Common Folder to the include system of SWIG list(APPEND ADDITIONAL_TMP_SWIG_INCLUDES -I${MITK_WRAPPING_COMMON_DIR} ) # This is necessary, because SWIG hard-codeds the integer size. See # https://github.com/swig/swig/issues/568 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") list(APPEND ADDITIONAL_TMP_SWIG_INCLUDES -DSWIGWORDSIZE64) endif() # Set the additional parameters to the input project file: set_property(SOURCE ${swig_file} PROPERTY SWIG_FLAGS ${ADDITIONAL_TMP_SWIG_INCLUDES} ) + + # In addition include python dependencies: + include_directories( ${PYTHON_INCLUDE_DIR}) + list(APPEND SWIG_MODULE_${swig_module}_EXTRA_DEPS ${PYTHON_INCLUDE_DIR}) + + # Add additional include paths, for example to the common files: + list(APPEND SWIG_MODULE_${swig_module}_EXTRA_DEPS ${SWIG_EXTRA_DEPS}) + + set(SWIG_MODULE_${swig_module}_EXTRA_DEPS + ${SWIG_MODULE_${swig_module}_EXTRA_DEPS} PARENT_SCOPE) endfunction() diff --git a/Wrapping/Python/CMakeLists.txt b/Wrapping/Python/CMakeLists.txt index 7c9c634fe6..ac708a0b76 100644 --- a/Wrapping/Python/CMakeLists.txt +++ b/Wrapping/Python/CMakeLists.txt @@ -1,77 +1,77 @@ # Version 2.8.1 is the minium requirement for this script. # this is lower than the general minimum requirement. #cmake_minimum_required ( VERSION 2.8.1 FATAL_ERROR ) include(mitkTargetLinkLibrariesWithDynamicLookup) project( MITK_Python ) set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "" FORCE) set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "" FORCE) mitk_check_dynamic_lookup(MODULE SHARED MITK_UNDEFINED_SYMBOLS_ALLOWED ) # # Find the necessary libraries etc.. # if ( MITK_UNDEFINED_SYMBOLS_ALLOWED ) set( _QUIET_LIBRARY "QUIET" ) else() set( _QUIET_LIBRARY "REQUIRED" ) endif() find_package ( PythonInterp REQUIRED ) find_package ( PythonLibs ${_QUIET_LIBRARY} ) include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} ) # # Options # option ( MITK_PYTHON_THREADS "Enable threaded python usage by unlocking the GIL." ON ) mark_as_advanced( MITK_PYTHON_THREADS ) option ( MITK_PYTHON_EGG "Add building of python eggs to the dist target." OFF ) mark_as_advanced( MITK_PYTHON_EGG ) option ( MITK_PYTHON_WHEEL "Add building of python wheels to the dist target." ON ) mark_as_advanced( MITK_PYTHON_WHEEL ) # Prepare the SWIG-File, i.e. especially add necessary include folders -mitkSwigPrepareFiles(MITK.i "MitkCore;MitkCLCore;MitkCLUtilities;ITKCommon") +mitkSwigPrepareFiles(pyMITK MITK.i "MitkCore;MitkCLCore;MitkCLUtilities;ITKCommon") # Add additional SWIG Parameters # These parameters depend on the target language set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_GLOBAL_FLAGS} -features autodoc=1 -keyword ) if( MITK_PYTHON_THREADS ) set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} -threads) endif() set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) # Create the actual SWIG project swig_add_module(pyMITK python MITK.i ) mitkSwigAddLibraryDependencies(pyMITK "MitkCore;MitkCLCore;MitkCLUtilities;ITKCommon") mitk_target_link_libraries_with_dynamic_lookup(${SWIG_MODULE_pyMITK_REAL_NAME} ${PYTHON_LIBRARIES}) if(DEFINED SKBUILD) message(WARNING "SKBuild exists") # Currently this installation install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pyMITK.py ${CMAKE_CURRENT_SOURCE_DIR}/Packaging/__init__.py # ${MITK_DOC_FILES} DESTINATION pyMITK COMPONENT Runtime ) install(TARGETS ${SWIG_MODULE_pyMITK_REAL_NAME} RUNTIME DESTINATION pyMITK LIBRARY DESTINATION pyMITK COMPONENT Runtime ) else() message(WARNING "SKBuild missing") include(LegacyPackaging.cmake) endif()