lutin/cmake/GLDTools.cmake

132 lines
4.9 KiB
CMake

cmake_minimum_required(VERSION 3.20)
##
## @brief List all folder in a specific inout folder.
## @param[out] VAR_OUT Result list of folders.
## @param[in] BASE_FOLDER Basic folder to parse.
##
function(sub_dir_list VAR_OUT BASE_FOLDER)
#message(" Search: ${BASE_FOLDER}" )
file(GLOB CHILDREN "${BASE_FOLDER}/*")
#message(" ==>>> ${children}" )
set(OUT_DATA "")
foreach(CHILD ${CHILDREN})
#message(" - ${child}" )
if(IS_DIRECTORY ${CHILD})
#message(" ==> is directory" )
list(APPEND OUT_DATA ${CHILD})
endif()
endforeach()
set(${VAR_OUT} ${OUT_DATA} PARENT_SCOPE)
endfunction()
function(replace_base_path VAR_OUT BASE LIST_ELEMENT)
set(OUT_DATA "")
foreach(ELEM ${LIST_ELEMENT})
string(REPLACE "${BASE}" "" TMP_VARIABLE ${ELEM})
list(APPEND OUT_DATA ${TMP_VARIABLE})
endforeach()
set(${VAR_OUT} ${OUT_DATA} PARENT_SCOPE)
endfunction()
function(copy_file_with_reference BASE_PATH SRC DST)
#check if input function if compatible with changing folder model...
string(FIND "${SRC}" "!" POSITION_IN_FILE REVERSE)
#message("POSITION_IN_FILE=${POSITION_IN_FILE}")
if(${POSITION_IN_FILE} GREATER 0)
string(SUBSTRING "${SRC}" 0 ${POSITION_IN_FILE} FILE_NAME)
MATH(EXPR POSITION_IN_FILE "${POSITION_IN_FILE}+1")
string(SUBSTRING "${SRC}" ${POSITION_IN_FILE} -1 PART_2)
string(FIND "${PART_2}" ":" POSITION_IN_FILE REVERSE)
string(SUBSTRING "${PART_2}" 0 ${POSITION_IN_FILE} FOLDER_SRC)
MATH(EXPR POSITION_IN_FILE "${POSITION_IN_FILE}+1")
string(SUBSTRING "${PART_2}" ${POSITION_IN_FILE} -1 FOLDER_DST)
#message("***********************************************************************")
#message("FILE_NAME=${FILE_NAME}")
#message("FOLDER_SRC=${FOLDER_SRC}")
#message("FOLDER_DST=${FOLDER_DST}")
configure_file(${BASE_PATH}/${FOLDER_SRC}/${FILE_NAME} ${DST}/${FOLDER_DST}/${FILE_NAME} COPYONLY)
else()
configure_file(${BASE_PATH}/${SRC} ${DST}/${SRC} COPYONLY)
endif()
endfunction()
##
## @brief Recursive search of a specific patter (stop whan find the pattern in a folder.
## (have a limit of parsing ==> optimise resarch in a worktree).
## @param[out] VAR_OUT List of all files that corespond of the reg-exp
## @param[in] BASE_FOLDER Basic folder to parse.
## @param[in] REG_EXP Regular expression to search the data.
## @param[in] LIMIT Lismit of folder to recursively parse.
##
function(find_all_files VAR_OUT BASE_FOLDER REG_EXP LIMIT)
if (${LIMIT} LESS_EQUAL 0)
set(${VAR_OUT} "" PARENT_SCOPE)
return()
endif()
MATH(EXPR LIMIT "${LIMIT}-1")
get_filename_component(BASE_FOLDER ${BASE_FOLDER} ABSOLUTE)
#message("KK Search in subDiratory: ${BASE_FOLDER}/${REG_EXP}" )
file(GLOB TMP_FILES "${BASE_FOLDER}/${REG_EXP}")
#message("-end-" )
set(GLD_FILES "")
#message("Find file: '${GLD_FILES}'" )
foreach(ELEM ${TMP_FILES})
if(IS_DIRECTORY "${ELEM}")
get_filename_component(DIR_NAME_RELATIVE ${ELEM} NAME)
#message(" =!=> DIR_NAME_RELATIVE = ${DIR_NAME_RELATIVE}" )
if("${ELEM}" STREQUAL "${BASE_FOLDER}" OR "${ELEM}" STREQUAL "${BASE_FOLDER}/" OR "${ELEM}" STREQUAL ".")
continue()
endif()
#message(" element: ${ELEM}" )
#message(" BASE_FOLDER: ${BASE_FOLDER}" )
find_all_files(OUT_SUB_LIST "${ELEM}" "${REG_EXP}" ${LIMIT})
#message(" start Add 1" )
list(APPEND GLD_FILES ${OUT_SUB_LIST})
#message(" -end-" )
else()
#message(" start Add 2" )
list(APPEND GLD_FILES ${ELEM})
#message(" -end-" )
endif()
endforeach()
set(${VAR_OUT} ${GLD_FILES} PARENT_SCOPE)
endfunction()
function(find_all_files_exeption VAR_OUT BASE_FOLDER REG_EXP LIMIT)
if (${LIMIT} LESS_EQUAL 0)
set(${VAR_OUT} "" PARENT_SCOPE)
return()
endif()
MATH(EXPR LIMIT "${LIMIT}-1")
get_filename_component(BASE_FOLDER ${BASE_FOLDER} ABSOLUTE)
#message("KK Search in subDiratory: ${BASE_FOLDER}/${REG_EXP}" )
file(GLOB GLD_FILES "${BASE_FOLDER}/${REG_EXP}")
#message("Find file: '${GLD_FILES}'" )
if("${GLD_FILES}" STREQUAL "")
#message("Search in subDiratory: ${BASE_FOLDER}" )
# no element continue search...
set(SUBDIRS "")
sub_dir_list(SUBDIRS "${BASE_FOLDER}")
#message(" =!=> : ${SUBDIRS}" )
foreach(ELEM ${SUBDIRS})
get_filename_component(DIR_NAME_RELATIVE ${ELEM} NAME)
#message(" =!=> DIR_NAME_RELATIVE = ${DIR_NAME_RELATIVE}" )
if("${DIR_NAME_RELATIVE}" STREQUAL ".git" OR "${DIR_NAME_RELATIVE}" STREQUAL ".island" OR "${DIR_NAME_RELATIVE}" STREQUAL "archive" OR "${DIR_NAME_RELATIVE}" STREQUAL "out" OR "${DIR_NAME_RELATIVE}" STREQUAL "target" OR "${DIR_NAME_RELATIVE}" STREQUAL "lutin")
continue()
endif()
if("${ELEM}" STREQUAL "${BASE_FOLDER}" OR "${ELEM}" STREQUAL "${BASE_FOLDER}/")
continue()
endif()
#message(" element: ${ELEM}" )
#message(" BASE_FOLDER: ${BASE_FOLDER}" )
find_all_files_exeption(OUT_SUB_LIST "${ELEM}" "${REG_EXP}" ${LIMIT})
list(APPEND GLD_FILES ${OUT_SUB_LIST})
endforeach()
endif()
set(${VAR_OUT} ${GLD_FILES} PARENT_SCOPE)
endfunction()