chiark / gitweb /
Support cmake 3.13
authorJulien Schueller <schueller@phimeca.com>
Sat, 13 Oct 2018 08:43:00 +0000 (10:43 +0200)
committerJulien Schueller <schueller@phimeca.com>
Mon, 15 Oct 2018 06:44:33 +0000 (08:44 +0200)
src/swig/CMakeLists.txt

index 341e1db8d406c539fec79c443f30ca723f4c95d5..cae8060722cc312c4111ead6a88b772d54ac88bc 100644 (file)
@@ -1,4 +1,7 @@
 
+if (POLICY CMP0078)
+  cmake_policy(SET CMP0078 NEW)
+endif ()
 include (UseSWIG)
 include (TargetLinkLibrariesWithDynamicLookup)
 
@@ -16,24 +19,32 @@ set_source_files_properties (nlopt.i PROPERTIES CPLUSPLUS ON)
 
 if (NUMPY_FOUND AND PYTHONLIBS_FOUND)
 
-  set (SWIG_MODULE_nlopt_EXTRA_DEPS nlopt-python.i numpy.i)
+  set (SWIG_MODULE_nlopt_python_EXTRA_DEPS nlopt-python.i numpy.i)
 
+  # swig_add_module is deprecated
   if (CMAKE_VERSION VERSION_LESS 3.8)
-    swig_add_module (nlopt python nlopt.i)
+    swig_add_module (nlopt_python python nlopt.i)
+  else ()
+    swig_add_library (nlopt_python LANGUAGE python SOURCES nlopt.i)
+  endif ()
+
+  # UseSWIG generates now standard target names
+  if (CMAKE_VERSION VERSION_LESS 3.13)
+    set (nlopt_python ${SWIG_MODULE_nlopt_python_REAL_NAME})
   else ()
-    swig_add_library (nlopt LANGUAGE python SOURCES nlopt.i)
+    set (nlopt_python "nlopt_python")
   endif ()
 
-  target_include_directories (${SWIG_MODULE_nlopt_REAL_NAME} PUBLIC ${PYTHON_INCLUDE_DIRS})
-  target_include_directories (${SWIG_MODULE_nlopt_REAL_NAME} PUBLIC ${NUMPY_INCLUDE_DIRS})
+  target_include_directories (${nlopt_python} PUBLIC ${PYTHON_INCLUDE_DIRS})
+  target_include_directories (${nlopt_python} PUBLIC ${NUMPY_INCLUDE_DIRS})
 
-  swig_link_libraries (nlopt ${nlopt_lib})
-  target_link_libraries_with_dynamic_lookup (${SWIG_MODULE_nlopt_REAL_NAME} ${PYTHON_LIBRARIES})
+  swig_link_libraries (nlopt_python ${nlopt_lib})
+  target_link_libraries_with_dynamic_lookup (${nlopt_python} ${PYTHON_LIBRARIES})
 
-  set_target_properties (${SWIG_MODULE_nlopt_REAL_NAME} PROPERTIES OUTPUT_NAME _nlopt)
+  set_target_properties (${nlopt_python} PROPERTIES OUTPUT_NAME _nlopt)
 
   install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.py DESTINATION ${INSTALL_PYTHON_DIR})
-  install (TARGETS ${SWIG_MODULE_nlopt_REAL_NAME} LIBRARY DESTINATION ${INSTALL_PYTHON_DIR})
+  install (TARGETS ${nlopt_python} LIBRARY DESTINATION ${INSTALL_PYTHON_DIR})
 endif ()
 
 
@@ -43,16 +54,24 @@ if (GUILE_FOUND AND (SWIG_VERSION VERSION_GREATER 2.0.9))
   set_source_files_properties (nlopt.i PROPERTIES SWIG_FLAGS "-scmstub")
   set (SWIG_MODULE_nlopt_guile_EXTRA_DEPS nlopt-guile.i)
 
+  # swig_add_module is deprecated
   if (CMAKE_VERSION VERSION_LESS 3.8)
     swig_add_module (nlopt_guile guile nlopt.i)
   else ()
     swig_add_library (nlopt_guile LANGUAGE guile SOURCES nlopt.i)
   endif ()
 
-  target_include_directories (${SWIG_MODULE_nlopt_guile_REAL_NAME} PUBLIC ${GUILE_INCLUDE_DIRS})
+  # UseSWIG generates now standard target names
+  if (CMAKE_VERSION VERSION_LESS 3.13)
+    set (nlopt_guile ${SWIG_MODULE_nlopt_guile_REAL_NAME})
+  else ()
+    set (nlopt_guile "nlopt_guile")
+  endif ()
+
+  target_include_directories (${nlopt_guile} PUBLIC ${GUILE_INCLUDE_DIRS})
 
   swig_link_libraries (nlopt_guile ${nlopt_lib})
-  target_link_libraries_with_dynamic_lookup (${SWIG_MODULE_nlopt_guile_REAL_NAME} ${GUILE_LIBRARIES})
+  target_link_libraries_with_dynamic_lookup (${nlopt_guile} ${GUILE_LIBRARIES})
 
   file (RELATIVE_PATH _REL_GUILE_SITE_PATH ${GUILE_ROOT_DIR} ${GUILE_SITE_DIR})
   set (GUILE_SITE_PATH ${_REL_GUILE_SITE_PATH})
@@ -60,5 +79,5 @@ if (GUILE_FOUND AND (SWIG_VERSION VERSION_GREATER 2.0.9))
 
   file (RELATIVE_PATH _REL_GUILE_EXTENSION_PATH ${GUILE_ROOT_DIR} ${GUILE_EXTENSION_DIR})
   set (GUILE_EXTENSION_PATH ${_REL_GUILE_EXTENSION_PATH})
-  install (TARGETS ${SWIG_MODULE_nlopt_guile_REAL_NAME} LIBRARY DESTINATION ${GUILE_EXTENSION_PATH})
+  install (TARGETS ${nlopt_guile} LIBRARY DESTINATION ${GUILE_EXTENSION_PATH})
 endif ()