-endif(kernel_minimal_version)
-
-macro(defstr name value)
- add_definitions(-D${name}=${value})
-endmacro(defstr)
-
-# Pre-packaging
-macro(project_targets_populate)
-
- # Default Widget default directory
- set(PACKAGE_BINDIR ${PROJECT_PKG_BUILD_DIR}/bin)
- set(PACKAGE_ETCDIR ${PROJECT_PKG_BUILD_DIR}/etc)
- set(PACKAGE_LIBDIR ${PROJECT_PKG_BUILD_DIR}/lib)
- set(PACKAGE_HTTPDIR ${PROJECT_PKG_BUILD_DIR}/htdocs)
- set(PACKAGE_DATADIR ${PROJECT_PKG_BUILD_DIR}/data)
-
- add_custom_target(populate)
- get_property(PROJECT_TARGETS GLOBAL PROPERTY PROJECT_TARGETS)
- foreach(TARGET ${PROJECT_TARGETS})
- get_target_property(T ${TARGET} LABELS)
- if(T)
- # Declaration of a custom command that will populate widget tree with the target
- set(POPULE_PACKAGE_TARGET "project_populate_${TARGET}")
-
- get_target_property(P ${TARGET} PREFIX)
- get_target_property(BD ${TARGET} BINARY_DIR)
- get_target_property(OUT ${TARGET} OUTPUT_NAME)
-
- if(P MATCHES "NOTFOUND$")
- if (${T} STREQUAL "BINDING")
- set(P "lib")
- else()
- set(P "")
- endif()
- endif()
-
- if(${T} STREQUAL "BINDING")
- add_custom_command(OUTPUT ${PACKAGE_LIBDIR}/${P}${TARGET}.so
- DEPENDS ${TARGET}
- COMMAND mkdir -p ${PACKAGE_LIBDIR}
- COMMAND cp ${BD}/${P}${OUT}.so ${PACKAGE_LIBDIR}
- )
- add_custom_target(${POPULE_PACKAGE_TARGET} DEPENDS ${PACKAGE_LIBDIR}/${P}${TARGET}.so)
- add_dependencies(populate ${POPULE_PACKAGE_TARGET})
- elseif(${T} STREQUAL "EXECUTABLE")
- add_custom_command(OUTPUT ${PACKAGE_BINDIR}/${P}${TARGET}
- DEPENDS ${TARGET}
- COMMAND mkdir -p ${PACKAGE_BINDIR}
- COMMAND cp ${BD}/${P}${OUT} ${PACKAGE_BINDIR}
- )
- add_custom_target(${POPULE_PACKAGE_TARGET} DEPENDS ${PACKAGE_BINDIR}/${P}${TARGET})
- add_dependencies(populate ${POPULE_PACKAGE_TARGET})
- elseif(${T} STREQUAL "HTDOCS")
- add_custom_command(OUTPUT ${PACKAGE_HTTPDIR}
- DEPENDS ${TARGET}
- COMMAND mkdir -p ${PACKAGE_HTTPDIR}
- COMMAND cp -r ${BD}/${P}${OUT}/* ${PACKAGE_HTTPDIR}
- )
- add_custom_target(${POPULE_PACKAGE_TARGET} DEPENDS ${PACKAGE_HTTPDIR})
- add_dependencies(populate ${POPULE_PACKAGE_TARGET})
- elseif(${T} STREQUAL "DATA")
- add_custom_command(OUTPUT ${PACKAGE_DATADIR}
- DEPENDS ${TARGET}
- COMMAND mkdir -p ${PACKAGE_DATADIR}
- COMMAND cp -r ${BD}/${P}${OUT} ${PACKAGE_DATADIR}
- )
- add_custom_target(${POPULE_PACKAGE_TARGET} DEPENDS ${PACKAGE_DATADIR})
- add_dependencies(populate ${POPULE_PACKAGE_TARGET})
- endif(${T} STREQUAL "BINDING")
- elseif(${CMAKE_BUILD_TYPE} MATCHES "[Dd][Ee][Bb][Uu][Gg]")
- MESSAGE(".. Warning: ${TARGET} ignored when packaging.")
- endif()
- endforeach()
-endmacro(project_targets_populate)
-
-macro(remote_targets_populate)
- if (DEFINED ENV{RSYNC_TARGET})
- set (RSYNC_TARGET $ENV{RSYNC_TARGET})
- endif()
- if (DEFINED ENV{RSYNC_PREFIX})
- set (RSYNC_PREFIX $ENV{RSYNC_PREFIX})
- endif()
-
- set(
- REMOTE_LAUNCH "Test on target with: ${CMAKE_CURRENT_BINARY_DIR}/target/start-on-${RSYNC_TARGET}.sh"
- CACHE STRING "Command to start ${PROJECT_NAME} on remote target ${RSYNC_TARGET}"
- )
-
- if(NOT RSYNC_TARGET OR NOT RSYNC_PREFIX)
- message ("${Yellow}.. Warning: RSYNC_TARGET RSYNC_PREFIX not defined 'make remote-target-populate' not instanciated${ColourReset}")
- add_custom_target(remote-target-populate
- COMMENT "${Red}*** Fatal: RSYNC_TARGET RSYNC_PREFIX environment variables required with 'make remote-target-populate'${ColourReset}"
- COMMAND exit -1
- )
- else()
-
- configure_file(${SSH_TEMPLATE_DIR}/start-on-target.in ${CMAKE_CURRENT_BINARY_DIR}/target/start-on-${RSYNC_TARGET}.sh)
- configure_file(${GDB_TEMPLATE_DIR}/gdb-on-target.in ${CMAKE_CURRENT_BINARY_DIR}/target/gdb-on-${RSYNC_TARGET}.ini)
-
- add_custom_target(remote-target-populate
- DEPENDS populate
- COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/target/start-on-${RSYNC_TARGET}.sh
- COMMAND rsync --archive --delete ${PROJECT_PKG_BUILD_DIR}/ ${RSYNC_TARGET}:${RSYNC_PREFIX}/${PROJECT_NAME}
- COMMENT "${REMOTE_LAUNCH}"
- )
- endif()
-endmacro(remote_targets_populate)
-
-macro(wgt_package_build)
- # Build widget spec file from template only once (Fulup good idea or should depend on time ????)
- if(NOT EXISTS ${TEMPLATE_WGT_DIR}/config.xml.in OR NOT EXISTS ${TEMPLATE_WGT_DIR}/${PROJECT_ICON})
- configure_file(${TEMPLATE_WGT_DIR}/config.xml.in ${PROJECT_PKG_BUILD_DIR}/config.xml)
- configure_file(${TEMPLATE_WGT_DIR}/config.xml.in ${PROJECT_PKG_ENTRY_POINT}/config.xml)
- file(COPY ${TEMPLATE_WGT_DIR}/icon-default.png DESTINATION ${PROJECT_PKG_BUILD_DIR}/${PROJECT_ICON})
- endif(NOT EXISTS ${TEMPLATE_WGT_DIR}/config.xml.in OR NOT EXISTS ${TEMPLATE_WGT_DIR}/${PROJECT_ICON})
- if(NOT EXISTS ${WGT_TEMPLATE_DIR}/config.xml.in OR NOT EXISTS ${WGT_TEMPLATE_DIR}/icon-default.png)
- MESSAGE(FATAL_ERROR "${Red}WARNING ! Missing mandatory files to build widget file.\nYou need config.xml.in and ${PROJECT_ICON} files in ${WGT_TEMPLATE_DIR} folder.${ColourReset}")
- endif()
-
- configure_file(${WGT_TEMPLATE_DIR}/config.xml.in ${PROJECT_PKG_BUILD_DIR}/config.xml)
- configure_file(${WGT_TEMPLATE_DIR}/config.xml.in ${PROJECT_PKG_ENTRY_POINT}/config.xml)
- file(COPY ${WGT_TEMPLATE_DIR}/icon-default.png DESTINATION ${PROJECT_PKG_BUILD_DIR}/${PROJECT_ICON})
-
- # Fulup ??? copy any extra file in wgt/etc into populate package before building the widget
- file(GLOB PROJECT_CONF_FILES "${WGT_TEMPLATE_DIR}/etc/*")
- if(${PROJECT_CONF_FILES})
- file(COPY "${WGT_TEMPLATE_DIR}/etc/*" DESTINATION ${PROJECT_PKG_BUILD_DIR}/etc/)
- endif(${PROJECT_CONF_FILES})
-
- add_custom_command(OUTPUT ${PROJECT_NAME}.wgt
- DEPENDS ${PROJECT_TARGETS}
- COMMAND wgtpkg-pack -f -o ${PROJECT_NAME}.wgt ${PROJECT_PKG_BUILD_DIR}
- )
-
- add_custom_target(widget DEPENDS ${PROJECT_NAME}.wgt)
- add_dependencies(widget populate)
- set(ADDITIONAL_MAKE_CLEAN_FILES, "${PROJECT_NAME}.wgt")
-
- if(PACKAGE_MESSAGE)
- add_custom_command(TARGET widget
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan "++ ${PACKAGE_MESSAGE}")
- endif()
-endmacro(wgt_package_build)
-
-macro(rpm_package_build)
- if(NOT EXISTS ${RPM_TEMPLATE_DIR}/rpm-config.spec.in)
- MESSAGE(FATAL_ERROR "${Red}Missing mandatory files: you need rpm-config.spec.in in ${RPM_TEMPLATE_DIR} folder.${ColourReset}")
- endif()
-
- # extract PROJECT_PKG_DEPS and replace ; by , for RPM spec file
- get_property(PROJECT_PKG_DEPS GLOBAL PROPERTY PROJECT_PKG_DEPS)
- foreach (PKFCONF ${PROJECT_PKG_DEPS})
- set(RPM_PKG_DEPS "${RPM_PKG_DEPS}, pkgconfig(${PKFCONF})")
- endforeach()
-
- # build rpm spec file from template
- configure_file(${RPM_TEMPLATE_DIR}/rpm-config.spec.in ${PROJECT_PKG_BUILD_DIR}/${PROJECT_NAME}.spec)
- configure_file(${RPM_TEMPLATE_DIR}/rpm-config.spec.in ${PROJECT_PKG_ENTRY_POINT}/${PROJECT_NAME}.spec)