cmake: read and compile dynamically-generated list of cpp files

前端 未结 3 620
既然无缘
既然无缘 2021-01-18 15:17

I have a custom tool that processes a given list of IDL files and produces a number of .cpp and .h files as output. I want to add those files to the list of things to compil

3条回答
  •  一向
    一向 (楼主)
    2021-01-18 15:31

    This is a few years late but this works just fine:

    #run whatever tool that generates the cpp files
    execute_process(COMMAND "./your_tool.sh")
    
    #read files from files.txt and make a cmake 'list' out of them
    file(READ "files.txt" SOURCES)
    
    #found this technique to build the cmake list here:
    #http://public.kitware.com/pipermail/cmake/2007-May/014236.html
    #maybe there is a better way...
    STRING(REGEX REPLACE ";" "\\\\;" SOURCES "${SOURCES}")
    STRING(REGEX REPLACE "\n" ";" SOURCES "${SOURCES}")
    
    #at this point you have your source files inside ${SOURCES}
    #build a static library...?
    add_library(mylib STATIC ${SOURCES})
    

提交回复
热议问题