I'm working on a C++ project that has some hand coded source files, as well as some source and header files that are generated by a command line tool.
The actual source and header files generated are determined by the contents of a JSON file that the tool reads, and so cannot be hardcoded into the scons script.
I would like to set up scons so that if I clean the project, then make it, it will know to run the command line tool to generate the generated source and header files as the first step, and then after that compile both my hand coded files and the generated source files and link them to make my binary.
Is this possible? I'm at a loss as to how to achieve this, so any help would be much appreciated.
Yes, this is possible. Depending on which tool you're using to create the header/source files, you want to check our ToolIndex at https://bitbucket.org/scons/scons/wiki/ToolsIndex , or read our guide https://bitbucket.org/scons/scons/wiki/ToolsForFools for writing your own Builder.
Based on your description you'll probably have to write your own Emitter, which parses the JSON input file and returns the filenames that will finally result from the call. Then, all you need to do is:
# creates foo.h/cpp and bar.h/cpp
env.YourBuilder('input.json')
env.Program(Glob('*.cpp'))
The Glob will find the created files, even if they don't physically exist on the hard drive yet, and add them to the overall dependencies.
If you have further questions or problems arise, please consider subscribing to our User mailing list at scons-users#scons.org (see also http://scons.org/lists.html ).
Thanks to Dirk Baechle I got this working - for anyone else interested here is the code I used.
import subprocess
env = Environment( MSVC_USE_SCRIPT = "c:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\bin\\vcvars32.bat")
def modify_targets(target, source, env):
#Call the code generator to generate the list of file names that will be generated.
subprocess.call(["d:/nk/temp/sconstest/codegenerator/CodeGenerator.exe", "-filelist"])
#Read the file name list and add a target for each file.
with open("GeneratedFileList.txt") as f:
content = f.readlines()
content = [x.strip('\n') for x in content]
for newTarget in content:
target.append(newTarget)
return target, source
bld = Builder(action = 'd:/nk/temp/sconstest/codegenerator/CodeGenerator.exe', emitter = modify_targets)
env.Append(BUILDERS = {'GenerateCode' : bld})
env.GenerateCode('input.txt')
# Main.exe depends on all the CPP files in the folder. Note that this
# will include the generated files, even though they may not currently
# exist in the folder.
env.Program('main.exe', Glob('*.cpp'))
There's an example at:
https://github.com/SCons/scons/wiki/UsingCodeGenerators
I'll also echo Dirk's suggestion to join the users mailing list.
I'm trying to build opencv2 as a universal framework. I am systematically removing the files/folders that I do not need. But I am running into this issue where the include files are not found. See the image below:
The following image clearly shows that the file is indeed there.
One of the contractors working with us said he had put the include files into the same directory as the source files and rename them according to their file structure but using "." instead of "/" as shown below:
But that means that I must go through all of the files that include files and change the include statement to use "." instead of "/". REALLY?
Is this true? Or do we have a configuration set wrong?
You need to setup search paths for your target in Build Settings->Search Paths->Header search paths.
I would like to generate documentation for C++ files with doxygen. Everything is good when all the *.h and *.cpp files are stored in one folder. Then I type
doxygen -g doxygenfile
and then
doxygen doxygenfile
After all this I have a latex folder and an html folder. Everything is good. The problem is when these files *.h *.cpp are stored in different locations, e.g.: *.h in H folder *.cpp in CPP folder and so on. Could somebody tell me how to generate the documentation in this case?
If you want a GUI to tweak how Doxygen works you can use doxywizard and open the generate Doxyfile.
In order to make doxygen look into the subdirectories you can change in the Doxyfile this line
RECURSIVE =
with
RECURSIVE = YES
Edit: As bornruffians pointed out, Doxygen looks for the source files in the directories specified in the INPUT setting (always in the Doxyfile). So you can specify each directory in the INPUT tag by writing something like
INPUT = "src/CPP" "src/H"
and turn off the RECURSIVE tag. You can also put single files as values for the INPUT tag.
How do I configure the list of file extensions for syntax highlighting in PyScripter?
In particular I like to include Zope Page Template files (ZPT) with extension .pt to the list of HTML files to show proper syntax highlighting.
Finally got it:
You need to modify the file filter for HTML files to include the .pt
extension in Tools > Options > IDE Options.
I would like Visual Studio to automatically put my .h file in a folder /ProjectPath/include and my src file in /ProjectPath/src. That way, if I use the "Create class wizard" for instance, it would put the good path by default without me having to change the folder. Anyone know what setting I should change to get this behaviour when I add file ?
Thanks,
Jean-Philippe
You can right click on a folder in solution explorer and go to properties, you need to set the Filter property.
For example the Source Files folder by default has a filter like this in a C++ project: cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx