Copy a prebuild file to build folder (SCons) - scons

I want to copy a (prebuild) file from the source folder to the destination folder (variant_dir).
This results in a dependency cycle:
Command('main.elf', 'main.elf', Copy("$TARGET", "$SOURCE"))
How could I specify that the file to copy is located in the source folder (project folder) and the target is in the build folder without using constant values (in SConscript)?
As workaround I renamed the file:
Command('main.elf', 'main.orig', Copy("$TARGET", "$SOURCE"))

This should be the proper syntax for what you want to do:
Command('main.elf', 'main.elf', Copy("$TARGET", "${SOURCE.srcpath}"))
See: http://scons.org/doc/production/HTML/scons-man.html and search for srcpath to see the section on substitution.
That said what you are really asking for is duplicate=partial. I'm not sure if this will work.
Can you specify the elf file with full path on the command line to your tool?
Command('main.elf', 'main.elf',"my_tool $TARGET ${SOURCE.srcpath}")
Or equivalent?

Related

no such file or directory (cygwin)

I am trying to install a solver (SCIP) with cygwin. After unpacking the folder consists of another 5 folders. The manual says I have to go in folder A and use make. Here, I get the message that one file was not found:
zimpl/bool.h: No such file or directory
This file is in folder B in the path zimpl/src/bool.h. How can I link this file from folder B that cygwin can use it while using make in folder A?
The support says:
Blockquote The error you postet looks like your zimpl softlink is incorrect. If you use a relative path, make sure that it is relative to the position where
the link is created. Most softlinks are created directly in the lib
directory, the zimpl softlink, however, is in a subdirectory of the lib
directory, so you have to go up two directories to get to the main SCIP
directory.
However I am not sure how to check the softlinks.
Thanks!

Configure websocketd and PATH variable

I am trying to use this project (websocketd), but the third step is not working:
1-download the platform specific archive //done
2-extract files to folder of your choice or extract executable only // done
3-add the location of websocketd to your PATH variable
Currently i have this PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/www/cpu-stats/websocketd
But when i run this code:
websocketd --help
I will get:
bash: websocketd: command not found
websocketd location
/var/www/cpu-stats/websocketd
Any idea?
I think you should just add the folder "/var/www/cpu-stats" to your path without the executable file name.

In scons, how to specify path of the target?

I'm new to scons. I was trying to specify the path of the target. I don't want the executable to be generated in the same folder, in which the SConstruct file resides.
I tried the following:
(Suppose the SConstruct file resides in some folder 'Foo')
env.Program(
#executable name
target="~/Desktop/my_executable",
...
However this creates directories Foo/~/Desktop/ and places the target my_executable into the leaf directory.
How do I get scons to generate the target inside some fixed folder? I'm using linux.

How to copy built target from build directory to parent directory?

my target is built within build directory named example1,but the resource is at data directory outside of build which is ../
I am using this to copy target out of build:
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/../example1) #remove old one
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/build/example1 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../)
each single line of them works separately but when I put them together,they don't work,example1 cannot update to the same as the one in the build directory.
If your target is named "Example1" say, you should be able to just do:
add_custom_command(TARGET Example1 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:Example1> ${CMAKE_CURRENT_BINARY_DIR}/..)
However, if this copies your exe from your build tree into your source tree, it may be better to consider keeping your source tree clean by copying the required resources from your source tree into your build tree instead.

How to force Scons output (exe, obj, lib & dll) to specific build directory?

I've been trying to get scons to output exe, obj, lib and dll files to a specific build directory.
My file structure looks like this:
/projectdir
/build
/bin
/obj
/source
/subdirs
/..
SConstruct
Basically, what I get now is my source directory is getting polluted with obj files. I'd rather have it all in one place.
The SConstruct file looks like this:
env.VariantDir('build', 'source', duplicate = 0)
env.Program('Hierarchy', source = ['source/sconstest.cpp', 'source/utils/IntUtil.cpp'])
The easiest way I've found is to use 2 files, a SConstruct file and a separate SConscript.
In the SConstruct you simply call the other file and specify the directory for the build output:
# content SConstruct
SConscript('main.scons', variant_dir='build', duplicate=0)
Then in 'main.scons' you do the meat of your build. You can forget about variant directories in this file.
# content of main.scons
env = Environment()
env.Program('Hierarchy',
source = ['source/sconstest.cpp', 'source/utils/IntUtil.cpp'])
It's not that tough to get VariantDir working using only one SConstruct file (for a small project), but it's very confusing as the configuration is different for the one-file and two-file use case.
Only SConstruct:
env = Environment()
env.VariantDir('build', 'src', duplicate=0)
files = Glob('build\*.c')
env.Program("build\program", files)
Notice how the source files are located in .\src but .\build is specified as the location. The output has to be also "prefixed" with .\build otherwise the compiled program will reside in the directory of the SConstruct file.
When you execute the script SCons will compile the *.c files from .\src and put the resulting objects to .\build.
No wonder they renamed BuildDir to VariantDir to try to avoid the confusion (without much success).
The VariantDir (also described in the user guide) tells scons to put generated files in a separate directory. In older versions of scons this function was named BuildDir.
You may also want to read up on avoiding duplicating the source directory (described both in the user guide and on the wiki).
I was using a two-file method like richq's answer, but although the final build products (libs, programs) were going into the right variant directory, the object files were still going to the source directory.
The solution turned out to be to glob the source files by relative path instead of absolute. I have no idea why.
My second scons file originally looked like this. Note globbing by absolute path - when I first wrote this I didn't realize paths would automatically be relative to the scons file.
import os, inspect
env = Environment()
packageDir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
src = Glob(os.path.join(packageDir, "src/*/*.c*"), strings=True, source=True)
env.Program('Foo', source = src)
And that resulted in *.obj ending up under src/ and the program under my variant dir. When I changed it to the following, the object files also went to the variant dir:
env = Environment()
src = Glob("src/*/*.c*", strings=True, source=True)
env.Program('Foo', source = src)
Using absolute paths is probably a noob mistake - I'm relatively new to both scons and Python - but I thought I'd share it in case anyone else has the same frustrating problem.

Resources