Browse Source

cmake: update swig support

* Bumped required CMake Version

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
Thomas Ingleby 10 years ago
parent
commit
d71e4e5dc2
4 changed files with 128 additions and 2 deletions
  1. 5
    2
      CMakeLists.txt
  2. 104
    0
      src/CMakeLists.txt
  3. 8
    0
      src/package.json.in
  4. 11
    0
      src/pkgconfig.in

+ 5
- 2
CMakeLists.txt View File

@@ -1,4 +1,4 @@
1
-cmake_minimum_required (VERSION 2.8)
1
+cmake_minimum_required (VERSION 2.8.11)
2 2
 project (upm)
3 3
 
4 4
 find_package (SWIG)
@@ -39,12 +39,15 @@ endif()
39 39
 set (upm_VERSION_MAJOR ${VERSION_MAJOR})
40 40
 set (upm_VERSION_MINOR ${VERSION_MINOR})
41 41
 set (upm_VERSION_PATCH ${VERSION_PATCH})
42
-set (upm_VERSION_STRING ${maa_VERSION_MAJOR}.${maa_VERSION_MINOR}.${maa_VERSION_PATCH})
42
+set (upm_VERSION_STRING ${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH})
43 43
 
44 44
 set (CMAKE_SWIG_FLAGS "")
45 45
 
46 46
 option (IPK "Generate IPK using CPack" OFF)
47 47
 option (BUILDDOC "Build all doc." OFF)
48
+option (BUILDSWIG "Build swig modules." ON)
49
+option (BUILDSWIGPYTHON "Build swig python modules." ON)
50
+option (BUILDSWIGNODE "Build swig node modules." ON)
48 51
 
49 52
 if (BUILDDOC)
50 53
   # add a target to generate API documentation with Doxygen

+ 104
- 0
src/CMakeLists.txt View File

@@ -8,6 +8,110 @@ macro(subdirlist result curdir)
8 8
   endforeach()
9 9
   set(${result} ${dirlist})
10 10
 endmacro()
11
+
12
+macro (upm_CREATE_INSTALL_PKGCONFIG generated_file install_location)
13
+  configure_file (${PROJECT_SOURCE_DIR}/src/pkgconfig.in
14
+    ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY)
15
+  install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} DESTINATION ${install_location})
16
+endmacro (upm_CREATE_INSTALL_PKGCONFIG)
17
+
18
+macro(upm_SWIG_PYTHON)
19
+  if(BUILDSWIGPYTHON)
20
+    set (CMAKE_C_FLAGS -DSWIGPYTHON=${SWIG_FOUND})
21
+    set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
22
+    swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${libname}.cxx)
23
+    swig_link_libraries (pyupm_${libname} ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
24
+    target_include_directories ( ${SWIG_MODULE_pyupm_${libname}_REAL_NAME}
25
+      PUBLIC
26
+      "${PYTHON_INCLUDE_PATH}"
27
+      "${PYTHON_INCLUDE_DIRS}"
28
+     )
29
+    install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_pyupm_${libname}.so
30
+         ${CMAKE_CURRENT_BINARY_DIR}/pyupm_${libname}.py
31
+         DESTINATION lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/
32
+         COMPONENT ${libname})
33
+  endif()
34
+endmacro()
35
+
36
+macro(upm_SWIG_NODE)
37
+  if(BUILDSWIGNODE)
38
+    set (CMAKE_CXX_FLAGS -DBUILDING_NODE_EXTENSION)
39
+    set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
40
+    set_source_files_properties (jsupm_${libname}.i PROPERTIES SWIG_FLAGS "-node")
41
+    swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i ${libname}.cxx)
42
+    swig_link_libraries (jsupm_${libname} ${MAA_LIBRARIES} ${NODE_LIBRARIES})
43
+    target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
44
+      PUBLIC
45
+      "${NODE_INCLUDE_DIRS}"
46
+     )
47
+    set_target_properties (jsupm_${libname} PROPERTIES
48
+      PREFIX ""
49
+      SUFFIX ".node"
50
+    )
51
+    createpackagejson(${libname})
52
+    install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}.node
53
+         DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
54
+  endif()
55
+endmacro()
56
+
57
+macro(upm_doxygen)
58
+  if (DOXYGEN_FOUND)
59
+    set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
60
+    add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
61
+      COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n
62
+        ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
63
+        ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
64
+        DEPENDS ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
65
+    )
66
+    add_custom_target (${libname}doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i)
67
+    add_dependencies (${libname}doc_i doc)
68
+    add_dependencies (${SWIG_MODULE_pyupm_${libname}_REAL_NAME} ${libname}doc_i)
69
+  endif ()
70
+endmacro()
71
+
72
+if (SWIG_FOUND)
73
+  if(BUILDSWIGPYTHON)
74
+    find_package (PythonLibs)
75
+    string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
76
+    list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
77
+    list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
78
+  endif(BUILDSWIGPYTHON)
79
+  if(BUILDSWIGNODE)
80
+    find_path (NODE_ROOT_DIR "node/node.h")
81
+    set (NODE_INCLUDE_DIRS
82
+      ${NODE_ROOT_DIR}/src
83
+      ${NODE_ROOT_DIR}/node
84
+      ${NODE_ROOT_DIR}/deps/v8/include
85
+      ${NODE_ROOT_DIR}/deps/uv/include
86
+    )
87
+    macro(createpackagejson)
88
+        configure_file (${PROJECT_SOURCE_DIR}/src/package.json.in ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY)
89
+        install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json
90
+            DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
91
+    endmacro()
92
+
93
+  endif(BUILDSWIGNODE)
94
+endif()
95
+
96
+macro(upm_module_init)
97
+  include_directories (${MAA_INCLUDE_DIR} .)
98
+  target_link_libraries (${libname} ${MAA_LIBRARIES})
99
+  set_target_properties(${libname} PROPERTIES PREFIX "libupm-")
100
+  upm_create_install_pkgconfig (upm-${libname}.pc lib${LIB_SUFFIX}/pkgconfig)
101
+  if (SWIG_FOUND)
102
+    upm_swig_python()
103
+    upm_swig_node()
104
+    upm_doxygen()
105
+  endif()
106
+  install (TARGETS ${libname} DESTINATION lib COMPONENT ${libname})
107
+  install (FILES ${libname}.h DESTINATION include/upm COMPONENT ${libname})
108
+
109
+  if (IPK)
110
+    cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
111
+    set(CPACK_COMPONENT_${libname}_DESCRIPTION "${libdescription}")
112
+  endif()
113
+endmacro(upm_module_init)
114
+
11 115
 subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
12 116
 foreach(subdir ${SUBDIRS})
13 117
     add_subdirectory(${subdir})

+ 8
- 0
src/package.json.in View File

@@ -0,0 +1,8 @@
1
+{
2
+  "name" : "jsupm_@libname@",
3
+  "main" : "./jsupm_@libname@.node",
4
+  "engines": {
5
+    "node": ">= 1.0.x"
6
+  },
7
+  "license": "MIT"
8
+}

+ 11
- 0
src/pkgconfig.in View File

@@ -0,0 +1,11 @@
1
+prefix=@CMAKE_INSTALL_PREFIX@
2
+exec_prefix=${prefix}
3
+libdir=${exec_prefix}/lib@LIB_SUFFIX@
4
+includedir=${prefix}/include
5
+
6
+Name: upm-@libname@
7
+Description: upm lib @libname@
8
+Version: @upm_VERSION_STRING@
9
+
10
+Libs: -L${libdir} -lupm-@libname@
11
+Cflags: -I${includedir}/upm