Personal files inclusion now by projects.
authorRomain Forlot <romain.forlot@iot.bzh>
Wed, 16 Aug 2017 16:33:46 +0000 (18:33 +0200)
committerRomain Forlot <romain.forlot@iot.bzh>
Wed, 16 Aug 2017 16:47:52 +0000 (18:47 +0200)
Depending on file name you can include some files from your
home or system by project or globally

Change-Id: I1fef678073977633576a21893065e681b286646c
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
README.md
cmake/cmake.d/03-macros.cmake
cmake/common.cmake
docs/dev_guide/4_advanced_customization.md

index 4487817..195162f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -307,8 +307,13 @@ automatically from some specifics locations. They are included in that order:
 - Home CMake files located in _$HOME/.config/app-templates/cmake.d_
 - System CMake files located in _/etc/app-templates/cmake.d_
 
-CMake files has to be named using the following convention: `XX-***.cmake`,
-where `XX` are numbers, `***` file name (ie. `99-my_customs.cmake`).
+CMake files has to be named using the following convention: `XX-common-*.cmake`
+or `XX-${PROJECT_NAME}-*.cmake`, where `XX` are numbers, `*` file name
+(ie. `99-common-my_customs.cmake`).
+
+> **NOTE** You need to specify after numbers that indicate include order, to
+which project that file applies, if it applies to all project then use keyword
+`common`.
 
 So, saying that you should be aware that every normal cmake variables used at
 project level could be overwrited by home or system located cmake files if
index 62e5790..7abbf08 100644 (file)
@@ -50,21 +50,41 @@ endmacro(configure_files_in_dir)
 
 # Create custom target dedicated for HTML5 and DATA AGL target type
 macro(add_input_files INPUT_FILES)
+       set(XML_LIST ${INPUT_FILES})
+       set(LUA_LIST ${INPUT_FILES})
+       set(JSON_LIST ${INPUT_FILES})
+       list(FILTER XML_LIST INCLUDE REGEX "xml$")
+       list(FILTER LUA_LIST INCLUDE REGEX "lua$")
+       list(FILTER JSON_LIST INCLUDE REGEX "json$")
+
        add_custom_target(${TARGET_NAME} 
        DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
        )
 
+       foreach(file ${XML_LIST})
+               add_custom_command(TARGET ${TARGET_NAME}
+                       PRE_BUILD
+                       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+                       COMMAND ${XML_CHECKER} ${file}
+               )
+       endforeach()
+       foreach(file ${LUA_LIST})
        add_custom_command(TARGET ${TARGET_NAME}
-       PRE_BUILD
-       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-       COMMAND [ -f *xml ] && ${XML_CHECKER} ${INPUT_FILES}
-       COMMAND [ -f *lua ] && ${LUA_CHECKER} ${INPUT_FILES}
-       COMMAND [ -f *json ] && for f in ${INPUT_FILES}; do cat ${INPUT_FILES} | ${JSON_CHECKER}; done
+               PRE_BUILD
+               WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+               COMMAND ${LUA_CHECKER} ${file}
        )
+       endforeach()
+       foreach(file ${JSON_LIST})
+       add_custom_command(TARGET ${TARGET_NAME}
+               PRE_BUILD
+               WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+               COMMAND cat ${file} | ${JSON_CHECKER}
+       )
+       endforeach()
 
        add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
-       DEPENDS  ${INPUT_FILES}
-       OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
+       DEPENDS ${INPUT_FILES}
        COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
        COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
        COMMAND cp -r ${INPUT_FILES} ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
@@ -163,13 +183,19 @@ macro(project_targets_populate)
                                add_dependencies(populate ${POPULE_PACKAGE_TARGET})
                                add_dependencies(${POPULE_PACKAGE_TARGET} ${TARGET})
                        elseif(${T} STREQUAL "DATA")
-                               add_custom_command(OUTPUT ${PACKAGE_DATADIR}-xx
-                                       DEPENDS ${BD}/${P}${OUT}
+                               # Generate list of output files instead of just one output directory
+                               get_target_property(SF ${TARGET} SOURCES)
+                               foreach(file ${SF})
+                                       get_filename_component(JUST_FILENAME ${file} NAME)
+                                       list(APPEND OUTPUT_FILES ${PACKAGE_DATADIR}/${JUST_FILENAME})
+                               endforeach()
+                               add_custom_target(${POPULE_PACKAGE_TARGET})
+                               add_custom_command(TARGET ${POPULE_PACKAGE_TARGET}
+                                       POST_BUILD
                                        COMMAND mkdir -p ${PACKAGE_DATADIR}
                                        COMMAND touch ${PACKAGE_DATADIR}
-                                       COMMAND cp -r ${BD}/${P}${OUT}/* ${PACKAGE_DATADIR}
+                                       COMMAND cp -r ${BD}/${TARGET} ${PACKAGE_DATADIR}
                                )
-                               add_custom_target(${POPULE_PACKAGE_TARGET} DEPENDS ${PACKAGE_DATADIR}-xx)
                                add_dependencies(populate ${POPULE_PACKAGE_TARGET})
                                add_dependencies(${POPULE_PACKAGE_TARGET} ${TARGET})
                        endif(${T} STREQUAL "BINDING")
index 4e34fcd..1cec2a7 100644 (file)
@@ -26,9 +26,9 @@
 
 file(GLOB project_cmakefiles ${PROJECT_APP_TEMPLATES_DIR}/cmake/cmake.d/[0-9][0-9]-*.cmake)
 list(SORT project_cmakefiles)
-file(GLOB home_cmakefiles $ENV{HOME}/.config/app-templates/cmake.d/[0-9][0-9]-*.cmake)
+file(GLOB home_cmakefiles $ENV{HOME}/.config/app-templates/cmake.d/[0-9][0-9]-common-*.cmake $ENV{HOME}/.config/app-templates/cmake.d/[0-9][0-9]-${PROJECT_NAME}-*.cmake)
 list(SORT home_cmakefiles)
-file(GLOB system_cmakefiles /etc/app-templates/cmake.d/[0-9][0-9]-*.cmake)
+file(GLOB system_cmakefiles /etc/app-templates/cmake.d/[0-9][0-9]-common-*.cmake /etc/app-templates/cmake.d/[0-9][0-9]-${PROJECT_NAME}-*.cmake)
 list(SORT system_cmakefiles)
 
 foreach(file ${system_cmakefiles} ${home_cmakefiles} ${project_cmakefiles})
index 796232f..0d8957e 100644 (file)
@@ -9,8 +9,13 @@ automatically from some specifics locations. They are included in that order:
 - Home CMake files located in _$HOME/.config/app-templates/cmake.d_
 - System CMake files located in _/etc/app-templates/cmake.d_
 
-CMake files has to be named using the following convention: `XX-***.cmake`,
-where `XX` are numbers, `***` file name (ie. `99-my_customs.cmake`).
+CMake files has to be named using the following convention: `XX-common-*.cmake`
+or `XX-${PROJECT_NAME}-*.cmake`, where `XX` are numbers, `*` file name
+(ie. `99-common-my_customs.cmake`).
+
+> **NOTE** You need to specify after numbers that indicate include order, to
+which project that file applies, if it applies to all project then use keyword
+`common`.
 
 So, saying that you should be aware that every normal cmake variables used at
 project level could be overwrited by home or system located cmake files if