chiark / gitweb /
strip
[nlopt.git] / src / swig / CMakeLists.txt
1
2 if (POLICY CMP0078)
3   cmake_policy(SET CMP0078 NEW)
4 endif ()
5 include (UseSWIG)
6 include (TargetLinkLibrariesWithDynamicLookup)
7
8 if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-enum-renames.i)
9   file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/nlopt-enum-renames.i "// AUTOMATICALLY GENERATED -- DO NOT EDIT\n")
10   file (STRINGS ${PROJECT_SOURCE_DIR}/src/api/nlopt.h NLOPT_H_LINES REGEX "    NLOPT_[A-Z0-9_]+")
11   foreach (NLOPT_H_LINE ${NLOPT_H_LINES})
12     string (REGEX REPLACE ".*NLOPT_([A-Z0-9_]+).*" "%rename(NLOPT_\\1) nlopt::\\1;\n" ENUM_LINE ${NLOPT_H_LINE})
13     file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/nlopt-enum-renames.i "${ENUM_LINE}")
14   endforeach ()
15 endif ()
16
17 include_directories (${NLOPT_PRIVATE_INCLUDE_DIRS})
18 set_source_files_properties (nlopt.i PROPERTIES CPLUSPLUS ON)
19
20 if (NUMPY_FOUND AND PYTHONLIBS_FOUND)
21
22   set (SWIG_MODULE_nlopt_python_EXTRA_DEPS nlopt-python.i numpy.i)
23
24   # swig_add_module is deprecated
25   if (CMAKE_VERSION VERSION_LESS 3.8)
26     swig_add_module (nlopt_python python nlopt.i)
27   else ()
28     swig_add_library (nlopt_python LANGUAGE python SOURCES nlopt.i)
29   endif ()
30
31   # UseSWIG generates now standard target names
32   if (CMAKE_VERSION VERSION_LESS 3.13)
33     set (nlopt_python ${SWIG_MODULE_nlopt_python_REAL_NAME})
34   else ()
35     set (nlopt_python "nlopt_python")
36   endif ()
37
38   target_include_directories (${nlopt_python} PUBLIC ${PYTHON_INCLUDE_DIRS})
39   target_include_directories (${nlopt_python} PUBLIC ${NUMPY_INCLUDE_DIRS})
40
41   swig_link_libraries (nlopt_python ${nlopt_lib})
42   target_link_libraries_with_dynamic_lookup (${nlopt_python} ${PYTHON_LIBRARIES})
43
44   set_target_properties (${nlopt_python} PROPERTIES OUTPUT_NAME nlopt)
45   if (CMAKE_VERSION VERSION_LESS 3.13)
46     set_target_properties (${nlopt_python} PROPERTIES PREFIX "_")
47   endif ()
48
49   install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.py DESTINATION ${INSTALL_PYTHON_DIR})
50   install (TARGETS ${nlopt_python} LIBRARY DESTINATION ${INSTALL_PYTHON_DIR})
51 endif ()
52
53
54 # guile bindings with gcc only ok with swig >= 2.0.10
55 if (GUILE_FOUND AND (SWIG_VERSION VERSION_GREATER 2.0.9))
56
57   set_source_files_properties (nlopt.i PROPERTIES SWIG_FLAGS "-scmstub")
58   set (SWIG_MODULE_nlopt_guile_EXTRA_DEPS nlopt-guile.i)
59
60   # swig_add_module is deprecated
61   if (CMAKE_VERSION VERSION_LESS 3.8)
62     swig_add_module (nlopt_guile guile nlopt.i)
63   else ()
64     swig_add_library (nlopt_guile LANGUAGE guile SOURCES nlopt.i)
65   endif ()
66
67   # UseSWIG generates now standard target names
68   if (CMAKE_VERSION VERSION_LESS 3.13)
69     set (nlopt_guile ${SWIG_MODULE_nlopt_guile_REAL_NAME})
70   else ()
71     set (nlopt_guile "nlopt_guile")
72   endif ()
73
74   target_include_directories (${nlopt_guile} PUBLIC ${GUILE_INCLUDE_DIRS})
75
76   swig_link_libraries (nlopt_guile ${nlopt_lib})
77   target_link_libraries_with_dynamic_lookup (${nlopt_guile} ${GUILE_LIBRARIES})
78
79   file (RELATIVE_PATH _REL_GUILE_SITE_PATH ${GUILE_ROOT_DIR} ${GUILE_SITE_DIR})
80   set (GUILE_SITE_PATH ${_REL_GUILE_SITE_PATH})
81   install (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlopt.scm DESTINATION ${GUILE_SITE_PATH})
82
83   file (RELATIVE_PATH _REL_GUILE_EXTENSION_PATH ${GUILE_ROOT_DIR} ${GUILE_EXTENSION_DIR})
84   set (GUILE_EXTENSION_PATH ${_REL_GUILE_EXTENSION_PATH})
85   install (TARGETS ${nlopt_guile} LIBRARY DESTINATION ${GUILE_EXTENSION_PATH})
86 endif ()