![]() Also, you can generate the configuration files for your build system in the generation process. We designed it to allow a several levels of generator-generated dependencies so that one generator can rely on generated products of another.Īnother two tricks to consider, if your build system allows you to use regular expressions to build files, you may want to use it. We also ended up running the build system twice with two different graphs, one graph for generators and another graph for the other files. (we don't need it at the moment as our files don't change that often) The build system of course did not run the generator directly, but instead we wrote a small python script that decided how to run the generator properly - for example an improvement we can add is generating all the files to /tmp and only moving the changed files (comparing using diff), thus only the changed files will be touched. If the generator or the xml files changed the build system ran the generator (which generated everything - even if only one file changed, that means it touches all the generated files). Our solution involved treating the xmls and the generator as code that needs to compile, treating the generator as a dependency and the xml files as source. I don't know cmake, but this might give you several ideas: Only we don't work with cmake but another build system. ![]() If you do not know the name of the files, you can use ADD_CUSTOM_COMMAND( OUTPUT generated.timestampĬOMMAND $" COPY_ONLY )įILE( GLOB GENERATED_SOURCES. The custom command will take care of regeneration IF required. You may write a simple script, that build a hash of source tree and re. Normally you would list all your source files in your CMakeLists.txt and if you add a file there CMake would automatically re-run to generate new build/make files. However, since it does nothing (besides printing the comment and checking the dependencies) in this case, that doesn't matter. Then you have to re-run CMake each time, so it will run that command again. NB: The RunGenerator target will always be considered out-of-date and, thus, always run. ![]() Then make your other targets depend on this one: ADD_DEPENDENCIES( MyTarget RunGenerator ) To ensure this, the following should do the trick: ADD_CUSTOM_TARGET( RunGenerator DEPENDS generatedfile1 generatedfile2ĬOMMENT "Checking if re-generation is required" ) Make sure that the generated files are not used in more than one independent target that may compile in parallel or you may(will) get a conflict during your build. ADD_CUSTOM_COMMAND( OUTPUT generatedfile1 generatedfile2ĬOMMAND python generateSources.py xmlfile1 xmlfile2ĭEPENDS xmlfile1 xmlfile2 generateSources.pyĬOMMENT "Generating source code from XML" ) It allows you to define input and output dependencies and will only run if the outputs are older than the inputs. Use ADD_CUSTOM_COMMAND to trigger your generator. My code generator will generate a variable number of files. But this relies on the output of the code generator being known in advance. What is the proper way to handle such a situation in cmake? I have seen this previous answer: " Get CMake to execute a target in project before building a library". In other words, I want the libraries to depend on the generator to have run. I also want to make sure that the generated code is always run before my libraries. However, this runs every time I run cmake and it touches the files, causing my generated code to be recompiled and adding to my total compile time. At the moment, I am using execute_process to fire off the generator. I want to use cmake to manage the build process. ![]() The input (an XML file) to the generator changes.I know that the generated code will only change if one of two conditions are true: This code is subsequently compiled and linked to my libraries and executables. src/generated (supposed for the generated c and header files by protoc)ĬMakeLists-1 (project root) cmake_minimum_required (VERSION 2.I am working on a source code repository that generates some C++ code by running a python script outputting headers and implementation. src/externals/protodef (from other repository, only contains. In general, before the build process starts the macro should have been run to generated the source files. Setting the file properties to generated seems also not to help. I can not add the sources to the target, because the files do not exist, they exist after generation, so this results in an error when CMake runs. It seems however the make file is not invoked because no sources are added to the target. This macro is invoked from the CMakeLists.txt in the subdirectory containing the. If the PROTOBUF_GENERATE_CPP macro is executed it generates the sources and the headers files. I have a project with subdirectories, where each subdirectory has its own CMakeLists.txt I am quite new to CMake and until now everything was easy except the integration with protocol buffers. I have seen a lot of similar questions and answers, but until now it seems not so obvious to get it working.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |