1macro(subdirlist result curdir) 2 file(GLOB children RELATIVE ${curdir} ${curdir}/*) 3 set(dirlist "") 4 foreach(child ${children}) 5 if(IS_DIRECTORY ${curdir}/${child}) 6 set(dirlist ${dirlist} ${child}) 7 endif() 8 endforeach() 9 set(${result} ${dirlist}) 10endmacro() 11 12macro (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}) 16endmacro (upm_CREATE_INSTALL_PKGCONFIG) 17 18macro(upm_SWIG_PYTHON) 19 if (BUILDSWIGPYTHON AND BUILDSWIG) 20 set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON) 21 swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${module_src}) 22 swig_link_libraries (pyupm_${libname} ${PYTHON_LIBRARIES} ${MRAA_LIBRARIES}) 23 target_include_directories ( ${SWIG_MODULE_pyupm_${libname}_REAL_NAME} 24 PUBLIC 25 "${PYTHON_INCLUDE_PATH}" 26 "${PYTHON_INCLUDE_DIRS}" 27 ) 28 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_pyupm_${libname}.so 29 ${CMAKE_CURRENT_BINARY_DIR}/pyupm_${libname}.py 30 DESTINATION ${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/ 31 COMPONENT ${libname}) 32 endif() 33endmacro() 34 35macro(upm_SWIG_NODE) 36 if (BUILDSWIGNODE AND BUILDSWIG) 37 set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON) 38 set_source_files_properties (jsupm_${libname}.i PROPERTIES SWIG_FLAGS "-node") 39 swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i ${module_src}) 40 swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES}) 41 target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME} 42 PUBLIC 43 "${NODE_INCLUDE_DIRS}" 44 ) 45 set_target_properties (jsupm_${libname} PROPERTIES 46 COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=0x0${V8_DEFINE_STRING}" 47 PREFIX "" 48 SUFFIX ".node" 49 ) 50 createpackagejson(${libname}) 51 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}.node 52 DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname}) 53 endif() 54endmacro() 55 56macro(upm_SWIG_JAVA) 57 if (BUILDSWIGJAVA AND BUILDSWIG) 58 59 FIND_PACKAGE (JNI REQUIRED) 60 61 include_directories ( 62 ${JAVA_INCLUDE_PATH} 63 ${JAVA_INCLUDE_PATH2} 64 ${CMAKE_CURRENT_SOURCE_DIR}/.. 65 ) 66 67 set_source_files_properties (javaupm_${libname}.i PROPERTIES CPLUSPLUS ON) 68 set_source_files_properties (javaupm_${libname}.i PROPERTIES SWIG_FLAGS ";-package;upm_${libname};-I${CMAKE_BINARY_DIR}/src") 69 swig_add_module (javaupm_${libname} java javaupm_${libname}.i ${module_src}) 70 swig_link_libraries (javaupm_${libname} ${MRAA_LIBRARIES} ${JAVA_LIBRARIES}) 71 target_include_directories ( ${SWIG_MODULE_javaupm_${libname}_REAL_NAME} 72 PUBLIC 73 "${JAVA_INCLUDE_DIRS}" 74 "${JAVA_INCLUDE_PATH}" 75 ) 76 set_target_properties (javaupm_${libname} PROPERTIES 77 COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -DJAVACALLBACK" 78 PREFIX "lib" 79 SUFFIX ".so" 80 ) 81 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/libjavaupm_${libname}.so 82 DESTINATION lib/java 83 ) 84 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/upm_${libname}.jar 85 DESTINATION lib/java 86 ) 87 88 if (NOT DEFINED $ENV{JAVA_HOME_NATIVE}) 89 set (JAVAC $ENV{JAVA_HOME}/bin/javac) 90 set (JAR $ENV{JAVA_HOME}/bin/jar) 91 else () 92 set (JAVAC $ENV{JAVA_HOME_NATIVE}/bin/javac) 93 set (JAR $ENV{JAVA_HOME_NATIVE}/bin/jar) 94 endif () 95 96 add_custom_command (TARGET javaupm_${libname} 97 POST_BUILD 98 COMMAND cmake -E echo "Compiling java.." 99 COMMAND cmake -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/upm_${libname} 100 COMMAND ${JAVAC} *.java -d ${CMAKE_CURRENT_BINARY_DIR} 101 COMMAND cmake -E echo "Creating jar" 102 COMMAND ${JAR} cvf upm_${libname}.jar upm_${libname} 103 ) 104 105 endif() 106endmacro() 107 108macro(upm_doxygen) 109 if (DOXYGEN_FOUND) 110 if(NOT DEFINED classname) 111 set (classname ${libname}) 112 endif() 113 set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND}) 114 add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i 115 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n 116 ${CMAKE_BINARY_DIR}/xml/${classname}_8h.xml 117 ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i 118 DEPENDS ${CMAKE_BINARY_DIR}/xml/${classname}_8h.xml 119 ) 120 add_custom_target (${libname}doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i) 121 add_dependencies (${libname}doc_i doc) 122 if (BUILDSWIG) 123 add_dependencies (_pyupm_${libname} ${libname}doc_i) 124 add_dependencies (pydoc _pyupm_${libname}) 125 else () 126 add_dependencies (${libname} doc) 127 endif () 128 endif () 129endmacro() 130 131if (SWIG_FOUND) 132 if(BUILDSWIGPYTHON) 133 find_package (PythonLibs) 134 string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING}) 135 list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR) 136 list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR) 137 endif(BUILDSWIGPYTHON) 138 if(BUILDSWIGNODE) 139 if(NOT NODE_FOUND) 140 find_package(Node) 141 endif() 142 if(SWIG_VERSION VERSION_LESS 3.0.5 AND NODE_VERSION_STRING VERSION_GREATER 0.12) 143 message("WARNING - SWIG 3.0.5+ required for building with nodejs 0.12. Current version is ${SWIG_VERSION}") 144 endif() 145 find_path (NODE_ROOT_DIR "node/node.h") 146 set (NODE_INCLUDE_DIRS 147 ${NODE_ROOT_DIR}/src 148 ${NODE_ROOT_DIR}/node 149 ${NODE_ROOT_DIR}/deps/v8/include 150 ${NODE_ROOT_DIR}/deps/uv/include 151 ) 152 macro(createpackagejson) 153 configure_file (${PROJECT_SOURCE_DIR}/src/package.json.in ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY) 154 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json 155 DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname}) 156 endmacro() 157 158 endif(BUILDSWIGNODE) 159# if(BUILDSWIGJAVA) 160# add_subdirectory (java) 161# endif(BUILDSWIGJAVA) 162 163endif() 164 165macro(upm_module_init) 166 add_library (${libname} SHARED ${module_src}) 167 foreach (linkflag ${ARGN}) 168 target_link_libraries (${libname} ${linkflag}) 169 endforeach () 170 include_directories (${MRAA_INCLUDE_DIR} .) 171 target_link_libraries (${libname} ${MRAA_LIBRARIES}) 172 set_target_properties( 173 ${libname} 174 PROPERTIES PREFIX "libupm-" 175 SOVERSION ${upm_VERSION_MAJOR} 176 VERSION ${upm_VERSION_STRING} 177 ) 178 upm_create_install_pkgconfig (upm-${libname}.pc lib${LIB_SUFFIX}/pkgconfig) 179 if (SWIG_FOUND) 180 upm_swig_python() 181 upm_swig_node() 182 upm_swig_java() 183 endif() 184 if (BUILDDOC) 185 upm_doxygen() 186 endif() 187 install(TARGETS ${libname} DESTINATION ${CMAKE_INSTALL_LIBDIR}) 188 install (FILES ${module_h} DESTINATION include/upm COMPONENT ${libname}) 189 190 if (IPK) 191 cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all) 192 set(CPACK_COMPONENT_${libname}_DESCRIPTION "${libdescription}") 193 endif() 194endmacro(upm_module_init) 195 196subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR}) 197foreach(subdir ${SUBDIRS}) 198 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/CMakeLists.txt) 199 add_subdirectory(${subdir}) 200 endif() 201endforeach() 202