2016-11-03 16:10:35 -07:00
|
|
|
# Selectively disable certain CXX warnings for SWIG wrappers
|
|
|
|
# SWIG wrappers emit -Wdelete-non-virtual-dtor and -Wunused-function warnings
|
2017-02-01 15:41:39 -08:00
|
|
|
# Unfortunaly this quick fix for issue #518, adds a .c file to the
|
|
|
|
# java swig wrapper which then failes on CXX compiler warnings. For
|
|
|
|
# now, turn off warnings as errors for all the swig wrappers.
|
2017-02-02 12:25:59 -07:00
|
|
|
set (SWIG_CXX_DISABLE_WARNINGS -Wno-error
|
|
|
|
-Wno-delete-non-virtual-dtor
|
|
|
|
-Wno-unused-function
|
|
|
|
-Wno-maybe-uninitialized
|
|
|
|
-Wno-strict-aliasing)
|
2016-11-03 16:10:35 -07:00
|
|
|
|
2017-02-07 17:00:29 -08:00
|
|
|
# If building under android, make sure swig gets an ANDROID flag
|
|
|
|
if (ANDROID)
|
|
|
|
list (APPEND CMAKE_SWIG_FLAGS -DANDROID)
|
|
|
|
endif (ANDROID)
|
|
|
|
|
2016-01-13 13:38:23 +02:00
|
|
|
macro (file_to_list readfile outlist)
|
|
|
|
FILE(READ "${readfile}" contents)
|
|
|
|
STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}")
|
|
|
|
STRING(REGEX REPLACE "\n" ";" contents "${contents}")
|
|
|
|
set("${outlist}" "${contents}" )
|
2016-08-17 17:58:21 -07:00
|
|
|
endmacro(file_to_list)
|
2016-01-13 13:38:23 +02:00
|
|
|
|
|
|
|
file_to_list ("javaswig_blacklist" JAVASWIG_BLACKLIST)
|
|
|
|
file_to_list ("pythonswig_blacklist" PYTHONSWIG_BLACKLIST)
|
|
|
|
file_to_list ("nodeswig_blacklist" NODESWIG_BLACKLIST)
|
|
|
|
|
2014-06-05 13:58:34 +01:00
|
|
|
macro(subdirlist result curdir)
|
|
|
|
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
|
|
|
set(dirlist "")
|
|
|
|
foreach(child ${children})
|
|
|
|
if(IS_DIRECTORY ${curdir}/${child})
|
|
|
|
set(dirlist ${dirlist} ${child})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(${result} ${dirlist})
|
2016-08-17 17:58:21 -07:00
|
|
|
endmacro(subdirlist)
|
2014-06-11 13:54:19 +01:00
|
|
|
|
2016-08-17 17:58:21 -07:00
|
|
|
macro (upm_create_install_pkgconfig generated_file install_location)
|
2014-06-11 13:54:19 +01:00
|
|
|
configure_file (${PROJECT_SOURCE_DIR}/src/pkgconfig.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY)
|
|
|
|
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} DESTINATION ${install_location})
|
2016-08-17 17:58:21 -07:00
|
|
|
endmacro(upm_create_install_pkgconfig)
|
2014-06-11 13:54:19 +01:00
|
|
|
|
2017-02-07 17:00:29 -08:00
|
|
|
# Given a target name, return all in-project targets ALREADY defined (ie, this
|
|
|
|
# does not comprehend targets that have yet to be added.
|
|
|
|
function (_get_dependency_targets target return_variable)
|
|
|
|
# Clear the variable
|
|
|
|
set(${return_variable} "")
|
|
|
|
|
|
|
|
# Get the LINK_LIBRARIES property of the target
|
|
|
|
get_target_property(_dep_libs ${target} LINK_LIBRARIES)
|
|
|
|
|
|
|
|
# Remove this libname from the _dep_libs (if it exists)
|
|
|
|
list(REMOVE_ITEM _dep_libs ${libname})
|
|
|
|
|
|
|
|
# Check if any of the LINK_LIBRARIES are targets in this project,
|
|
|
|
# if so, add them to ${return_variable}
|
|
|
|
foreach (deplib ${_dep_libs})
|
|
|
|
# Only add targets that exist
|
|
|
|
if (TARGET ${deplib})
|
|
|
|
list(APPEND ${return_variable} ${deplib})
|
|
|
|
# Special case - mraa is NOT in this project, but add it to the
|
|
|
|
# reqlibname list (used in various items like pom files, .pc files, etc
|
|
|
|
elseif (${deplib} MATCHES mraa)
|
|
|
|
list(APPEND ${return_variable} mraa)
|
|
|
|
endif (TARGET ${deplib})
|
|
|
|
endforeach (deplib ${_dep_libs})
|
|
|
|
# Uniquify
|
|
|
|
list(REMOVE_DUPLICATES ${return_variable})
|
|
|
|
# Make the list available outside this function
|
|
|
|
set (${return_variable} ${${return_variable}} PARENT_SCOPE)
|
|
|
|
endfunction (_get_dependency_targets target)
|
|
|
|
|
|
|
|
# This function iterates over all provided target names and
|
|
|
|
# writes a .pc file to each build directory
|
|
|
|
function (_gen_pkg_config_per_target LABEL)
|
|
|
|
list(LENGTH ARGN n_targets)
|
|
|
|
message(STATUS "Generating pkg-config files for ${n_targets} ${LABEL} libraries...")
|
2017-01-30 18:14:48 -08:00
|
|
|
# Iterate over the targets an build package config (.pc) files
|
2017-02-07 17:00:29 -08:00
|
|
|
foreach (target ${ARGN})
|
2017-01-30 18:14:48 -08:00
|
|
|
if (TARGET ${target})
|
|
|
|
get_target_property(libname ${target} PKG_CONFIG_NAME)
|
|
|
|
get_target_property(libdescription ${target} PKG_CONFIG_DESCRIPTION)
|
|
|
|
get_target_property(reqlibname ${target} PKG_EXT_REQ_LIBS)
|
|
|
|
get_target_property(BINARY_DIR ${target} BINARY_DIR)
|
2017-02-07 17:00:29 -08:00
|
|
|
|
|
|
|
# Get a list of in-project dependency targets for this target
|
|
|
|
_get_dependency_targets(${target} DEPLIBS)
|
|
|
|
|
2017-01-30 18:14:48 -08:00
|
|
|
# Check if any of the LINK_LIBRARIES are targets in this project,
|
|
|
|
# if so, add them to reqlibname
|
|
|
|
foreach (deplib ${DEPLIBS})
|
2017-02-07 17:00:29 -08:00
|
|
|
# Get the actual library name (which equates to it's .pc filename,
|
|
|
|
# example: target dfrph = <upm-dfrph>.pc
|
2017-01-30 18:14:48 -08:00
|
|
|
if (TARGET ${deplib})
|
|
|
|
get_target_property(deplibname ${deplib} PKG_CONFIG_NAME)
|
|
|
|
list(APPEND reqlibname ${deplibname})
|
|
|
|
elseif (${deplib} MATCHES mraa)
|
|
|
|
list(APPEND reqlibname mraa)
|
|
|
|
endif (TARGET ${deplib})
|
|
|
|
endforeach (deplib ${DEPLIBS})
|
|
|
|
# Make sure no dups exist
|
|
|
|
separate_arguments(reqlibname)
|
|
|
|
list(REMOVE_DUPLICATES reqlibname)
|
|
|
|
# Switch to comma separated Requires: field (per pkg-config docs)
|
|
|
|
string(REPLACE ";" "," reqlibname "${reqlibname}")
|
|
|
|
|
2017-02-07 17:00:29 -08:00
|
|
|
# Create the .pc file
|
2017-01-30 18:14:48 -08:00
|
|
|
upm_create_install_pkgconfig (${libname}.pc ${LIB_INSTALL_DIR}/pkgconfig)
|
|
|
|
endif (TARGET ${target})
|
2017-02-07 17:00:29 -08:00
|
|
|
endforeach (target ${ARGN})
|
|
|
|
message(STATUS "Generating pkg-config files for ${n_targets} ${LABEL} libraries... Complete")
|
2017-01-30 18:14:48 -08:00
|
|
|
endfunction (_gen_pkg_config_per_target)
|
|
|
|
|
2017-02-07 17:00:29 -08:00
|
|
|
# This function iterates over all provided target names and
|
|
|
|
# writes a pom file to each build directory
|
|
|
|
function (_gen_pom_per_target)
|
|
|
|
list(LENGTH ARGN n_targets)
|
|
|
|
message(STATUS "Generating pom files for ${n_targets} CXX libraries...")
|
|
|
|
# Iterate over the targets an build pom files
|
|
|
|
foreach (target ${ARGN})
|
|
|
|
if (TARGET ${target})
|
|
|
|
get_target_property(libname ${target} PKG_CONFIG_NAME)
|
|
|
|
get_target_property(libdescription ${target} PKG_CONFIG_DESCRIPTION)
|
|
|
|
get_target_property(reqlibname ${target} PKG_EXT_REQ_LIBS)
|
|
|
|
get_target_property(BINARY_DIR ${target} BINARY_DIR)
|
|
|
|
|
|
|
|
# Get a list of in-project dependency targets for this target
|
|
|
|
_get_dependency_targets(${target} DEPLIBS)
|
|
|
|
|
|
|
|
# Default the packaging for java
|
|
|
|
set (pom_packaging jar)
|
|
|
|
# Default the groupid for java
|
|
|
|
set (pom_base_groupId io.mraa)
|
|
|
|
if (ANDROID)
|
|
|
|
# Android overrides
|
|
|
|
set (pom_packaging aar)
|
|
|
|
set (pom_base_groupId io.mraa.at)
|
|
|
|
endif (ANDROID)
|
|
|
|
|
|
|
|
# Top-level pom groupId
|
|
|
|
set (pom_groupId ${pom_base_groupId}.upm)
|
|
|
|
|
|
|
|
# Template for a single dependency
|
|
|
|
set (pom_dep_template "
|
|
|
|
<dependency>
|
|
|
|
<groupId>\@pom_dep_groupId\@</groupId>
|
|
|
|
<artifactId>\@deplib\@</artifactId>
|
|
|
|
<version>[\@pom_version_minimum\@, \)</version>
|
|
|
|
<scope>compile</scope>
|
|
|
|
</dependency>")
|
|
|
|
|
|
|
|
# Iterate over the dependency targets, build an XML vector of dependencies
|
|
|
|
set (pom_dependencies "")
|
|
|
|
foreach (deplib ${DEPLIBS})
|
|
|
|
unset(_tmp_pom_dep)
|
|
|
|
# mraa is a special case
|
|
|
|
if (${deplib} MATCHES mraa)
|
|
|
|
set (pom_dep_groupId "${pom_base_groupId}")
|
|
|
|
set (pom_version_minimum ${MRAA_MINIMUM})
|
|
|
|
string(CONFIGURE ${pom_dep_template} _tmp_pom_dep @ONLY)
|
|
|
|
# Only match CXX target dependencies
|
|
|
|
elseif ("${UPM_TARGETS_CXX}" MATCHES ";${deplib};")
|
|
|
|
set (deplib upm_${deplib})
|
|
|
|
set (pom_dep_groupId "${pom_base_groupId}.upm")
|
|
|
|
set (pom_version_minimum ${upm_VERSION_STRING})
|
|
|
|
string(CONFIGURE ${pom_dep_template} _tmp_pom_dep @ONLY)
|
|
|
|
endif (${deplib} MATCHES mraa)
|
|
|
|
|
|
|
|
# Add this dependency to the list of pom dependencies
|
|
|
|
set (pom_dependencies "${pom_dependencies}${_tmp_pom_dep}")
|
|
|
|
endforeach (deplib ${DEPLIBS})
|
|
|
|
|
|
|
|
# Separate the dependency elements
|
|
|
|
STRING(REGEX REPLACE ";" "\\n;" pom_dependencies "${pom_dependencies}")
|
|
|
|
# Configure the pom file
|
|
|
|
configure_file (${CMAKE_SOURCE_DIR}/src/pom.xml.in
|
|
|
|
${BINARY_DIR}/upm_${target}-${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.pom)
|
|
|
|
endif (TARGET ${target})
|
|
|
|
endforeach (target ${ARGN})
|
|
|
|
message(STATUS "Generating pom files for ${n_targets} CXX libraries... Complete")
|
|
|
|
endfunction (_gen_pom_per_target)
|
|
|
|
|
|
|
|
# Print out a quick summary of the UPM targets
|
|
|
|
function (_print_target_summary)
|
|
|
|
list(LENGTH UPM_TARGETS_C N_C)
|
|
|
|
list(LENGTH UPM_TARGETS_CXX N_CXX)
|
|
|
|
list(LENGTH UPM_TARGETS_JAVA N_JAVA)
|
|
|
|
list(LENGTH UPM_TARGETS_NODEJS N_NODEJS)
|
|
|
|
list(LENGTH UPM_TARGETS_PYTHON2 N_PYTHON2)
|
|
|
|
list(LENGTH UPM_TARGETS_PYTHON3 N_PYTHON3)
|
|
|
|
|
|
|
|
message(STATUS "UPM target summary:")
|
|
|
|
message(STATUS "\tFound C libraries: ${N_C}")
|
|
|
|
message(STATUS "\tFound CXX libraries: ${N_CXX}")
|
|
|
|
message(STATUS "\tFound JAVA libraries: ${N_JAVA}")
|
|
|
|
message(STATUS "\tFound NODEJS libraries: ${N_NODEJS}")
|
|
|
|
message(STATUS "\tFound PYTHON2 libraries: ${N_PYTHON2}")
|
|
|
|
message(STATUS "\tFound PYTHON3 libraries: ${N_PYTHON3}")
|
|
|
|
endfunction (_print_target_summary)
|
|
|
|
|
2017-01-30 18:14:48 -08:00
|
|
|
function (_get_target_dependency_interface_include_dirs target varIncludeDirs)
|
|
|
|
set (${varIncludeDirs} "")
|
|
|
|
|
|
|
|
# For each LINK_LIBRARIES of target
|
|
|
|
get_property(_targets TARGET ${target} PROPERTY LINK_LIBRARIES)
|
|
|
|
foreach (_target ${_targets})
|
|
|
|
# If the target currently exists, use its include directories
|
|
|
|
if (TARGET ${_target})
|
|
|
|
get_property(_tmp_prop_val TARGET ${_target} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
|
|
|
list(APPEND ${varIncludeDirs} ${_tmp_prop_val})
|
|
|
|
# It's possible that the target does NOT exist yet, attempt to build an include directory
|
|
|
|
else ()
|
|
|
|
# Guess at a src dir name
|
|
|
|
file (TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}/src/${_target}" _dirname)
|
|
|
|
if (EXISTS ${_dirname})
|
|
|
|
list(APPEND ${varIncludeDirs} ${_dirname})
|
|
|
|
else ()
|
|
|
|
endif (EXISTS ${_dirname})
|
|
|
|
endif (TARGET ${_target})
|
|
|
|
endforeach (_target ${_targets})
|
|
|
|
set(${varIncludeDirs} "${${varIncludeDirs}}" PARENT_SCOPE)
|
|
|
|
endfunction (_get_target_dependency_interface_include_dirs target varIncludeDirs)
|
2016-03-29 10:28:22 -07:00
|
|
|
|
2016-09-29 13:46:20 -07:00
|
|
|
# Create a single swig target for python
|
|
|
|
macro(_upm_swig_python)
|
2017-01-30 18:14:48 -08:00
|
|
|
# Transitive headers don't appear to get picked up by swig_add_module call for
|
|
|
|
# wrapper generation. Get them manually and add them here.
|
|
|
|
_get_target_dependency_interface_include_dirs(${libname} DEPEND_DIRS)
|
|
|
|
|
2017-02-07 17:00:29 -08:00
|
|
|
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/..
|
2017-01-30 18:14:48 -08:00
|
|
|
${DEPEND_DIRS})
|
2016-09-29 13:46:20 -07:00
|
|
|
|
|
|
|
set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
|
|
|
set_source_files_properties (pyupm_${libname}.i PROPERTIES SWIG_FLAGS "-I${CMAKE_CURRENT_BINARY_DIR}/..")
|
2016-03-29 17:08:12 -07:00
|
|
|
|
2016-09-29 13:46:20 -07:00
|
|
|
# Set current python binary dir
|
|
|
|
set (CMAKE_CURRENT_PYTHON_BINARY_DIR
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
|
2016-08-17 17:58:21 -07:00
|
|
|
|
2016-09-29 13:46:20 -07:00
|
|
|
# Make sure swig places wrapper/.py collateral under python2/3 directory
|
2016-10-21 12:27:05 -07:00
|
|
|
# Save the original BINARY_DIR, set a new BINARY_DIR, then restore at
|
|
|
|
# the end of this macro. This works for cmake > 3 and works AROUND a bug in
|
|
|
|
# cmake < 3 (#13173,#13772,#14459).
|
|
|
|
set(CMAKE_CURRENT_BINARY_DIR_SAVED ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
set(CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_PYTHON_BINARY_DIR})
|
2016-09-29 13:46:20 -07:00
|
|
|
|
2016-10-10 14:48:42 -07:00
|
|
|
# Swig module name (example: pyupm_a110x-python2)
|
|
|
|
set (python_wrapper_name pyupm_${libname}-python${PYTHON_VERSION_MAJOR})
|
|
|
|
swig_add_module (${python_wrapper_name} python pyupm_${libname}.i)
|
|
|
|
# Get target library name (example _pyupm_a110x-python2)
|
|
|
|
set (python_wrapper_target ${SWIG_MODULE_${python_wrapper_name}_REAL_NAME})
|
2017-02-07 17:00:29 -08:00
|
|
|
add_dependencies(${python_wrapper_target} ${libname})
|
2016-10-10 14:48:42 -07:00
|
|
|
|
2017-02-06 16:15:58 -08:00
|
|
|
swig_link_libraries (${python_wrapper_name} ${PYTHON_LIBRARIES} ${libname})
|
2016-10-10 14:48:42 -07:00
|
|
|
target_include_directories (${python_wrapper_target}
|
2014-06-11 13:54:19 +01:00
|
|
|
PUBLIC
|
|
|
|
"${PYTHON_INCLUDE_PATH}"
|
2017-01-30 18:14:48 -08:00
|
|
|
"${PYTHON_INCLUDE_DIRS}"
|
|
|
|
${DEPEND_DIRS})
|
2016-09-29 13:46:20 -07:00
|
|
|
|
2016-10-13 12:18:52 -07:00
|
|
|
# Turn off flags for wrapper
|
2016-11-03 16:10:35 -07:00
|
|
|
foreach(flag ${SWIG_CXX_DISABLE_WARNINGS})
|
2016-10-13 12:18:52 -07:00
|
|
|
compiler_flag_supported(CXX is_supported ${flag})
|
|
|
|
if (is_supported)
|
|
|
|
target_compile_options(${python_wrapper_target}
|
|
|
|
PRIVATE "${flag}")
|
|
|
|
endif(is_supported)
|
2016-11-03 16:10:35 -07:00
|
|
|
endforeach(flag ${SWIG_CXX_DISABLE_WARNINGS})
|
2016-10-13 12:18:52 -07:00
|
|
|
|
2016-09-29 13:46:20 -07:00
|
|
|
# Add C++ comments to ALL python modules (requires doc build)
|
|
|
|
if (BUILDDOC)
|
|
|
|
# Python module depends on doxy2swig .i file generated from the monolithic doxygen xml file
|
2016-10-10 14:48:42 -07:00
|
|
|
add_dependencies(${python_wrapper_target} pyupm_doxy2swig )
|
2016-09-29 13:46:20 -07:00
|
|
|
|
|
|
|
# The pydoc target depends on EACH python module
|
2016-10-10 14:48:42 -07:00
|
|
|
add_dependencies(pydoc ${python_wrapper_target})
|
2016-09-29 13:46:20 -07:00
|
|
|
endif (BUILDDOC)
|
|
|
|
|
2016-10-10 14:48:42 -07:00
|
|
|
# Python collateral names will be the same for python2/3 w/different library dirs
|
|
|
|
set_target_properties (${python_wrapper_target} PROPERTIES
|
2016-09-29 13:46:20 -07:00
|
|
|
OUTPUT_NAME _pyupm_${libname}
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_PYTHON_BINARY_DIR})
|
|
|
|
|
2016-10-10 14:48:42 -07:00
|
|
|
# Install .py's to python packages directory/upm
|
2016-10-21 12:27:05 -07:00
|
|
|
install (FILES ${swig_extra_generated_files}
|
2016-10-10 14:48:42 -07:00
|
|
|
DESTINATION ${PYTHON_PACKAGES_PATH}/upm
|
2016-09-29 13:46:20 -07:00
|
|
|
COMPONENT ${libname})
|
|
|
|
|
2016-10-10 14:48:42 -07:00
|
|
|
# Install python wrapper module library
|
|
|
|
install (TARGETS ${python_wrapper_target}
|
|
|
|
DESTINATION ${PYTHON_PACKAGES_PATH}/upm)
|
2016-09-29 13:46:20 -07:00
|
|
|
|
2016-10-21 12:27:05 -07:00
|
|
|
# Restore CMAKE_CURRENT_BINARY_DIR
|
|
|
|
set(CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR_SAVED})
|
2016-09-29 13:46:20 -07:00
|
|
|
endmacro(_upm_swig_python)
|
|
|
|
|
|
|
|
# Generate both python2 and python3 modules if possible
|
|
|
|
macro(upm_swig_python)
|
2016-10-10 14:48:42 -07:00
|
|
|
# Skip if the libname is in the blacklist
|
|
|
|
if (NOT ";${PYTHONSWIG_BLACKLIST};" MATCHES ";${libname};")
|
|
|
|
# Generate python2 module if python2 libs are available
|
|
|
|
if (PYTHON2LIBS_FOUND)
|
|
|
|
set(PYTHON_INCLUDE_DIRS ${PYTHON2_INCLUDE_DIRS})
|
|
|
|
set(PYTHON_INCLUDE_PATH ${PYTHON2_INCLUDE_PATH})
|
|
|
|
set(PYTHON_LIBRARIES ${PYTHON2_LIBRARIES})
|
|
|
|
set(PYTHON_VERSION_MAJOR ${PYTHON2_VERSION_MAJOR})
|
|
|
|
set(PYTHON_VERSION_MINOR ${PYTHON2_VERSION_MINOR})
|
|
|
|
set(PYTHON_PACKAGES_PATH ${PYTHON2_PACKAGES_PATH})
|
|
|
|
_upm_swig_python()
|
2017-02-07 17:00:29 -08:00
|
|
|
|
|
|
|
# Keep track of all Python2 targets
|
|
|
|
set(UPM_TARGETS_PYTHON2 ${UPM_TARGETS_PYTHON2} ${python_wrapper_target}
|
|
|
|
CACHE INTERNAL "List of Python target names")
|
2016-10-10 14:48:42 -07:00
|
|
|
endif (PYTHON2LIBS_FOUND)
|
|
|
|
|
|
|
|
# Generate python3 module if python3 libs are available
|
|
|
|
if (PYTHON3LIBS_FOUND)
|
|
|
|
set(PYTHON_INCLUDE_DIRS ${PYTHON3_INCLUDE_DIRS})
|
|
|
|
set(PYTHON_INCLUDE_PATH ${PYTHON3_INCLUDE_PATH})
|
|
|
|
set(PYTHON_LIBRARIES ${PYTHON3_LIBRARIES})
|
|
|
|
set(PYTHON_VERSION_MAJOR ${PYTHON3_VERSION_MAJOR})
|
|
|
|
set(PYTHON_VERSION_MINOR ${PYTHON3_VERSION_MINOR})
|
|
|
|
set(PYTHON_PACKAGES_PATH ${PYTHON3_PACKAGES_PATH})
|
|
|
|
_upm_swig_python()
|
2017-02-07 17:00:29 -08:00
|
|
|
|
|
|
|
# Keep track of all Python3 targets
|
|
|
|
set(UPM_TARGETS_PYTHON3 ${UPM_TARGETS_PYTHON3} ${python_wrapper_target}
|
|
|
|
CACHE INTERNAL "List of Python target names")
|
2016-10-10 14:48:42 -07:00
|
|
|
endif (PYTHON3LIBS_FOUND)
|
|
|
|
endif (NOT ";${PYTHONSWIG_BLACKLIST};" MATCHES ";${libname};")
|
2016-08-17 17:58:21 -07:00
|
|
|
endmacro(upm_swig_python)
|
2014-06-11 13:54:19 +01:00
|
|
|
|
2016-08-17 17:58:21 -07:00
|
|
|
macro(upm_swig_node)
|
2016-10-10 14:48:42 -07:00
|
|
|
# Skip if the libname is in the blacklist
|
|
|
|
if (NOT ";${NODESWIG_BLACKLIST};" MATCHES ";${libname};")
|
2016-03-22 12:01:59 +00:00
|
|
|
# SWIG treats SWIG_FLAGS as a list and not a string so semicolon seperation is
|
|
|
|
# required. This hardcodes V8_VERSION to be <10 but I assume that's not going
|
|
|
|
# to be a problem for a little while! SWIG uses a padded SWIG_V8 version which
|
|
|
|
# we hack together from our findnode module.
|
|
|
|
set (V8_VERSION_HEX 0x0${V8_VERSION_MAJOR}${V8_VERSION_MINOR}${V8_VERSION_PATCH})
|
|
|
|
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
|
|
|
|
while (V8_VERSION_HEX_length LESS 8)
|
|
|
|
set (V8_VERSION_HEX "${V8_VERSION_HEX}0")
|
|
|
|
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
|
|
|
|
endwhile ()
|
2016-03-29 10:28:22 -07:00
|
|
|
|
2017-01-30 18:14:48 -08:00
|
|
|
# Transitive headers don't appear to get picked up by swig_add_module call for
|
|
|
|
# wrapper generation. Get them manually and add them here.
|
|
|
|
_get_target_dependency_interface_include_dirs(${libname} DEPEND_DIRS)
|
|
|
|
|
2017-02-07 17:00:29 -08:00
|
|
|
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/..
|
|
|
|
${DEPEND_DIRS})
|
2016-03-26 22:01:46 +03:00
|
|
|
|
2016-03-22 12:01:59 +00:00
|
|
|
set_property (SOURCE jsupm_${libname}.i PROPERTY SWIG_FLAGS "-node" "-DV8_VERSION=${V8_VERSION_HEX}")
|
2014-06-11 13:54:19 +01:00
|
|
|
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
2016-08-17 17:58:21 -07:00
|
|
|
swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i)
|
2017-02-07 17:00:29 -08:00
|
|
|
add_dependencies(jsupm_${libname} ${libname})
|
2017-02-06 16:15:58 -08:00
|
|
|
swig_link_libraries (jsupm_${libname} ${NODE_LIBRARIES} ${libname})
|
2014-06-11 13:54:19 +01:00
|
|
|
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
|
|
|
|
PUBLIC
|
|
|
|
"${NODE_INCLUDE_DIRS}"
|
2017-01-30 18:14:48 -08:00
|
|
|
${DEPEND_DIRS}
|
2016-03-22 12:01:59 +00:00
|
|
|
)
|
|
|
|
|
2016-10-13 12:18:52 -07:00
|
|
|
# Turn off flags for wrapper
|
2016-11-03 16:10:35 -07:00
|
|
|
foreach(flag ${SWIG_CXX_DISABLE_WARNINGS})
|
2016-10-13 12:18:52 -07:00
|
|
|
compiler_flag_supported(CXX is_supported ${flag})
|
|
|
|
if (is_supported)
|
|
|
|
target_compile_options(${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
|
|
|
|
PRIVATE "${flag}")
|
|
|
|
endif(is_supported)
|
2016-11-03 16:10:35 -07:00
|
|
|
endforeach(flag ${SWIG_CXX_DISABLE_WARNINGS})
|
2016-10-13 12:18:52 -07:00
|
|
|
|
2014-06-11 13:54:19 +01:00
|
|
|
set_target_properties (jsupm_${libname} PROPERTIES
|
2016-10-13 12:18:52 -07:00
|
|
|
COMPILE_FLAGS "-DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=${V8_VERSION_HEX}"
|
2014-06-11 13:54:19 +01:00
|
|
|
PREFIX ""
|
|
|
|
SUFFIX ".node"
|
|
|
|
)
|
2015-11-24 02:50:17 +03:00
|
|
|
if (${V8_VERSION_MAJOR} GREATER 3)
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
2015-12-10 13:57:55 -08:00
|
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
|
2016-09-05 21:57:41 -07:00
|
|
|
message(FATAL_ERROR "FATAL_ERROR: GCC 4.7 or above is required to compile jsupm_${libname} ")
|
2015-12-10 13:57:55 -08:00
|
|
|
endif()
|
2015-11-24 02:50:17 +03:00
|
|
|
endif()
|
2016-03-29 10:28:22 -07:00
|
|
|
|
2015-11-24 02:50:17 +03:00
|
|
|
endif()
|
2016-10-10 14:48:42 -07:00
|
|
|
|
2014-06-11 13:54:19 +01:00
|
|
|
createpackagejson(${libname})
|
2016-10-10 14:48:42 -07:00
|
|
|
|
2016-10-24 13:58:52 -07:00
|
|
|
if (NPM)
|
|
|
|
add_custom_command (TARGET jsupm_${libname} POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}JAVASCRIPT_wrap.cxx
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname})
|
|
|
|
endif ()
|
|
|
|
|
2016-10-10 14:48:42 -07:00
|
|
|
install (TARGETS jsupm_${libname} DESTINATION ${NODE_MODULE_INSTALL_PATH})
|
|
|
|
endif (NOT ";${NODESWIG_BLACKLIST};" MATCHES ";${libname};")
|
2017-02-07 17:00:29 -08:00
|
|
|
|
|
|
|
# Keep track of all NODE targets
|
|
|
|
set(UPM_TARGETS_NODEJS ${UPM_TARGETS_NODEJS} jsupm_${libname} CACHE INTERNAL "List of NodeJs target names")
|
2016-08-17 17:58:21 -07:00
|
|
|
endmacro(upm_swig_node)
|
2014-06-11 13:54:19 +01:00
|
|
|
|
2016-08-17 17:58:21 -07:00
|
|
|
macro(upm_swig_java)
|
2016-10-10 14:48:42 -07:00
|
|
|
# Skip if the libname is in the blacklist
|
|
|
|
if (NOT ";${JAVASWIG_BLACKLIST};" MATCHES ";${libname};")
|
2017-01-30 18:14:48 -08:00
|
|
|
# Transitive headers don't appear to get picked up by swig_add_module call for
|
|
|
|
# wrapper generation. Get them manually and add them here.
|
|
|
|
_get_target_dependency_interface_include_dirs(${libname} DEPEND_DIRS)
|
|
|
|
|
2015-08-05 19:43:31 +03:00
|
|
|
include_directories (
|
|
|
|
${JAVA_INCLUDE_PATH}
|
|
|
|
${JAVA_INCLUDE_PATH2}
|
2017-02-07 17:00:29 -08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/..
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/..
|
2017-01-30 18:14:48 -08:00
|
|
|
${DEPEND_DIRS}
|
2015-08-05 19:43:31 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
set_source_files_properties (javaupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
|
|
|
set_source_files_properties (javaupm_${libname}.i PROPERTIES SWIG_FLAGS ";-package;upm_${libname};-I${CMAKE_BINARY_DIR}/src")
|
2017-02-01 15:41:39 -08:00
|
|
|
# NOTE, ${module_src} is ONLY needed when swig'ing to JAVA. This is
|
|
|
|
# because *some* upm libraries have ifdef's for JAVA and SWIG in their
|
|
|
|
# source (cxx) which builds in different functionality. Because of this,
|
|
|
|
# the source must be added when building the JAVA wrapper.
|
|
|
|
# See issue #518
|
|
|
|
# TODO: Fix this somehow
|
|
|
|
swig_add_module (javaupm_${libname} java javaupm_${libname}.i ${module_src})
|
2017-02-07 17:00:29 -08:00
|
|
|
swig_link_libraries (javaupm_${libname} ${MRAAJAVA_LIBRARY} ${JAVA_LIBRARIES} ${libname})
|
|
|
|
add_dependencies(javaupm_${libname} ${libname})
|
2015-08-05 19:43:31 +03:00
|
|
|
target_include_directories ( ${SWIG_MODULE_javaupm_${libname}_REAL_NAME}
|
|
|
|
PUBLIC
|
|
|
|
"${JAVA_INCLUDE_DIRS}"
|
|
|
|
"${JAVA_INCLUDE_PATH}"
|
2017-01-30 18:14:48 -08:00
|
|
|
${DEPEND_DIRS}
|
2015-08-05 19:43:31 +03:00
|
|
|
)
|
|
|
|
set_target_properties (javaupm_${libname} PROPERTIES
|
2017-02-07 15:37:46 -08:00
|
|
|
COMPILE_FLAGS "-fpermissive -DJAVACALLBACK -DSWIGJAVA"
|
2015-08-12 19:07:48 +03:00
|
|
|
PREFIX "lib"
|
2015-08-05 19:43:31 +03:00
|
|
|
SUFFIX ".so"
|
|
|
|
)
|
2016-10-10 14:48:42 -07:00
|
|
|
|
2016-10-13 12:18:52 -07:00
|
|
|
# Turn off flags for wrapper
|
2016-11-03 16:10:35 -07:00
|
|
|
foreach(flag ${SWIG_CXX_DISABLE_WARNINGS})
|
2016-10-13 12:18:52 -07:00
|
|
|
compiler_flag_supported(CXX is_supported ${flag})
|
|
|
|
if (is_supported)
|
|
|
|
target_compile_options(${SWIG_MODULE_javaupm_${libname}_REAL_NAME}
|
|
|
|
PRIVATE "${flag}")
|
|
|
|
endif(is_supported)
|
2016-11-03 16:10:35 -07:00
|
|
|
endforeach(flag ${SWIG_CXX_DISABLE_WARNINGS})
|
2016-10-13 12:18:52 -07:00
|
|
|
|
2016-03-28 16:11:46 -07:00
|
|
|
install (TARGETS javaupm_${libname} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
|
2016-10-20 14:00:15 -06:00
|
|
|
# Java jar files always need to go under lib/java, regardless of
|
|
|
|
# architecture.
|
2016-10-10 14:48:42 -07:00
|
|
|
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/upm_${libname}.jar
|
2016-10-20 14:00:15 -06:00
|
|
|
DESTINATION lib/java)
|
2015-08-05 19:43:31 +03:00
|
|
|
|
2015-10-08 18:07:25 +03:00
|
|
|
if (NOT DEFINED $ENV{JAVA_HOME_NATIVE})
|
2015-11-24 02:50:17 +03:00
|
|
|
set (JAVAC $ENV{JAVA_HOME}/bin/javac)
|
|
|
|
set (JAR $ENV{JAVA_HOME}/bin/jar)
|
2015-10-08 18:07:25 +03:00
|
|
|
else ()
|
2015-11-24 02:50:17 +03:00
|
|
|
set (JAVAC $ENV{JAVA_HOME_NATIVE}/bin/javac)
|
|
|
|
set (JAR $ENV{JAVA_HOME_NATIVE}/bin/jar)
|
2015-10-08 18:07:25 +03:00
|
|
|
endif ()
|
2015-08-05 19:43:31 +03:00
|
|
|
|
|
|
|
add_custom_command (TARGET javaupm_${libname}
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND cmake -E echo "Compiling java.."
|
2015-08-17 16:36:33 +03:00
|
|
|
COMMAND cmake -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/upm_${libname}
|
2015-08-05 19:43:31 +03:00
|
|
|
COMMAND ${JAVAC} *.java -d ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
COMMAND cmake -E echo "Creating jar"
|
2015-08-17 16:36:33 +03:00
|
|
|
COMMAND ${JAR} cvf upm_${libname}.jar upm_${libname}
|
2015-08-05 19:43:31 +03:00
|
|
|
)
|
|
|
|
|
2017-02-07 17:00:29 -08:00
|
|
|
# Keep track of all JAVA targets
|
|
|
|
set(UPM_TARGETS_JAVA ${UPM_TARGETS_JAVA} javaupm_${libname} CACHE INTERNAL "List of JAVA target names")
|
2016-10-10 14:48:42 -07:00
|
|
|
endif (NOT ";${JAVASWIG_BLACKLIST};" MATCHES ";${libname};")
|
2016-08-17 17:58:21 -07:00
|
|
|
endmacro(upm_swig_java)
|
2015-08-05 19:43:31 +03:00
|
|
|
|
2014-06-11 13:54:19 +01:00
|
|
|
macro(upm_doxygen)
|
2014-08-11 11:31:32 +01:00
|
|
|
if (DOXYGEN_FOUND)
|
2014-06-11 13:54:19 +01:00
|
|
|
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
|
2016-09-29 13:46:20 -07:00
|
|
|
add_dependencies (doc ${libname})
|
2014-06-11 13:54:19 +01:00
|
|
|
endif ()
|
2016-08-17 17:58:21 -07:00
|
|
|
endmacro(upm_doxygen)
|
2014-06-11 13:54:19 +01:00
|
|
|
|
2016-10-24 13:58:52 -07:00
|
|
|
if (NPM)
|
|
|
|
add_custom_target (npmpkg)
|
|
|
|
add_custom_command (TARGET npmpkg POST_BUILD COMMAND echo "Creating NPM tarballs..."
|
|
|
|
COMMAND find . -maxdepth 2 -type d -name "jsupm_*" -print0 |
|
|
|
|
xargs -0 -I {} tar czf `basename {}`.tar.gz -C {} .
|
|
|
|
)
|
|
|
|
endif (NPM)
|
|
|
|
|
2016-09-29 13:46:20 -07:00
|
|
|
if (BUILDSWIGNODE)
|
|
|
|
if(SWIG_VERSION VERSION_LESS 3.0.5 AND NODE_VERSION_STRING VERSION_GREATER 0.12)
|
|
|
|
message(WARNING "WARNING - SWIG 3.0.5+ required for building with nodejs 0.12. Current version is ${SWIG_VERSION}")
|
|
|
|
endif()
|
|
|
|
find_path (NODE_ROOT_DIR "include/node/node.h")
|
|
|
|
set (NODE_INCLUDE_DIRS
|
|
|
|
${NODE_ROOT_DIR}/include/src
|
|
|
|
${NODE_ROOT_DIR}/include/node
|
|
|
|
${NODE_ROOT_DIR}/include/deps/v8/include
|
|
|
|
${NODE_ROOT_DIR}/include/deps/uv/include
|
|
|
|
)
|
|
|
|
macro(createpackagejson)
|
2016-10-24 13:58:52 -07:00
|
|
|
if (NPM)
|
2016-10-26 10:52:17 -07:00
|
|
|
# Dependency to generate wrappers before packing, skip modules that depend on 3rd party libs
|
|
|
|
if (NOT DEFINED reqlibname)
|
|
|
|
set (reqlibname "")
|
|
|
|
endif ()
|
|
|
|
if (reqlibname STREQUAL "" OR reqlibname MATCHES "mraa")
|
2016-10-24 13:58:52 -07:00
|
|
|
# Grab all module sources and headers, also add sources to gyp list
|
|
|
|
file (GLOB srcfiles RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/*.c"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/*.cxx"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/*.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
|
|
|
|
foreach (srcfile ${srcfiles})
|
|
|
|
file (COPY ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname})
|
2016-12-13 17:14:21 -08:00
|
|
|
if(${srcfile} MATCHES ".c$")
|
2016-12-15 16:44:36 -08:00
|
|
|
get_filename_component(csource ${srcfile} NAME_WE)
|
2016-12-13 17:14:21 -08:00
|
|
|
file (RENAME ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}/${srcfile} ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}/${csource}_c.c)
|
|
|
|
set (upm_LIB_SRCS_GYP "'${csource}_c.c',\n${upm_LIB_SRCS_GYP}")
|
|
|
|
elseif (${srcfile} MATCHES ".cxx$" OR ${srcfile} MATCHES ".cpp$")
|
2016-10-24 13:58:52 -07:00
|
|
|
set (upm_LIB_SRCS_GYP "'${srcfile}',\n${upm_LIB_SRCS_GYP}")
|
|
|
|
endif ()
|
|
|
|
endforeach ()
|
|
|
|
set (upm_LIB_SRCS_GYP "'jsupm_${libname}JAVASCRIPT_wrap.cxx',\n${upm_LIB_SRCS_GYP}")
|
|
|
|
|
|
|
|
# Create list of include directories and copy them
|
|
|
|
foreach (includedir ${UPM_COMMON_HEADER_DIRS})
|
|
|
|
file (RELATIVE_PATH rel ${CMAKE_SOURCE_DIR} ${includedir})
|
|
|
|
set (upm_LIB_INCLUDE_DIRS_GYP "'${rel}',\n${upm_LIB_INCLUDE_DIRS_GYP}")
|
|
|
|
endforeach (includedir)
|
|
|
|
file (COPY ${CMAKE_SOURCE_DIR}/include DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname})
|
|
|
|
set (upm_LIB_INCLUDE_DIRS_GYP "'.',\n${upm_LIB_INCLUDE_DIRS_GYP}")
|
|
|
|
|
2016-10-26 10:52:17 -07:00
|
|
|
# Utilities and interfaces
|
|
|
|
file (COPY ${CMAKE_SOURCE_DIR}/src/utilities DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname})
|
2017-01-30 18:14:48 -08:00
|
|
|
file (COPY ${CMAKE_SOURCE_DIR}/src/interfaces DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname})
|
2016-10-26 10:52:17 -07:00
|
|
|
set (upm_LIB_SRCS_GYP "'utilities/upm_utilities.c',\n${upm_LIB_SRCS_GYP}")
|
|
|
|
set (upm_LIB_INCLUDE_DIRS_GYP "'utilities',\n${upm_LIB_INCLUDE_DIRS_GYP}")
|
2017-01-30 18:14:48 -08:00
|
|
|
set (upm_LIB_INCLUDE_DIRS_GYP "'interfaces',\n${upm_LIB_INCLUDE_DIRS_GYP}")
|
2016-10-24 13:58:52 -07:00
|
|
|
|
2016-10-26 10:52:17 -07:00
|
|
|
# Add readme, package.json for NPM and node-gyp config file
|
2016-10-24 13:58:52 -07:00
|
|
|
configure_file (${PROJECT_SOURCE_DIR}/src/binding.gyp.in ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}/binding.gyp @ONLY)
|
2016-10-26 10:52:17 -07:00
|
|
|
configure_file (${PROJECT_SOURCE_DIR}/src/package.json.npm.in ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}/package.json @ONLY)
|
2016-10-24 13:58:52 -07:00
|
|
|
configure_file (${PROJECT_SOURCE_DIR}/doxy/README.npm.md ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}/README.md)
|
2016-10-26 10:52:17 -07:00
|
|
|
|
|
|
|
add_dependencies (npmpkg jsupm_${libname})
|
|
|
|
else ()
|
|
|
|
message ("Skipping jsupm_${libname}, needs ${reqlibname}")
|
|
|
|
endif ()
|
2016-10-24 13:58:52 -07:00
|
|
|
endif (NPM)
|
|
|
|
|
2016-10-26 10:52:17 -07:00
|
|
|
# package.json for regular install
|
2016-09-29 13:46:20 -07:00
|
|
|
configure_file (${PROJECT_SOURCE_DIR}/src/package.json.in ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY)
|
2016-10-24 13:58:52 -07:00
|
|
|
|
2016-09-29 13:46:20 -07:00
|
|
|
# If a CMAKE_INSTALL_PREFIX has NOT been provided, set NODE_MODULE_INSTALL_PATH
|
|
|
|
# base on the NODE_ROOT_DIR.
|
|
|
|
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
|
|
|
set (NODE_MODULE_INSTALL_PATH ${NODE_ROOT_DIR}/lib/node_modules/jsupm_${libname}/)
|
|
|
|
# If a CMAKE_INSTALL_PREFIX has been provided, set NODE_MODULE_INSTALL_PATH
|
|
|
|
# relative to the provided install directory.
|
|
|
|
else ()
|
|
|
|
set (NODE_MODULE_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/lib/node_modules/jsupm_${libname}/)
|
|
|
|
endif ()
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json
|
|
|
|
DESTINATION ${NODE_MODULE_INSTALL_PATH} COMPONENT ${libname})
|
|
|
|
endmacro(createpackagejson)
|
|
|
|
endif(BUILDSWIGNODE)
|
2014-06-11 13:54:19 +01:00
|
|
|
|
2016-08-17 17:58:21 -07:00
|
|
|
# Process C/C++ sensor modules
|
|
|
|
# This function pre-processes sensor library input and hands off the
|
|
|
|
# necessary global variables to upm_module_init for library creation,
|
|
|
|
# documenation, swigging, etc...
|
|
|
|
function (UPM_MIXED_MODULE_INIT)
|
|
|
|
# CPP_WRAPS_C -> Set to have CPP library link to C library
|
|
|
|
# DESCRIPTION -> Library description string
|
|
|
|
# CPP_HDR -> List of CPP header files
|
|
|
|
# CPP_SRC -> List of CPP source files
|
|
|
|
# C_HDR -> List of C header files
|
|
|
|
# C_SRC -> List of C source files
|
|
|
|
# FTI_SRC -> List of C FTI source files
|
|
|
|
# REQUIRES -> List requires libraries for pkg-config
|
2017-01-27 15:06:44 -08:00
|
|
|
# Exports to PARENT scope:
|
|
|
|
# libname -> CXX target name
|
|
|
|
# libnamec -> C target name (if used)
|
2016-08-17 17:58:21 -07:00
|
|
|
set (options CPP_WRAPS_C)
|
|
|
|
set (oneValueArgs NAME DESCRIPTION)
|
|
|
|
set (multiValueArgs CPP_HDR CPP_SRC C_HDR C_SRC FTI_SRC FTI_HDR REQUIRES)
|
|
|
|
# Parse function parameters
|
|
|
|
cmake_parse_arguments(UPM_MIXED_MODULE_INIT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
|
|
|
|
|
|
|
|
# Set the description
|
|
|
|
set (libdescription ${UPM_MIXED_MODULE_INIT_DESCRIPTION})
|
|
|
|
|
2017-01-30 18:14:48 -08:00
|
|
|
# Make sure REQUIRES is a list
|
|
|
|
separate_arguments(UPM_MIXED_MODULE_INIT_REQUIRES)
|
|
|
|
|
2016-08-17 17:58:21 -07:00
|
|
|
# Always build C libs first
|
|
|
|
if (UPM_MIXED_MODULE_INIT_C_SRC)
|
|
|
|
set (libname ${UPM_MIXED_MODULE_INIT_NAME})
|
|
|
|
# Set the src and hpp variables for upm_module_init
|
|
|
|
set (module_src ${UPM_MIXED_MODULE_INIT_C_SRC})
|
|
|
|
set (module_hpp ${UPM_MIXED_MODULE_INIT_C_HDR})
|
|
|
|
|
|
|
|
# If building FTI, and FTI src exists, add it in
|
|
|
|
if (BUILDFTI AND UPM_MIXED_MODULE_INIT_FTI_SRC)
|
|
|
|
#set (module_src ${UPM_MIXED_MODULE_INIT_C_SRC} ${UPM_MIXED_MODULE_INIT_FTI_SRC})
|
|
|
|
list (APPEND module_src ${UPM_MIXED_MODULE_INIT_FTI_SRC})
|
|
|
|
endif (BUILDFTI AND UPM_MIXED_MODULE_INIT_FTI_SRC)
|
|
|
|
|
|
|
|
# Set a flag to tell upm_module_init that it's building a C library
|
|
|
|
set (IS_C_LIBRARY TRUE)
|
2017-01-30 18:14:48 -08:00
|
|
|
upm_module_init(${UPM_MIXED_MODULE_INIT_REQUIRES})
|
2016-08-24 15:40:30 -06:00
|
|
|
|
2017-02-07 17:00:29 -08:00
|
|
|
# If a c target has a dependency on utilities-c, then swap the corresponding
|
|
|
|
# C++ target's dependency on utilities-c to utilities. This solves a niche
|
|
|
|
# problem for Android Things (C++ which depends on C which depends on
|
|
|
|
# utilities-c is not getting the utilities-c library). Since only C++
|
|
|
|
# packages get swig'ed to Java, the only way to get the utilities-c library
|
|
|
|
# is to packages with a utilites C++ library and add a dependency.
|
|
|
|
# TODO: Find a better way to do this.
|
|
|
|
if ("${UPM_MIXED_MODULE_INIT_REQUIRES}" MATCHES utilities-c)
|
|
|
|
list (REMOVE_ITEM UPM_MIXED_MODULE_INIT_REQUIRES utilities-c)
|
|
|
|
list (APPEND UPM_MIXED_MODULE_INIT_REQUIRES utilities)
|
|
|
|
endif ()
|
2016-09-13 11:18:17 -06:00
|
|
|
|
|
|
|
## "export" the logical C lib target for the calling module's
|
|
|
|
## CMakeLists.txt
|
|
|
|
set (libnamec ${libname} PARENT_SCOPE)
|
|
|
|
|
2016-08-29 17:39:41 -06:00
|
|
|
endif (UPM_MIXED_MODULE_INIT_C_SRC)
|
2016-08-17 17:58:21 -07:00
|
|
|
|
|
|
|
# Build C++ if enabled AND C++ headers exist
|
|
|
|
if (BUILDCPP AND UPM_MIXED_MODULE_INIT_CPP_HDR)
|
|
|
|
# Set the src and hpp variables for upm_module_init
|
|
|
|
set (module_src ${UPM_MIXED_MODULE_INIT_CPP_SRC})
|
|
|
|
set (module_hpp ${UPM_MIXED_MODULE_INIT_CPP_HDR})
|
|
|
|
|
|
|
|
# Reset the libname (upm_module_init can change it)
|
|
|
|
set (libname ${UPM_MIXED_MODULE_INIT_NAME})
|
|
|
|
unset (IS_C_LIBRARY)
|
2017-01-30 18:14:48 -08:00
|
|
|
upm_module_init(${UPM_MIXED_MODULE_INIT_REQUIRES})
|
2016-08-17 17:58:21 -07:00
|
|
|
|
|
|
|
# If the C++ wraps the C target, add the C target as a dependency
|
|
|
|
if (UPM_MIXED_MODULE_INIT_CPP_WRAPS_C)
|
|
|
|
target_link_libraries(${libname} ${libname}-c)
|
|
|
|
endif (UPM_MIXED_MODULE_INIT_CPP_WRAPS_C)
|
2016-09-13 11:18:17 -06:00
|
|
|
|
|
|
|
## "export" the logical C++ lib target for the calling module's
|
|
|
|
## CMakeLists.txt
|
2017-01-27 15:06:44 -08:00
|
|
|
set (libname ${libname} PARENT_SCOPE)
|
2016-09-13 11:18:17 -06:00
|
|
|
|
2016-08-17 17:58:21 -07:00
|
|
|
endif (BUILDCPP AND UPM_MIXED_MODULE_INIT_CPP_HDR)
|
2016-09-13 11:18:17 -06:00
|
|
|
|
2016-08-17 17:58:21 -07:00
|
|
|
endfunction (UPM_MIXED_MODULE_INIT)
|
|
|
|
|
2017-01-27 15:06:44 -08:00
|
|
|
function(upm_module_init)
|
2016-08-17 17:58:21 -07:00
|
|
|
set (basename ${libname})
|
|
|
|
|
|
|
|
# If this is a C library, handle different collateral naming
|
|
|
|
if (IS_C_LIBRARY)
|
|
|
|
set (libname ${libname}-c)
|
2017-01-27 15:06:44 -08:00
|
|
|
# If this is a C library, export C library target name to parent's libname
|
|
|
|
set (libname ${libname} PARENT_SCOPE)
|
2016-08-17 17:58:21 -07:00
|
|
|
set (libprefix upmc-)
|
2017-02-07 17:00:29 -08:00
|
|
|
# Keep track of all C targets
|
|
|
|
set(UPM_TARGETS_C ${UPM_TARGETS_C} ${libname} CACHE INTERNAL "List of C target names")
|
2016-08-17 17:58:21 -07:00
|
|
|
else ()
|
2017-02-07 17:00:29 -08:00
|
|
|
# Keep track of all CXX targets
|
|
|
|
set(UPM_TARGETS_CXX ${UPM_TARGETS_CXX} ${libname} CACHE INTERNAL "List of CXX target names")
|
2016-08-17 17:58:21 -07:00
|
|
|
set (libprefix upm-)
|
|
|
|
endif (IS_C_LIBRARY)
|
|
|
|
|
2017-01-30 18:14:48 -08:00
|
|
|
# Create the target library from src/hdrs
|
2016-09-09 14:10:30 -07:00
|
|
|
add_library (${libname} SHARED ${module_src} ${module_hpp})
|
2017-01-30 18:14:48 -08:00
|
|
|
|
|
|
|
# Specify the current source directory as an INTERFACE include dir.
|
|
|
|
# This allows for transitive header dependencies via target_link_libraries
|
|
|
|
target_include_directories(${libname} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
|
2017-02-07 17:00:29 -08:00
|
|
|
# Also add common header directories to this target
|
|
|
|
target_include_directories (${libname} PUBLIC ${UPM_COMMON_HEADER_DIRS})
|
|
|
|
|
2017-01-30 18:14:48 -08:00
|
|
|
# Iterate over all arguments passed to upm_module_init.
|
|
|
|
# 1. Add them via target_link_libraries
|
2017-02-06 16:15:58 -08:00
|
|
|
# 2. If mraa, then add a link and include dependency
|
2015-01-17 10:09:06 +00:00
|
|
|
foreach (linkflag ${ARGN})
|
2017-02-06 16:15:58 -08:00
|
|
|
# Add necessary MRAA components IF the target requires it
|
|
|
|
if (${linkflag} MATCHES mraa)
|
|
|
|
target_link_libraries (${libname} ${MRAA_LIBRARY})
|
|
|
|
# Always add a PUBLIC dependency to MRAA include dirs
|
|
|
|
target_include_directories (${libname} PUBLIC ${MRAA_INCLUDE_DIRS})
|
|
|
|
else ()
|
|
|
|
# Else, add the linkflag directly
|
|
|
|
target_link_libraries (${libname} ${linkflag})
|
|
|
|
endif (${linkflag} MATCHES mraa)
|
2015-01-17 10:09:06 +00:00
|
|
|
endforeach ()
|
2017-01-30 18:14:48 -08:00
|
|
|
|
2014-06-17 11:41:05 +01:00
|
|
|
set_target_properties(
|
|
|
|
${libname}
|
2016-08-17 17:58:21 -07:00
|
|
|
PROPERTIES PREFIX lib${libprefix}
|
|
|
|
OUTPUT_NAME ${basename}
|
2014-06-17 11:41:05 +01:00
|
|
|
SOVERSION ${upm_VERSION_MAJOR}
|
|
|
|
VERSION ${upm_VERSION_STRING}
|
|
|
|
)
|
2016-08-17 17:58:21 -07:00
|
|
|
|
|
|
|
# Don't SWIG C
|
2016-10-10 14:48:42 -07:00
|
|
|
if (NOT IS_C_LIBRARY)
|
|
|
|
if (BUILDSWIGPYTHON)
|
2016-01-13 13:38:23 +02:00
|
|
|
upm_swig_python()
|
2016-10-10 14:48:42 -07:00
|
|
|
endif (BUILDSWIGPYTHON)
|
|
|
|
if (BUILDSWIGNODE)
|
2016-01-13 13:38:23 +02:00
|
|
|
upm_swig_node()
|
2016-10-10 14:48:42 -07:00
|
|
|
endif (BUILDSWIGNODE)
|
|
|
|
if (BUILDSWIGJAVA)
|
2016-01-13 13:38:23 +02:00
|
|
|
upm_swig_java()
|
2016-10-10 14:48:42 -07:00
|
|
|
endif (BUILDSWIGJAVA)
|
|
|
|
endif (NOT IS_C_LIBRARY)
|
2016-08-17 17:58:21 -07:00
|
|
|
|
2017-02-07 17:00:29 -08:00
|
|
|
# Add additional properties to this target (used later for .pc file creation)
|
2017-01-30 18:14:48 -08:00
|
|
|
set_target_properties(${libname} PROPERTIES PKG_CONFIG_NAME "${libprefix}${basename}")
|
|
|
|
set_target_properties(${libname} PROPERTIES PKG_CONFIG_DESCRIPTION "${libdescription}")
|
|
|
|
set_target_properties(${libname} PROPERTIES PKG_EXT_REQ_LIBS "${reqlibname}")
|
|
|
|
|
2016-08-17 17:58:21 -07:00
|
|
|
# Skip doxygen run on C (for now)
|
|
|
|
if (BUILDDOC AND NOT IS_C_LIBRARY)
|
2014-06-11 13:54:19 +01:00
|
|
|
upm_doxygen()
|
|
|
|
endif()
|
2016-08-17 17:58:21 -07:00
|
|
|
|
2017-01-30 18:14:48 -08:00
|
|
|
# Install target library to lib dir
|
2016-08-17 17:58:21 -07:00
|
|
|
install (TARGETS ${libname} DESTINATION ${LIB_INSTALL_DIR})
|
2017-01-30 18:14:48 -08:00
|
|
|
|
|
|
|
# Install header files to include/upm/
|
2016-04-25 14:27:51 -07:00
|
|
|
install (FILES ${module_hpp} DESTINATION include/upm COMPONENT ${libname})
|
2014-06-11 13:54:19 +01:00
|
|
|
|
|
|
|
if (IPK)
|
|
|
|
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
|
|
|
set(CPACK_COMPONENT_${libname}_DESCRIPTION "${libdescription}")
|
|
|
|
endif()
|
2017-01-27 15:06:44 -08:00
|
|
|
endfunction(upm_module_init)
|
2016-10-10 14:48:42 -07:00
|
|
|
|
|
|
|
# Top-level module init
|
|
|
|
if (BUILDSWIGPYTHON)
|
|
|
|
file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/__init__.py "# UPM python modules")
|
|
|
|
if(PYTHON2LIBS_FOUND)
|
|
|
|
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/__init__.py
|
|
|
|
DESTINATION ${PYTHON2_PACKAGES_PATH}/upm
|
|
|
|
COMPONENT python2)
|
|
|
|
endif(PYTHON2LIBS_FOUND)
|
|
|
|
if(PYTHON3LIBS_FOUND)
|
|
|
|
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/__init__.py
|
|
|
|
DESTINATION ${PYTHON3_PACKAGES_PATH}/upm
|
|
|
|
COMPONENT python3)
|
|
|
|
endif(PYTHON3LIBS_FOUND)
|
|
|
|
endif (BUILDSWIGPYTHON)
|
2014-06-11 13:54:19 +01:00
|
|
|
|
2015-12-16 13:58:11 -08:00
|
|
|
# Generate python module documentation from doxygen collateral
|
2016-09-29 13:46:20 -07:00
|
|
|
if (BUILDDOC AND BUILDSWIGPYTHON)
|
2015-12-16 13:58:11 -08:00
|
|
|
# doxy2swig the doxygen output
|
2016-09-29 13:46:20 -07:00
|
|
|
add_custom_target (pyupm_doxy2swig ALL
|
2016-10-05 17:08:42 -07:00
|
|
|
COMMAND ${PYTHON2_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py
|
2015-12-16 13:58:11 -08:00
|
|
|
${CMAKE_BINARY_DIR}/xml/index.xml
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/pyupm_doxy2swig.i
|
2016-09-29 13:46:20 -07:00
|
|
|
DEPENDS doc)
|
2015-12-16 13:58:11 -08:00
|
|
|
# BUILDDOC not set but still building python modules, generate an empty
|
|
|
|
# pyupm_doxy2swig.i file (overwriting if necessary)
|
2016-09-29 13:46:20 -07:00
|
|
|
elseif (BUILDSWIGPYTHON)
|
2016-09-29 18:24:19 -07:00
|
|
|
message (STATUS "BUILDDOC=${BUILDDOC}, python modules will not contain cxx documentation")
|
2015-12-16 13:58:11 -08:00
|
|
|
file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/pyupm_doxy2swig.i "// Empty doxy2swig stub")
|
2016-09-29 13:46:20 -07:00
|
|
|
endif (BUILDDOC AND BUILDSWIGPYTHON)
|
2015-12-16 13:58:11 -08:00
|
|
|
|
2017-02-07 17:00:29 -08:00
|
|
|
# Provide a cached variable to groups of targets
|
|
|
|
set(UPM_TARGETS_C "" CACHE INTERNAL "List of C target names")
|
|
|
|
set(UPM_TARGETS_CXX "" CACHE INTERNAL "List of CXX target names")
|
|
|
|
set(UPM_TARGETS_JAVA "" CACHE INTERNAL "List of JAVA target names")
|
|
|
|
set(UPM_TARGETS_NODEJS "" CACHE INTERNAL "List of NodeJs target names")
|
|
|
|
set(UPM_TARGETS_PYTHON2 "" CACHE INTERNAL "List of Python2 target names")
|
|
|
|
set(UPM_TARGETS_PYTHON3 "" CACHE INTERNAL "List of Python3 target names")
|
2017-01-30 18:14:48 -08:00
|
|
|
|
2016-11-08 18:11:28 -08:00
|
|
|
# Add subdirectories from MODULE_LIST if defined
|
|
|
|
# Example -DMODULE_LIST="dfrph;rotaryencoder"
|
2015-11-19 15:49:18 -08:00
|
|
|
if (MODULE_LIST)
|
|
|
|
set(SUBDIRS ${MODULE_LIST})
|
2017-01-30 18:14:48 -08:00
|
|
|
# Add interfaces directory
|
|
|
|
set(SUBDIRS ${SUBDIRS} interfaces)
|
2015-11-19 15:49:18 -08:00
|
|
|
else()
|
2016-11-08 18:11:28 -08:00
|
|
|
# Otherwise, add all subdirectories
|
2015-11-19 15:49:18 -08:00
|
|
|
subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
endif()
|
2016-11-08 18:11:28 -08:00
|
|
|
|
|
|
|
# If the SUBDIRS list does NOT include the utilities directory, add it since
|
|
|
|
# most sensor library targets depend on utilities
|
|
|
|
if (NOT "${SUBDIRS}" MATCHES utilities)
|
|
|
|
add_subdirectory(${CMAKE_SOURCE_DIR}/src/utilities)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Iterate over each directory in SUBDIRS
|
2014-06-05 13:58:34 +01:00
|
|
|
foreach(subdir ${SUBDIRS})
|
2015-01-15 18:24:52 +01:00
|
|
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/CMakeLists.txt)
|
|
|
|
add_subdirectory(${subdir})
|
|
|
|
endif()
|
2014-06-05 13:58:34 +01:00
|
|
|
endforeach()
|
2017-01-30 18:14:48 -08:00
|
|
|
|
2017-02-07 17:00:29 -08:00
|
|
|
# Print stats for all targets
|
|
|
|
_print_target_summary()
|
|
|
|
|
2017-01-30 18:14:48 -08:00
|
|
|
# Generate a pkg-config file (.pc) per target
|
2017-02-07 17:00:29 -08:00
|
|
|
_gen_pkg_config_per_target(C ${UPM_TARGETS_C})
|
|
|
|
_gen_pkg_config_per_target(CXX ${UPM_TARGETS_CXX})
|
|
|
|
|
|
|
|
# Generate a pom file per CXX target
|
|
|
|
if (BUILDSWIGJAVA)
|
|
|
|
_gen_pom_per_target(${UPM_TARGETS_CXX})
|
|
|
|
endif (BUILDSWIGJAVA)
|