[CMake] [cmake-developers] Identify used source files

CHEVRIER, Marc marc.chevrier at sap.com
Tue Apr 28 04:48:23 EDT 2015


May be more clean and efficient to use CMake property SOURCES:
For example:
add_library (MY_LIB src1.cpp src2.cpp)
get_target_property (lib_sources MY_LIB SOURCES)

And variable lib_sources now contains list of sources associated with target.






On 28/04/15 10:30, "Roman Wüger" <roman.wueger at gmx.at> wrote:

>If someone is interessted in this solution:
>
> 
>set(FilenameUsedFiles ${CMAKE_BINARY_DIR}/UsedFiles.lst)
>file(WRITE ${FilenameUsedFiles} "")
> 
>function (parseArguments)
>    set(options)
>    set(oneValueArgs)
>    set(multiValueArgs)
>    cmake_parse_arguments(CFG "${options}""${oneValueArgs}" "${multiValueArgs}"${ARGN} )
> 
>    foreach(file ${ARGN})
>        get_filename_component(tempPath ${file} DIRECTORY)
>        string(FIND ${file} "${CMAKE_BINARY_DIR}"buildPathFoundPos)
>        string(FIND ${file} "${CMAKE_SOURCE_DIR}"sourcePathFoundPos)
> 
>        if ((NOT "${file}" STREQUAL"IMPORTED") AND
>            (NOT "${file}" STREQUAL "MODULE")AND
>            (NOT "${file}" STREQUAL "STATIC")AND
>            (NOT "${file}" STREQUAL "SHARED")AND
>            (NOT "${file}" STREQUAL "WIN32")AND
>            ${buildPathFoundPos} EQUAL -1)
>            if (${sourcePathFoundPos} EQUAL -1)
>                file(APPEND ${FilenameUsedFiles} "${CMAKE_CURRENT_SOURCE_DIR}/${file}\n")
>            else()
>                file(APPEND ${FilenameUsedFiles} "${file}\n")
>            endif()
>        endif()
>    endforeach()
>endfunction(parseArguments)
> 
>function(add_library name)
>  parseArguments(${ARGN})
>  _add_library(${name} ${ARGN})
>endfunction()
> 
>function(add_executable name)
>  parseArguments(${ARGN})
>  _add_executable(${name} ${ARGN})
>endfunction()
>
>Best Regards 
>Roman
>
>> Am 28.04.2015 um 07:00 schrieb Roman Wüger <roman.wueger at gmx.at>:
>> 
>> Hello,
>> 
>> is there a proper solution to get all used source files for all defined librarys and executables?
>> 
>> My first idea was to overload the main functions such as add_executable() and add_library() temporarily in the main CMakeLists.txt and write a text file or whatever, but I thought there were a better way.
>> 
>> Did anybody know a better way?
>> 
>> Maybe CMake has a way to get a list of used files?
>> 
>> The reason is to clean a big old source tree.
>> 
>> Thanks in advance
>> 
>> Best regards
>> Roman
>> -- 
>> 
>> Powered by www.kitware.com
>> 
>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>> 
>> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>> 
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>> 
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>> 
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/cmake-developers
>-- 
>
>Powered by www.kitware.com
>
>Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
>Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
>CMake Support: http://cmake.org/cmake/help/support.html
>CMake Consulting: http://cmake.org/cmake/help/consulting.html
>CMake Training Courses: http://cmake.org/cmake/help/training.html
>
>Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/cmake


More information about the CMake mailing list