Fix build dependency if swig wrapper and documentation is both switched on
[libftdi] / python / CMakeLists.txt
index 4843396..fc1c3d1 100644 (file)
@@ -1,5 +1,11 @@
+# swig_add_library behavior changed in cmake 3.13 to no longer set
+# SWIG_MODULE_<target>_REAL_NAME, so restore the old behavior.
+if ( POLICY CMP0078 )
+  cmake_policy( SET CMP0078 OLD )
+endif ()
+
 # workaround for cmake bug #0013449
-if ( NOT DEFINED CMAKE_FIND_ROOT_PATH )
+if ( NOT DEFINED CMAKE_FIND_ROOT_PATH OR NOT CMAKE_VERSION VERSION_LESS 3.0.0 )
   find_package ( SWIG REQUIRED )
 else ()
   find_program ( SWIG_EXECUTABLE NAMES swig2.0 swig )
@@ -18,8 +24,14 @@ link_directories ( ${CMAKE_CURRENT_BINARY_DIR}/../src )
 
 if ( DOCUMENTATION )
   set(CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
+  # manually add dependency for new cmake / swig versions
+  set_property(SOURCE ftdi1.i PROPERTY DEPENDS ftdi1_doc.i)
+endif()
+if(NOT CMAKE_VERSION VERSION_LESS 3.8.0)
+  swig_add_library ( ftdi1 LANGUAGE python SOURCES ftdi1.i )
+else ()
+  swig_add_module ( ftdi1 python ftdi1.i )
 endif()
-swig_add_module ( ftdi1 python ftdi1.i )
 swig_link_libraries ( ftdi1 ftdi1 )
 
 if ( LINK_PYTHON_LIBRARY )