Commit b0247c74 authored by Guillaume Pasero's avatar Guillaume Pasero

ENH: use official UseSWIG from CMake

parent 8ebce204
This diff is collapsed.
......@@ -22,6 +22,8 @@ cmake_minimum_required(VERSION 3.10.2)
foreach(p
CMP0072 # CMake 3.11
CMP0078 # CMake 3.13
CMP0086 # CMake 3.14
)
if(POLICY ${p})
cmake_policy(SET ${p} NEW)
......
......@@ -18,18 +18,10 @@
# limitations under the License.
#
if ( OTB_WRAP_PYTHON )
include ( UseSWIGLocal )
list(APPEND SWIG_EXTRA_DEPS
otbWrapperSWIGIncludes.h
itkBase.includes
${CMAKE_CURRENT_SOURCE_DIR}/itkBase.i
${CMAKE_CURRENT_SOURCE_DIR}/itkMacro.i
)
include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} )
endif()
include(UseSWIG)
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
# Python SWIG configuration
if ( OTB_WRAP_PYTHON )
add_subdirectory(python)
endif()
\ No newline at end of file
endif()
......@@ -21,6 +21,14 @@
include_directories ( ${PYTHON_INCLUDE_DIR} )
include_directories ( ${CMAKE_CURRENT_SOURCE_DIR})
set_source_files_properties ( ../otbApplication.i PROPERTIES CPLUSPLUS ON )
# Get target name
set(extension_target _otbApplication)
if(POLICY CMP0078)
cmake_policy(GET CMP0078 swig_target_name_policy)
if (swig_target_name_policy STREQUAL "NEW")
set(extension_target otbApplication)
endif()
endif()
# Run swig
set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_GLOBAL_FLAGS})
if(NUMPY_FOUND)
......@@ -36,34 +44,35 @@ set(SWIG_MODULE_otbApplication_EXTRA_DEPS
otbPythonLogOutput.h
otbProgressReporterManager.h
OTBApplicationEngine)
SWIG_add_module( otbApplication python ../otbApplication.i
otbApplicationPYTHON_wrap.cxx
itkPyCommand.cxx
../python/otbPythonLogOutput.cxx
../python/otbProgressReporterManager.cxx)
SWIG_link_libraries( otbApplication ${PYTHON_LIBRARIES} OTBApplicationEngine )
set_target_properties(_otbApplication PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SWIG_OUTDIR})
swig_add_library( otbApplication
LANGUAGE python
SOURCES ../otbApplication.i
itkPyCommand.cxx
otbPythonLogOutput.cxx
otbProgressReporterManager.cxx)
swig_link_libraries( otbApplication ${PYTHON_LIBRARIES} OTBApplicationEngine )
set_target_properties(${extension_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SWIG_OUTDIR})
if(MSVC)
set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/otbApplicationPYTHON_wrap.cxx COMPILE_FLAGS "/wd4005" )
set_source_files_properties( ${CMAKE_SWIG_OUTDIR}/otbApplicationPYTHON_wrap.cxx COMPILE_FLAGS "/wd4005" )
else()
set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/otbApplicationPYTHON_wrap.cxx COMPILE_FLAGS "-w" )
set_source_files_properties( ${CMAKE_SWIG_OUTDIR}/otbApplicationPYTHON_wrap.cxx COMPILE_FLAGS "-w" )
endif()
# byte-compile the resulting python file
add_custom_command(
TARGET _otbApplication
TARGET ${extension_target}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Byte-compiling otbApplication.py"
COMMAND ${PYTHON_EXECUTABLE}
${CMAKE_SOURCE_DIR}/CMake/PythonCompile.py
${CMAKE_SWIG_OUTDIR}/otbApplication.py
DEPENDS _otbApplication
DEPENDS ${extension_target}
)
otb_module_target_label( _otbApplication )
otb_module_target_label( ${extension_target} )
install( TARGETS _otbApplication
install( TARGETS ${extension_target}
DESTINATION ${OTB_INSTALL_PYTHON_DIR}
COMPONENT RuntimeLibraries )
......
......@@ -19,7 +19,7 @@
#
set(TEST_DRIVER otbTestDriver
--add-before-env PYTHONPATH $<TARGET_FILE_DIR:_otbApplication>
--add-before-env PYTHONPATH ${CMAKE_BINARY_DIR}/${OTB_INSTALL_PYTHON_DIR}
--add-before-env OTB_APPLICATION_PATH $<TARGET_FILE_DIR:otbapp_Smoothing> )
if(WIN32)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment