diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-05-05 18:28:49 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-05-05 18:28:49 +0200 |
commit | e49eed2b1fffced9f5f8d2b997bb6b987cf208f3 (patch) | |
tree | 290083dbd1e0ec9d4c2a99063527ecf72394b6b8 | |
parent | 792d96c11c6b43df1349edcf245a8a31072fa71d (diff) |
Update CMake following app-template repo update
Change-Id: Ib24f8c2000f78f5f6fea3126e52f34570e4eee18
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r-- | CAN-binder/CMakeLists.txt | 9 | ||||
-rw-r--r-- | CAN-binder/etc/config.cmake | 7 | ||||
-rw-r--r-- | CAN-binder/etc/macros.cmake | 201 | ||||
-rw-r--r-- | CAN-binder/libs/CMakeLists.txt | 2 | ||||
-rw-r--r-- | CAN-binder/low-can-binding/CMakeLists.txt | 8 | ||||
-rw-r--r-- | CAN-binder/low-can-demo/CMakeLists.txt | 7 | ||||
-rw-r--r-- | CAN-binder/low-can-demo/binding/CMakeLists.txt | 4 |
7 files changed, 116 insertions, 122 deletions
diff --git a/CAN-binder/CMakeLists.txt b/CAN-binder/CMakeLists.txt index 56e7860..f834f24 100644 --- a/CAN-binder/CMakeLists.txt +++ b/CAN-binder/CMakeLists.txt @@ -21,8 +21,13 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.3) include(${CMAKE_CURRENT_SOURCE_DIR}/etc/config.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/etc/macros.cmake) +MESSAGE(STATUS "INSTALL PREFIX: ${CMAKE_INSTALL_PREFIX}") + # Bindings to compile # -------------------- -search_targets() +project_subdirs_add() + +project_targets_populate() +project_package_build() -build_widget() +project_closing_msg() diff --git a/CAN-binder/etc/config.cmake b/CAN-binder/etc/config.cmake index d03a0ae..7893de0 100644 --- a/CAN-binder/etc/config.cmake +++ b/CAN-binder/etc/config.cmake @@ -23,7 +23,10 @@ set(VERSION "1.0") set(PROJECT_PRETTY_NAME "Low level CAN binding") set(PROJECT_DESCRIPTION "Expose CAN Low Level APIs through AGL Framework") set(PROJECT_URL "https://github.com/iotbzh/CAN_signaling") +set(PROJECT_AUTHOR "Romain Forlot") +set(PROJECT_AUTHOR_MAIL "romain.forlot@iot.bzh") set(PROJECT_ICON "icon.png") +set(PROJECT_LANGUAGES,"C") # Compilation Mode (DEBUG, RELEASE) # ---------------------------------- @@ -36,7 +39,7 @@ set(CMAKE_BUILD_TYPE "DEBUG") # PKG_CONFIG required packages # ----------------------------- -set (PKG_REQUIRED_LIST +set (PKG_REQUIRED_LIST json-c libsystemd afb-daemon @@ -58,7 +61,7 @@ set(CLOSING_MESSAGE "Test with: afb-daemon --rootdir=\$\$(pwd)/low-can-binding/p # (BUG!!!) as PKG_CONFIG_PATH does not work [should be an env variable] # --------------------------------------------------------------------- -set(CMAKE_INSTALL_PREFIX ${HOME}/opt) +set(CMAKE_INSTALL_PREFIX $ENV{HOME}/opt) set(CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}/lib64/pkgconfig ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) set(LD_LIBRARY_PATH ${CMAKE_INSTALL_PREFIX}/lib64 ${CMAKE_INSTALL_PREFIX}/lib) diff --git a/CAN-binder/etc/macros.cmake b/CAN-binder/etc/macros.cmake index 5e00b9d..184f8ba 100644 --- a/CAN-binder/etc/macros.cmake +++ b/CAN-binder/etc/macros.cmake @@ -19,7 +19,7 @@ #-------------------------------------------------------------------------- -# WARNING: +# WARNING: # Do not change this cmake template # Customise your preferences in "./etc/config.cmake" #-------------------------------------------------------------------------- @@ -30,84 +30,76 @@ macro(PROJECT_TARGET_ADD TARGET_NAME) set(PROJECT_TARGETS ${PROJECT_TARGETS} ${TARGET_NAME} CACHE INTERNAL PROJECT_TARGETS) set(TARGET_NAME ${TARGET_NAME}) + + # Cmake does not maintain targets list before 3.7 + # ------------------------------------------------- + if(${CMAKE_VERSION} VERSION_LESS 3.7) + set(GLOBAL_TARGET_LIST ${PROJECT_TARGETS}) + else() + get_property(GLOBAL_TARGET_LIST GLOBAL PROPERTY GlobalTargetList) + endif() endmacro(PROJECT_TARGET_ADD) macro(defstr name value) add_definitions(-D${name}=${value}) endmacro(defstr) -macro(setc name value) - if(NOT DEFINED ${name}) - set(${name} ${value}) - endif(NOT DEFINED ${name}) -endmacro(setc) - -# Dumb macro to add each directory under a path. Make sure we grab all header files! -macro(fill_include_dir path) - file(GLOB_RECURSE dirlist LIST_DIRECTORIES true "${path}/*") - foreach(filename ${dirlist}) - if(IS_DIRECTORY ${filename}) - include_directories(${filename}) - endif(IS_DIRECTORY ${filename}) - endforeach() -endmacro(fill_include_dir) - -# Helper function to retrieve source files from a library repo. -function(find_source_files path) - file(GLOB_RECURSE cfiles "${path}/*.[c]") - file(GLOB_RECURSE cppfiles "${path}/*.cpp") - foreach(filename ${cfiles}) - if(NOT ${filename} MATCHES ".*([Tt]est|[Ee]xample|[Ss]ample).*") - string(APPEND sources "${filename};") - endif(NOT ${filename} MATCHES ".*([Tt]est|[Ee]xample|[Ss]ample).*") - endforeach() - foreach(filename ${cppfiles}) - if(NOT ${filename} MATCHES ".*([Tt]est|[Ee]xample|[Ss]ample).*") - string(APPEND sources "${filename};") - endif(NOT ${filename} MATCHES ".*([Tt]est|[Ee]xample|[Ss]ample).*") +# WGT packaging +macro(project_targets_populate) + 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_WIDGET_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 ${WIDGET_LIBDIR}/${P}${TARGET}.so + DEPENDS ${TARGET} + COMMAND mkdir -p ${WIDGET_LIBDIR} + COMMAND cp ${BD}/${P}${OUT}.so ${WIDGET_LIBDIR} + ) + add_custom_target(${POPULE_WIDGET_TARGET} ALL DEPENDS ${WIDGET_LIBDIR}/${P}${TARGET}.so) + elseif(${T} STREQUAL "EXECUTABLE") + add_custom_command(OUTPUT ${WIDGET_BINDIR}/${P}${TARGET} + DEPENDS ${TARGET} + COMMAND mkdir -p ${WIDGET_BINDIR} + COMMAND cp ${BD}/${P}${OUT} ${WIDGET_BINDIR} + ) + add_custom_target(${POPULE_WIDGET_TARGET} ALL DEPENDS ${WIDGET_BINDIR}/${P}${TARGET}) + elseif(${T} STREQUAL "HTDOCS") + add_custom_command(OUTPUT ${WIDGET_HTTPDIR} + DEPENDS ${TARGET} + COMMAND cp -r ${BD}/${P}${OUT} ${WIDGET_HTTPDIR} + ) + add_custom_target(${POPULE_WIDGET_TARGET} ALL DEPENDS ${WIDGET_HTTPDIR}) + elseif(${T} STREQUAL "DATA") + add_custom_command(OUTPUT ${WIDGET_DATADIR} + DEPENDS ${TARGET} + COMMAND cp -r ${BD}/${P}${OUT} ${WIDGET_DATADIR} + ) + add_custom_target(${POPULE_WIDGET_TARGET} ALL DEPENDS ${WIDGET_HTTPDIR}) + endif(${T} STREQUAL "BINDING") + PROJECT_TARGET_ADD(${POPULE_WIDGET_TARGET}) +# elseif(${CMAKE_BUILD_TYPE} MATCHES "[Dd][Ee][Bb][Uu][Gg]") +# MESSAGE(AUTHOR_WARNING "This target, ${TARGET}, will be not be included in the package.") + endif() endforeach() - set(sources_files ${sources} PARENT_SCOPE) -endfunction(find_source_files) +endmacro(project_targets_populate) -# WGT packaging -macro(populate_widget) - # Declaration of a custom command that will populate widget tree with the target - set(POPULE_WIDGET_TARGET "populate_${TARGET_NAME}") - - get_target_property(T ${TARGET_NAME} LABELS) - get_target_property(OUT ${TARGET_NAME} OUTPUT_NAME) - if(${T} STREQUAL "BINDING") - add_custom_command(OUTPUT ${WIDGET_LIBDIR}/${TARGET_NAME}.so - DEPENDS ${TARGET_NAME} - COMMAND mkdir -p ${WIDGET_LIBDIR} - COMMAND cp ${OUT}.so ${WIDGET_LIBDIR} - ) - add_custom_target(${POPULE_WIDGET_TARGET} ALL DEPENDS ${WIDGET_LIBDIR}/${TARGET_NAME}.so) - elseif(${T} STREQUAL "EXECUTABLE") - add_custom_command(OUTPUT ${WIDGET_BINDIR}/${TARGET_NAME} - DEPENDS ${TARGET_NAME} - COMMAND mkdir -p ${WIDGET_BINDIR} - COMMAND cp ${OUT} ${WIDGET_BINDIR} - ) - add_custom_target(${POPULE_WIDGET_TARGET} ALL DEPENDS ${WIDGET_BINDIR}/${TARGET_NAME}) - elseif(${T} STREQUAL "HTDOCS") - add_custom_command(OUTPUT ${WIDGET_HTTPDIR} - DEPENDS ${TARGET_NAME} - COMMAND cp -r ${OUT} ${WIDGET_HTTPDIR} - ) - add_custom_target(${POPULE_WIDGET_TARGET} ALL DEPENDS ${WIDGET_HTTPDIR}) - elseif(${T} STREQUAL "DATA") - add_custom_command(OUTPUT ${WIDGET_DATADIR} - DEPENDS ${TARGET_NAME} - COMMAND cp -r ${OUT} ${WIDGET_DATADIR} - ) - add_custom_target(${POPULE_WIDGET_TARGET} ALL DEPENDS ${WIDGET_HTTPDIR}) - endif(${T} STREQUAL "BINDING") - PROJECT_TARGET_ADD(${POPULE_WIDGET_TARGET}) -endmacro(populate_widget) - -macro(build_widget) - if("${PROJECT_TARGETS}" MATCHES "populate_") +macro(project_package_build) + if("${PROJECT_TARGETS}" MATCHES "project_populate_") if(NOT EXISTS ${WIDGET_DIR}/config.xml.in OR NOT EXISTS ${WIDGET_DIR}/${PROJECT_ICON}.in) configure_file(${PROJECT_WGT_DIR}/config.xml.in ${WIDGET_DIR}/config.xml) file(COPY ${PROJECT_WGT_DIR}/${PROJECT_ICON}.in DESTINATION ${WIDGET_DIR}/${PROJECT_ICON}) @@ -126,28 +118,33 @@ macro(build_widget) set(ADDITIONAL_MAKE_CLEAN_FILES, "${PROJECT_NAME}.wgt") else() MESSAGE(FATAL_ERROR "Widget tree empty, please populate it by calling populate_widget() macro with target you want to include into it.") - endif("${PROJECT_TARGETS}" MATCHES "populate_") -endmacro(build_widget) + endif("${PROJECT_TARGETS}" MATCHES "project_populate_") +endmacro(project_package_build) + +macro(project_subdirs_add) + if(${ARGV0}) + file(GLOB filelist "${ARGV0}") + else() + file(GLOB filelist "*") + endif(${ARGV0}) -macro(search_targets) - file(GLOB filelist "*") foreach(filename ${filelist}) - if(EXISTS "${filename}/CMakeLists.txt") - add_subdirectory(${filename}) - endif(EXISTS "${filename}/CMakeLists.txt") + if(EXISTS "${filename}/CMakeLists.txt") + add_subdirectory(${filename}) + endif(EXISTS "${filename}/CMakeLists.txt") endforeach() -endmacro() +endmacro(project_subdirs_add) -setc(CMAKE_BUILD_TYPE Debug) +set(CMAKE_BUILD_TYPE Debug CACHE STRING "the type of build") set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMP0048 1) # Include project configuration # ------------------------------ -project(${NAME} VERSION ${VERSION}) -setc(PROJECT_WGT_DIR "packaging/wgt") -setc(PROJECT_LIBDIR "libs") -setc(PROJECT_RESOURCES "data") +project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES ${PROJECT_LANGUAGES}) +set(PROJECT_WGT_DIR "packaging/wgt" CACHE PATH "Subpath to the widget directory") +set(PROJECT_LIBDIR "libs" CACHE PATH "Subpath to libraries") +set(PROJECT_RESOURCES "data" CACHE PATH "Subpath to data") INCLUDE(FindPkgConfig) INCLUDE(CheckIncludeFiles) @@ -166,20 +163,20 @@ add_compile_options(-ffunction-sections -fdata-sections) add_compile_options(-fPIC) add_compile_options(-g) -setc(CMAKE_C_FLAGS_PROFILING "-g -O2 -pg -Wp,-U_FORTIFY_SOURCE") -setc(CMAKE_C_FLAGS_DEBUG "-g -O2 -ggdb -Wp,-U_FORTIFY_SOURCE") -setc(CMAKE_C_FLAGS_RELEASE "-O2") -setc(CMAKE_C_FLAGS_CCOV "-g -O2 --coverage") +set(CMAKE_C_FLAGS_PROFILING "-g -O2 -pg -Wp,-U_FORTIFY_SOURCE" CACHE STRING "Flags for profiling") +set(CMAKE_C_FLAGS_DEBUG "-g -O2 -ggdb -Wp,-U_FORTIFY_SOURCE" CACHE STRING "Flags for debugging") +set(CMAKE_C_FLAGS_RELEASE "-O2" CACHE STRING "Flags for releasing") +set(CMAKE_C_FLAGS_CCOV "-g -O2 --coverage" CACHE STRING "Flags for coverage test") set(CMAKE_CXX_FLAGS_PROFILING "-g -O0 -pg -Wp,-U_FORTIFY_SOURCE") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -ggdb -Wp,-U_FORTIFY_SOURCE") set(CMAKE_CXX_FLAGS_RELEASE "-g -O2") set(CMAKE_CXX_FLAGS_CCOV "-g -O2 --coverage") -setc(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/Install") +set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/Install" CACHE PATH "The path where to install") # (BUG!!!) as PKG_CONFIG_PATH does not work [should be en env variable] -setc(PKG_CONFIG_USE_CMAKE_PREFIX_PATH 1) +set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON CACHE BOOLEAN "Flag for using prefix path") # Loop on required package and add options foreach (PKG_CONFIG ${PKG_REQUIRED_LIST}) @@ -234,23 +231,17 @@ endif() if(EXTRA_DEPENDENCIES_ORDER) set(DEPENDENCIES_TARGET ${PROJECT_NAME}_extra_dependencies) add_custom_target(${DEPENDENCIES_TARGET} ALL - DEPENDS ${EXTRA_DEPENDENCY_ORDER} + DEPENDS ${EXTRA_DEPENDENCY_ORDER} ) endif() -# Cmake does not maintain targets list before 3.7 -# ------------------------------------------------- -if(${CMAKE_VERSION} VERSION_LESS 3.7) - set(GLOBAL_TARGET_LIST ${PROJECT_TARGETS}) -else() - get_property(GLOBAL_TARGET_LIST GLOBAL PROPERTY GlobalTargetList) -endif() - # Print developer helper message when everything is done # ------------------------------------------------------- -if(CLOSING_MESSAGE AND GLOBAL_TARGET_LIST) - add_custom_target(${PROJECT_NAME}_done ALL - DEPENDS ${DEPENDENCIES_TARGET} ${GLOBAL_TARGET_LIST} - COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan "++ ${CLOSING_MESSAGE}" - ) -endif() +macro(project_closing_msg) + if(CLOSING_MESSAGE AND GLOBAL_TARGET_LIST) + add_custom_target(${PROJECT_NAME}_done ALL + DEPENDS ${DEPENDENCIES_TARGET} ${GLOBAL_TARGET_LIST} + COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan "++ ${CLOSING_MESSAGE}" + ) + endif() +endmacro() diff --git a/CAN-binder/libs/CMakeLists.txt b/CAN-binder/libs/CMakeLists.txt index cc4af55..995c4e7 100644 --- a/CAN-binder/libs/CMakeLists.txt +++ b/CAN-binder/libs/CMakeLists.txt @@ -17,4 +17,4 @@ ########################################################################### # Add target to project dependency list -search_targets()
\ No newline at end of file +project_subdirs_add()
\ No newline at end of file diff --git a/CAN-binder/low-can-binding/CMakeLists.txt b/CAN-binder/low-can-binding/CMakeLists.txt index 6a871df..c408388 100644 --- a/CAN-binder/low-can-binding/CMakeLists.txt +++ b/CAN-binder/low-can-binding/CMakeLists.txt @@ -18,11 +18,12 @@ ########################################################################### # Add target to project dependency list -PROJECT_TARGET_ADD(low-can-binding) +PROJECT_TARGET_ADD(low-can) # Define project Targets add_library(${TARGET_NAME} MODULE - binding/${TARGET_NAME}.cpp + binding/${TARGET_NAME}-hat.cpp + binding/${TARGET_NAME}-cb.cpp binding/configuration.cpp binding/configuration-generated.cpp can/can-bus.cpp @@ -45,7 +46,7 @@ PROJECT_TARGET_ADD(low-can-binding) # Binder exposes a unique public entry point SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES - PREFIX "" + PREFIX "afs-" LABELS "BINDING" LINK_FLAGS ${BINDINGS_LINK_FLAG} OUTPUT_NAME ${TARGET_NAME} @@ -64,4 +65,3 @@ PROJECT_TARGET_ADD(low-can-binding) INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${BINDINGS_INSTALL_DIR}) - populate_widget() diff --git a/CAN-binder/low-can-demo/CMakeLists.txt b/CAN-binder/low-can-demo/CMakeLists.txt index a554598..6de2a25 100644 --- a/CAN-binder/low-can-demo/CMakeLists.txt +++ b/CAN-binder/low-can-demo/CMakeLists.txt @@ -17,9 +17,6 @@ # limitations under the License. ########################################################################### -# Add subdir targets -search_targets() - # Add target to project dependency list PROJECT_TARGET_ADD(low-can-demo) @@ -35,11 +32,11 @@ PROJECT_TARGET_ADD(low-can-demo) # Binder exposes a unique public entry point SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES - PREFIX "" LABELS "HTDOCS" OUTPUT_NAME dist.prod) # installation directory INSTALL(DIRECTORY dist.prod/ DESTINATION ${BINDINGS_INSTALL_DIR}) - populate_widget()
\ No newline at end of file +# Add subdir targets +project_subdirs_add() diff --git a/CAN-binder/low-can-demo/binding/CMakeLists.txt b/CAN-binder/low-can-demo/binding/CMakeLists.txt index 4078e2b..945d2d8 100644 --- a/CAN-binder/low-can-demo/binding/CMakeLists.txt +++ b/CAN-binder/low-can-demo/binding/CMakeLists.txt @@ -25,7 +25,7 @@ PROJECT_TARGET_ADD(stat-binding) # Binder exposes a unique public entry point SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES - PREFIX "" + PREFIX "afb-" LABELS "BINDING" LINK_FLAGS ${BINDINGS_LINK_FLAG} OUTPUT_NAME ${TARGET_NAME} @@ -38,5 +38,3 @@ PROJECT_TARGET_ADD(stat-binding) # installation directory INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${BINDINGS_INSTALL_DIR}) - - populate_widget() |