You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2020/06/08 19:24:00 UTC
[celix] 01/01: Refactors generation and usage of CelixTargets cmake
files for different configs
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch feature/single_bundle_targets_entry_point
in repository https://gitbox.apache.org/repos/asf/celix.git
commit 04268d9168d81f3161e4c733648082085806936c
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Mon Jun 8 21:23:28 2020 +0200
Refactors generation and usage of CelixTargets cmake files for different configs
---
bundles/http_admin/civetweb/CMakeLists.txt | 2 +-
cmake/CelixConfig.cmake | 6 +-
cmake/cmake_celix/BundlePackaging.cmake | 62 +++++++++++++-----
cmake/cmake_celix/ContainerPackaging.cmake | 73 ++++++++++++++++++++--
cmake/cmake_celix/DockerPackaging.cmake | 10 +--
examples/CMakeLists.txt | 7 ++-
examples/celix-examples/CMakeLists.txt | 1 +
.../celix-examples/http_example/CMakeLists.txt | 4 +-
8 files changed, 129 insertions(+), 36 deletions(-)
diff --git a/bundles/http_admin/civetweb/CMakeLists.txt b/bundles/http_admin/civetweb/CMakeLists.txt
index 2269ec5..8b43cf2 100644
--- a/bundles/http_admin/civetweb/CMakeLists.txt
+++ b/bundles/http_admin/civetweb/CMakeLists.txt
@@ -25,7 +25,7 @@ target_include_directories(civetweb_shared PUBLIC
$<INSTALL_INTERFACE:include/celix/http_admin>
)
target_link_libraries(civetweb_shared PUBLIC CURL::libcurl)
-
+add_library(Celix::civetweb_shared ALIAS civetweb_shared)
#Create static library
add_library(civetweb_static STATIC
diff --git a/cmake/CelixConfig.cmake b/cmake/CelixConfig.cmake
index f9cc1a4..db1eb3f 100644
--- a/cmake/CelixConfig.cmake
+++ b/cmake/CelixConfig.cmake
@@ -31,11 +31,7 @@ get_filename_component(REL_INSTALL_DIR "${REL_INSTALL_DIR}" PATH)
include("${REL_INSTALL_DIR}/share/celix/cmake/cmake_celix/UseCelix.cmake") #adds celix commands (e.g. add_celix_bundle)
include("${REL_INSTALL_DIR}/share/celix/cmake/Targets.cmake") #imports lib and exe targets (e.g. Celix::framework)
-# Load information for each installed configuration.
-file(GLOB CONFIG_FILES "${REL_INSTALL_DIR}/share/celix/cmake/CelixTargets-*.cmake")
-foreach(f ${CONFIG_FILES})
- include(${f})
-endforeach()
+include("${REL_INSTALL_DIR}/share/celix/cmake/CelixTargets.cmake")
# The rest is added to ensure backwards compatiblity with project using the cmake lib/include var instead of targets.
set(CELIX_CMAKE_MODULES_DIR ${REL_INSTALL_DIR}/share/celix/cmake/Modules)
diff --git a/cmake/cmake_celix/BundlePackaging.cmake b/cmake/cmake_celix/BundlePackaging.cmake
index 3081b5d..d76bdff 100644
--- a/cmake/cmake_celix/BundlePackaging.cmake
+++ b/cmake/cmake_celix/BundlePackaging.cmake
@@ -201,13 +201,19 @@ function(add_celix_bundle)
endif ()
- set(BUNDLE_FILENAME ${BASE_BUNDLE_FILENAME}-${CMAKE_BUILD_TYPE}.zip)
- foreach (NO_POSTFIX_BT IN LISTS CELIX_NO_POSTFIX_BUILD_TYPES)
- if (CMAKE_BUILD_TYPE STREQUAL NO_POSTFIX_BT)
- #setting bundle file name without postfix
- set(BUNDLE_FILENAME ${BASE_BUNDLE_FILENAME}.zip)
- endif ()
- endforeach ()
+ if (CMAKE_BUILD_TYPE)
+ set(BUNDLE_FILENAME ${BASE_BUNDLE_FILENAME}-${CMAKE_BUILD_TYPE}.zip)
+ foreach (NO_POSTFIX_BT IN LISTS CELIX_NO_POSTFIX_BUILD_TYPES)
+ if (CMAKE_BUILD_TYPE STREQUAL NO_POSTFIX_BT)
+ #setting bundle file name without postfix
+ set(BUNDLE_FILENAME ${BASE_BUNDLE_FILENAME}.zip)
+ endif ()
+ endforeach ()
+ else ()
+ #note if no CMAKE_BUILD_TYPE is set, do not use a postfix
+ set(BUNDLE_FILENAME ${BASE_BUNDLE_FILENAME}.zip)
+ endif ()
+
set(BUNDLE_FILE "${CMAKE_CURRENT_BINARY_DIR}/${BUNDLE_FILENAME}")
#set(BUNDLE_CONTENT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${BUNDLE_TARGET_NAME}_content")
@@ -304,7 +310,7 @@ function(add_celix_bundle)
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_DEPEND_TARGETS" "") #bundle target dependencies. Note can be extended after the add_bundle call
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_GEN_DIR" ${BUNDLE_GEN_DIR}) #location for generated output.
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_CREATE_BUNDLE_TARGET" ${BUNDLE_TARGET_NAME}_bundle) #target which creat the bundle zip
- set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_IMPORTED" FALSE) #whether targer is a imported (bundle) target
+ set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_IMPORTED" FALSE) #whether target is a imported (bundle) target
#bundle specific
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_CONTENT_DIR" ${BUNDLE_CONTENT_DIR}) #location where the content to be jar/zipped.
@@ -845,9 +851,12 @@ function(install_celix_bundle_targets)
set(EXPORT_FILE ${EXPORT_NAME}BundleTargets)
endif ()
-# if (NOT CMAKE_BUILD_TYPE STREQUAL "Release")
+ set(BASE_EXPORT_FILE ${EXPORT_FILE})
+ if (CMAKE_BUILD_TYPE)
set(EXPORT_FILE ${EXPORT_FILE}-${CMAKE_BUILD_TYPE})
-# endif ()
+ else ()
+ set(EXPORT_FILE ${EXPORT_FILE}-noconfig)
+ endif ()
if (NOT DEFINED EXPORT_PROJECT_NAME)
string(TOLOWER ${PROJECT_NAME} EXPORT_PROJECT_NAME)
@@ -881,24 +890,43 @@ get_filename_component(_IMPORT_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)
foreach(BUNDLE_TARGET IN LISTS EXPORT_BUNDLES)
set(TN "${EXPORT_NAMESPACE}${BUNDLE_TARGET}")
- string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
+ if (CMAKE_BUILD_TYPE)
+ string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
+ else ()
+ set(BUILD_TYPE "NOCONFIG")
+ endif ()
file(APPEND "${CONF_IN_FILE}" "
if (NOT TARGET ${TN})
add_library(${TN} SHARED IMPORTED)
- set_property(TARGET ${TN} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${BUILD_TYPE})
- set_target_properties(${TN} PROPERTIES
- BUNDLE_IMPORTED TRUE
- BUNDLE_FILE \"\${_IMPORT_PREFIX}/share/${EXPORT_PROJECT_NAME}/bundles/$<TARGET_PROPERTY:${BUNDLE_TARGET},BUNDLE_FILENAME>\"
- BUNDLE_FILENAME \"$<TARGET_PROPERTY:${BUNDLE_TARGET},BUNDLE_FILENAME>\"
- )
endif ()
+set_property(TARGET ${TN} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${BUILD_TYPE})
+set_target_properties(${TN} PROPERTIES
+ BUNDLE_IMPORTED TRUE
+ BUNDLE_FILE_${BUILD_TYPE} \"\${_IMPORT_PREFIX}/share/${EXPORT_PROJECT_NAME}/bundles/$<TARGET_PROPERTY:${BUNDLE_TARGET},BUNDLE_FILENAME>\"
+ BUNDLE_FILENAME_${BUILD_TYPE} \"$<TARGET_PROPERTY:${BUNDLE_TARGET},BUNDLE_FILENAME>\"
+)
")
endforeach()
+
file(GENERATE OUTPUT "${CONF_FILE}" INPUT "${CONF_IN_FILE}")
+
+ #Generate not build type specific targets file
+ set(GEN_CONF_FILE "${CMAKE_BINARY_DIR}/celix/gen/cmake/${EXPORT_NAME}-BundleTargets.cmake")
+ file(GENERATE OUTPUT ${GEN_CONF_FILE} CONTENT "
+# Load bundle information for each installed configuration.
+get_filename_component(_DIR \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)
+file(GLOB CONFIG_FILES \"\${_DIR}/${BASE_EXPORT_FILE}-*.cmake\")
+foreach(f \${CONFIG_FILES})
+ include(\${f})
+endforeach()
+")
+
if (EXPORT_COMPONENT)
install(FILES "${CONF_FILE}" DESTINATION ${EXPORT_DESTINATION} RENAME ${EXPORT_FILE}.cmake COMPONENT ${EXPORT_COMPONENT})
+ install(FILES "${GEN_CONF_FILE}" DESTINATION ${EXPORT_DESTINATION} RENAME ${BASE_EXPORT_FILE}.cmake COMPONENT ${EXPORT_COMPONENT})
else ()
install(FILES "${CONF_FILE}" DESTINATION ${EXPORT_DESTINATION} RENAME ${EXPORT_FILE}.cmake)
+ install(FILES "${GEN_CONF_FILE}" DESTINATION ${EXPORT_DESTINATION} RENAME ${BASE_EXPORT_FILE}.cmake)
endif ()
endfunction()
diff --git a/cmake/cmake_celix/ContainerPackaging.cmake b/cmake/cmake_celix/ContainerPackaging.cmake
index 7d643b7..bb385f4 100644
--- a/cmake/cmake_celix/ContainerPackaging.cmake
+++ b/cmake/cmake_celix/ContainerPackaging.cmake
@@ -364,13 +364,14 @@ function(celix_container_bundles_dir)
else ()
get_target_property(IMP ${BUNDLE} BUNDLE_IMPORTED)
if (IMP) #An imported bundle target -> handle target without DEPENDS
+ _celix_extract_imported_bundle_info(${BUNDLE}) #extracts BUNDLE_FILE and BUNDLE_FILENAME
string(MAKE_C_IDENTIFIER ${BUNDLE} BUNDLE_ID) #Create id with no special chars (e.g. for target like Celix::shell)
set(OUT "${CMAKE_BINARY_DIR}/celix/gen/containers/${CONTAINER_TARGET}/copy-bundle-for-target-${BUNDLE_ID}.timestamp")
- set(DEST "${CONTAINER_LOC}/${BD_DIR_NAME}/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
+ set(DEST "${CONTAINER_LOC}/${BD_DIR_NAME}/${BUNDLE_FILENAME}")
add_custom_command(OUTPUT ${OUT}
COMMAND ${CMAKE_COMMAND} -E touch ${OUT}
COMMAND ${CMAKE_COMMAND} -E make_directory ${CONTAINER_LOC}/${BD_DIR_NAME}
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>" ${DEST}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different "${BUNDLE_FILE}" ${DEST}
COMMENT "Copying (imported) bundle '${BUNDLE}' to '${CONTAINER_LOC}/${BD_DIR_NAME}'"
)
set(HANDLED TRUE)
@@ -461,8 +462,10 @@ function(celix_container_bundles)
else()
get_target_property(IMP ${BUNDLE} BUNDLE_IMPORTED)
if (IMP) #An imported bundle target -> handle target without DEPENDS
- set(COPY_LOC "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
- set(ABS_LOC "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>")
+ _celix_extract_imported_bundle_info(${BUNDLE}) #extracts BUNDLE_FILE and BUNDLE_FILENAME
+
+ set(COPY_LOC "${BUNDLE_FILENAME}")
+ set(ABS_LOC "${BUNDLE_FILE}")
set(HANDLED TRUE)
endif ()
endif ()
@@ -581,3 +584,65 @@ function(celix_container_properties)
celix_container_embedded_properties(${ARGN})
endif ()
endfunction()
+
+
+#[[
+extract the BUNDLE_FILENAME and BUNDLE_FILE from a imported bundle target taking into account the used CMAKE_BUILD_TYPE
+and if configured the MAP_IMPORTED_CONFIG_* or CMAKE_MAP_IMPORTED_CONFIG_*
+]]
+macro(_celix_extract_imported_bundle_info)
+ #get_target_property(_CONFIGS ${ARGV0} "IMPORTED_CONFIGURATIONS") #Not needed?
+
+ if (CMAKE_BUILD_TYPE)
+ string(TOUPPER ${CMAKE_BUILD_TYPE} _BUILD_TYPE)
+ else ()
+ set(_BUILD_TYPE "NOCONFIG")
+ endif ()
+
+ get_target_property(BUNDLE_FILE ${ARGV0} BUNDLE_FILE_${_BUILD_TYPE})
+ get_target_property(BUNDLE_FILENAME ${ARGV0} BUNDLE_FILENAME_${_BUILD_TYPE})
+
+ if (NOT BUNDLE_FILE)
+ #BUNDLE_FILE(NAME) not found for the current BUILD_TYPE looking for MAP value (if there is a cmake build type)
+ get_target_property(_MAP_TO_CONFIG ${ARGV0} MAP_IMPORTED_CONFIG_${_BUILD_TYPE})
+ if (NOT _MAP_TO_CONFIG AND CMAKE_MAP_IMPORTED_CONFIG_${_BUILD_TYPE})
+ set(_MAP_TO_CONFIG CMAKE_MAP_IMPORTED_CONFIG_${_BUILD_TYPE})
+ endif ()
+ if (_MAP_TO_CONFIG)
+ get_target_property(BUNDLE_FILE ${ARGV0} BUNDLE_FILE_${_MAP_TO_CONFIG})
+ get_target_property(BUNDLE_FILENAME ${ARGV0} BUNDLE_FILENAME_${_MAP_TO_CONFIG})
+ endif ()
+ unset(_MAP_TO_CONFIG)
+ endif ()
+
+ if (NOT BUNDLE_FILE)
+ get_target_property(BUNDLE_FILE ${ARGV0} BUNDLE_FILE)
+ get_target_property(BUNDLE_FILENAME ${ARGV0} BUNDLE_FILENAME)
+ endif ()
+
+ #fallback steps
+ #TODO TBD, should we now fall back to "any" release config or fail?
+ if (NOT BUNDLE_FILE)
+ get_target_property(BUNDLE_FILE ${ARGV0} BUNDLE_FILE_RELWITHDEBINFO)
+ get_target_property(BUNDLE_FILENAME ${ARGV0} BUNDLE_FILENAME_RELWITHDEBINFO)
+ endif ()
+ if (NOT BUNDLE_FILE)
+ get_target_property(BUNDLE_FILE ${ARGV0} BUNDLE_FILE_RELEASE)
+ get_target_property(BUNDLE_FILENAME ${ARGV0} BUNDLE_FILENAME_RELEASE)
+ endif ()
+ if (NOT BUNDLE_FILE)
+ get_target_property(BUNDLE_FILE ${ARGV0} BUNDLE_FILE_MINSIZEREL)
+ get_target_property(BUNDLE_FILENAME ${ARGV0} BUNDLE_FILENAME_MINSIZEREL)
+ endif ()
+ if (NOT BUNDLE_FILE)
+ get_target_property(BUNDLE_FILE ${ARGV0} BUNDLE_FILE_NOCONFIG)
+ get_target_property(BUNDLE_FILENAME ${ARGV0} BUNDLE_FILENAME_NOCONFIG)
+ endif ()
+ if (NOT BUNDLE_FILE)
+ get_target_property(BUNDLE_FILE ${ARGV0} BUNDLE_FILE_DEBUG)
+ get_target_property(BUNDLE_FILENAME ${ARGV0} BUNDLE_FILENAME_DEBUG)
+ endif ()
+
+ unset(_CONFIGS)
+ unset(_BUILD_TYPE)
+endmacro()
\ No newline at end of file
diff --git a/cmake/cmake_celix/DockerPackaging.cmake b/cmake/cmake_celix/DockerPackaging.cmake
index 430e96f..78643c1 100644
--- a/cmake/cmake_celix/DockerPackaging.cmake
+++ b/cmake/cmake_celix/DockerPackaging.cmake
@@ -392,21 +392,22 @@ function(celix_docker_bundles)
get_target_property(IMP ${BUNDLE} BUNDLE_IMPORTED)
if (IMP) #An imported bundle target -> handle target without DEPENDS
string(MAKE_C_IDENTIFIER ${BUNDLE} BUNDLE_ID) #Create id with no special chars (e.g. for target like Celix::shell)
+ _celix_extract_imported_bundle_info(${BUNDLE}) #extracts BUNDLE_FILE and BUNDLE_FILENAME
set(OUT "${CMAKE_BINARY_DIR}/celix/gen/docker/${DOCKER_TARGET}/copy-bundle-for-target-${BUNDLE_ID}.timestamp")
- set(DEST "${LOC}/${BUNDLES_DIR}/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
+ set(DEST "${LOC}/${BUNDLES_DIR}/${BUNDLE_FILENAME}")
add_custom_command(OUTPUT ${OUT}
COMMAND ${CMAKE_COMMAND} -E touch ${OUT}
COMMAND ${CMAKE_COMMAND} -E make_directory ${LOC}/${BUNDLES_DIR}
- COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILE>" ${DEST}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different "${BUNDLE_FILE}" ${DEST}
COMMENT "Copying (imported) bundle '${BUNDLE}' to '${LOC}/${BUNDLES_DIR}'"
)
- list(APPEND BUNDLES "${BUNDLES_DIR}/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
+ list(APPEND BUNDLES "${BUNDLES_DIR}/${BUNDLE_FILENAME}")
set(HANDLED TRUE)
endif ()
endif ()
endif ()
- if (NOT HANDLED) #assuming (future) bundle target
+ if (NOT HANDLED) #assuming (future) bundle target)
string(MAKE_C_IDENTIFIER ${BUNDLE} BUNDLE_ID) #Create id with no special chars (e.g. for target like Celix::shell)
set(OUT "${CMAKE_BINARY_DIR}/celix/gen/docker/${DOCKER_TARGET}/copy-bundle-for-target-${BUNDLE_ID}.timestamp")
set(DEST "${LOC}/${BUNDLES_DIR}/$<TARGET_PROPERTY:${BUNDLE},BUNDLE_FILENAME>")
@@ -564,6 +565,7 @@ function(install_celix_docker)
if(CELIX_BUILD_DOCKER_USE_DOCKER_DIR_TAR)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${DOCKER_PROJECT_NAME}/${DOCKER_IMAGE_NAME}.tar.gz
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${DOCKER_PROJECT_NAME}
COMMAND tar czf ${CMAKE_BINARY_DIR}/${DOCKER_PROJECT_NAME}/${DOCKER_IMAGE_NAME}.tar.gz --directory=$<TARGET_PROPERTY:${DOCKER_TARGET},DOCKER_LOC> .
DEPENDS ${DOCKERFILE} ${DOCKER_TARGET}
COMMENT "Generating '${DOCKER_IMAGE_NAME}.tar.gz'" VERBATIM
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index d775f8f..d26439c 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -21,14 +21,15 @@
# To build these example:
# - build and install celix
# - Create a new build project dir and cd to it
-# - set the CMAKE_PREFIX_PATH to the install location
+# - set the MAKE_FIND_ROOT_PATH to the install location
# of Celix (e.g. /opt/local) if this is different from
# /usr or /usr/local
# - cmake <loc_to_celix_src>/examples
# - make -j all
-cmake_minimum_required (VERSION 3.2)
+cmake_minimum_required (VERSION 3.4)
project (CelixUse C CXX)
-set(CMAKE_CXX_FLAGS "-std=c++11")
+set(CMAKE_C_FLAGS "-D_GNU_SOURCE -std=gnu99 ${CMAKE_C_FLAGS}")
+set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
find_package(Celix REQUIRED)
add_subdirectory(celix-examples examples)
diff --git a/examples/celix-examples/CMakeLists.txt b/examples/celix-examples/CMakeLists.txt
index 221fb63..7e06819 100644
--- a/examples/celix-examples/CMakeLists.txt
+++ b/examples/celix-examples/CMakeLists.txt
@@ -39,6 +39,7 @@ if (EXAMPLES)
add_subdirectory(embedding)
add_subdirectory(track_tracker_example)
add_subdirectory(log_service_example)
+
add_subdirectory(bundle_with_private_lib)
endif(EXAMPLES)
diff --git a/examples/celix-examples/http_example/CMakeLists.txt b/examples/celix-examples/http_example/CMakeLists.txt
index ac55add..e6f7b77 100644
--- a/examples/celix-examples/http_example/CMakeLists.txt
+++ b/examples/celix-examples/http_example/CMakeLists.txt
@@ -26,7 +26,7 @@ if (TARGET Celix::http_admin AND TARGET Celix::shell AND TARGET Celix::shell_wui
)
target_link_libraries(http_example PRIVATE Celix::http_admin_api)
- celix_bundle_private_libs(http_example civetweb_shared)
+ celix_bundle_private_libs(http_example Celix::civetweb_shared)
celix_bundle_add_dir(http_example resources)
celix_bundle_headers(http_example "X-Web-Resource: /hello$<SEMICOLON>/resources")
@@ -40,4 +40,4 @@ if (TARGET Celix::http_admin AND TARGET Celix::shell AND TARGET Celix::shell_wui
#SHELL_USE_ANSI_COLORS=false
)
-endif ()
\ No newline at end of file
+endif ()