CELIX-451: Adds celix_bundle_dir for copying files. Also remove mongoose example and adds a new civetweb example.
- The celix_bundle_dir also copy files again if they are updated - The mongoose example was removed, because the updated version of mongoose is now GPL - The civetweb example also uses a websocket Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/c4de9077 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/c4de9077 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/c4de9077 Branch: refs/heads/develop Commit: c4de9077dce47e13f4a084aa493f3e05a94b8408 Parents: 3f24edf Author: Pepijn Noltes <[email protected]> Authored: Tue Jul 3 22:43:27 2018 +0200 Committer: Pepijn Noltes <[email protected]> Committed: Tue Jul 3 22:43:27 2018 +0200 ---------------------------------------------------------------------- cmake/cmake_celix/BundlePackaging.cmake | 67 +- examples/celix-examples/CMakeLists.txt | 2 +- examples/celix-examples/civetweb/CMakeLists.txt | 37 + .../celix-examples/civetweb/civetweb/civetweb.c | 19792 +++++++++++++++++ .../celix-examples/civetweb/civetweb/civetweb.h | 1498 ++ .../civetweb/civetweb/handle_form.inl | 981 + .../celix-examples/civetweb/civetweb/md5.inl | 471 + .../celix-examples/civetweb/civetweb/sha1.inl | 323 + .../celix-examples/civetweb/civetweb/timer.inl | 246 + .../civetweb/resources/index.html | 34 + .../celix-examples/civetweb/resources/script.js | 43 + .../civetweb/src/bundle_activator.c | 108 + examples/celix-examples/mongoose/CMakeLists.txt | 42 - .../mongoose/private/include/mongoose.h | 218 - .../mongoose/private/src/activator.c | 79 - .../mongoose/private/src/mongoose.c | 4076 ---- .../celix-examples/mongoose/root/index.html | 23 - 17 files changed, 23595 insertions(+), 4445 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/c4de9077/cmake/cmake_celix/BundlePackaging.cmake ---------------------------------------------------------------------- diff --git a/cmake/cmake_celix/BundlePackaging.cmake b/cmake/cmake_celix/BundlePackaging.cmake index 6666d20..35f5c0a 100644 --- a/cmake/cmake_celix/BundlePackaging.cmake +++ b/cmake/cmake_celix/BundlePackaging.cmake @@ -340,15 +340,26 @@ function(celix_bundle_libs) endif() list(APPEND DEPS ${OUT}) elseif (TARGET ${LIB}) + get_target_property(TARGET_TYPE ${LIB} TYPE) #Assuming target #NOTE add_custom_command does not support generator expression in OUTPUT value (e.g. $<TARGET_FILE:${LIB}>) #Using a two step approach to be able to use add_custom_command instead of add_custom_target set(OUT "${BUNDLE_GEN_DIR}/lib-${LIBID}-copy-timestamp") - add_custom_command(OUTPUT ${OUT} - COMMAND ${CMAKE_COMMAND} -E touch ${OUT} - COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:${LIB}>" "${BUNDLE_DIR}/$<TARGET_SONAME_FILE_NAME:${LIB}>" - DEPENDS ${LIB} - ) + if ("${TARGET_TYPE}" STREQUAL "STATIC_LIBRARY") + add_custom_command(OUTPUT ${OUT} + COMMAND ${CMAKE_COMMAND} -E touch ${OUT} + COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:${LIB}>" "${BUNDLE_DIR}/$<TARGET_FILE_NAME:${LIB}>" + DEPENDS ${LIB} + ) + elseif ("${TARGET_TYPE}" STREQUAL "SHARED_LIBRARY") + add_custom_command(OUTPUT ${OUT} + COMMAND ${CMAKE_COMMAND} -E touch ${OUT} + COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:${LIB}>" "${BUNDLE_DIR}/$<TARGET_SONAME_FILE_NAME:${LIB}>" + DEPENDS ${LIB} + ) + else() + message(FATAL_ERROR "Unexptected target type (${TARGET_TYPE}) for target ${LIB}. Not a library") + endif() if (ADD_TO_MANIFEST) list(APPEND LIBS "$<TARGET_SONAME_FILE_NAME:${LIB}>") endif() @@ -404,9 +415,9 @@ function(bundle_files) message(DEPRECATION "bundle_files is deprecated, use celix_bundle_files instead.") celix_bundle_files(${ARGN}) endfunction() +#Note with celix_bundle_files, files are copied cmake generation time. Updates are not copied !! function(celix_bundle_files) #0 is bundle TARGET - #1..n is header name / header value list(GET ARGN 0 BUNDLE) list(REMOVE_AT ARGN 0) @@ -427,6 +438,50 @@ function(celix_bundle_files) file(COPY ${FILES_UNPARSED_ARGUMENTS} DESTINATION ${DESTINATION}) endfunction() +#Note celix_bundle_dir copies the dir and can track changes. +function(celix_bundle_dir) + #0 is bundle TARGET + list(GET ARGN 0 BUNDLE) + list(REMOVE_AT ARGN 0) + + #1 is the input dir + list(GET ARGN 0 INPUT_DIR) + list(REMOVE_AT ARGN 0) + + if (NOT BUNDLE OR NOT INPUT_DIR) + message(FATAL_ERROR "celix_bundle_dir must have atleast two arguments: BUNDLE_TARGET and INPUT_DIR!") + endif() + + set(OPTIONS ) + set(ONE_VAL_ARGS DESTINATION) + set(MULTI_VAL_ARGS ) + cmake_parse_arguments(COPY "${OPTIONS}" "${ONE_VAL_ARGS}" "${MULTI_VAL_ARGS}" ${ARGN}) + + get_target_property(BUNDLE_DIR ${BUNDLE} "BUNDLE_CONTENT_DIR") + if (NOT COPY_DESTINATION) + set(DESTINATION "${BUNDLE_DIR}/${FILES_DESTINATION}") + else() + set(DESTINATION "${BUNDLE_DIR}") + endif() + + set(COPY_CMAKE_SCRIPT "${CMAKE_BINARY_DIR}/celix/gen/bundles/${BUNDLE}/copy-${INPUT_DIR}.cmake") + file(WRITE ${COPY_CMAKE_SCRIPT} + "file(COPY ${CMAKE_CURRENT_LIST_DIR}/${INPUT_DIR} DESTINATION ${DESTINATION})") + + set(TIMESTAMP "${CMAKE_BINARY_DIR}/celix/gen/bundles/${BUNDLE}/copy-${INPUT_DIR}.timestamp") + file(GLOB DIR_FILES ${INPUT_DIR}) + add_custom_command(OUTPUT ${TIMESTAMP} + COMMAND ${CMAKE_COMMAND} -E touch ${TIMESTAMP} + COMMAND ${CMAKE_COMMAND} -P ${COPY_CMAKE_SCRIPT} + DEPENDS ${DIR_FILES} + COMMENT "Copying dir ${INPUT_DIR} to ${DESTINATION}" + ) + + get_target_property(DEPS ${BUNDLE} "BUNDLE_DEPEND_TARGETS") + list(APPEND DEPS "${TIMESTAMP}") + set_target_properties(${BUNDLE} PROPERTIES "BUNDLE_DEPEND_TARGETS" "${DEPS}") +endfunction() + function(bundle_headers) message(DEPRECATION "bundle_headers is deprecated, use celix_bundle_headers instead.") celix_bundle_headers(${ARGN}) http://git-wip-us.apache.org/repos/asf/celix/blob/c4de9077/examples/celix-examples/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/celix-examples/CMakeLists.txt b/examples/celix-examples/CMakeLists.txt index f11979f..86ed757 100644 --- a/examples/celix-examples/CMakeLists.txt +++ b/examples/celix-examples/CMakeLists.txt @@ -35,7 +35,7 @@ if (EXAMPLES) add_subdirectory(dm_example_cxx) if (NOT ANDROID) - add_subdirectory(mongoose) + add_subdirectory(civetweb) endif() add_subdirectory(embedding) add_subdirectory(service_hook_example) http://git-wip-us.apache.org/repos/asf/celix/blob/c4de9077/examples/celix-examples/civetweb/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/celix-examples/civetweb/CMakeLists.txt b/examples/celix-examples/civetweb/CMakeLists.txt new file mode 100644 index 0000000..99926f9 --- /dev/null +++ b/examples/celix-examples/civetweb/CMakeLists.txt @@ -0,0 +1,37 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +add_library(civetweb_static STATIC + civetweb/civetweb.c +) +target_include_directories(civetweb_static PUBLIC SYSTEM civetweb) +target_compile_options(civetweb_static PRIVATE -Wno-format -Wno-implicit-function-declaration -DUSE_WEBSOCKET) + +add_celix_bundle(embedded_civetweb + VERSION 1.0.0 + SOURCES src/bundle_activator.c +) +target_link_libraries(embedded_civetweb PRIVATE Celix::shell_api) +celix_bundle_private_libs(embedded_civetweb civetweb_static) +celix_bundle_dir(embedded_civetweb resources) + +add_celix_container(civetweb_example + BUNDLES + Celix::shell + Celix::shell_tui + embedded_civetweb +) \ No newline at end of file
