[cmake-developers] Identify used source files

Roman Wüger roman.wueger at gmx.at
Tue Apr 28 04:30:53 EDT 2015


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


More information about the cmake-developers mailing list