CMake: reorder Python detection
[libftdi] / python / CMakeLists.txt
index 4843396..5b6f420 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 )
@@ -8,8 +14,8 @@ else ()
     set ( SWIG_FOUND TRUE )
   endif ()
 endif ()
-find_package ( PythonLibs REQUIRED )
 find_package ( PythonInterp REQUIRED )
+find_package ( PythonLibs REQUIRED )
 
 include ( UseSWIG )
 include_directories ( BEFORE ${CMAKE_SOURCE_DIR}/src )
@@ -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 )