Waf: Recursively collect source files and include paths - c++

My C-gcc project structure is:
\Project\wscript (only one in project)
\Project\build\
\Project\Source\Module_1\foo.c
\Project\Source\Module_1\foo.h
\Project\Source\Module_1\dummy\foo2.h
\Project\Source\Module_n\bar.c
\Project\Source\Module_n\any dept...\bar.h
How can I recursively find all *.C files in 'Source' and add to
bld.program(source=HERE)?
instead of manually listing it:
bld.program(source="foo.c bar.c...", includes='..\\Source ..\\Source\Module_1')
Also how can I find every subfolders (preferably which has *.h) and append to include path?
Should I write my own finder functions in python and just pass it?
bld.program(source=SRCs_FOUND, includes=Paths_FOUND)
Will this cause any dependency problems in building?
In any modern IDE this thinking is common, drag one file to the Source tree, and it's automatically added to the build list. Thanks!

You can use globbing to scan the directories.
bld.program(
name = ...
....
source = bld.path.ant_glob('**/Source/*.C')
)
Just search for ant_glob in the waf book.

Related

Why would a CMake build not start build when header file changes

Below is a small sample of the way I'm building my project. I have a list of headers and a list of source files, and pass them to add_executable. Sometimes after several incremental builds, I'm changing the header file but the build isn't doing anything. The status shows that each target is checked but no changes are seen. If I do a small modification in the CPP file, then the build is executed.
What could be the cause of this?
list (APPEND ${PROJ_NAME}_SRC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/lua/lua_config.hpp)
list (APPEND ${PROJ_NAME}_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/source/lua/lua_config.cpp)
add_executable(${PROJ_NAME} ${${PROJ_NAME}_SRC_FILES} ${${PROJ_NAME}_SRC_HEADERS})
I'm using the 'Unix Makefiles' generator.
I see that all my projects header files are not part of the generated depend.cmake file. I guess this is the root of the problem. All the header files from the other conan packages are there, but not the ones for the top level project.
Two things are needed for the header files to be added to the depend.make file. First adding them in the list of files of the target, which I did and add the include directory using target_include_directories.
target_include_directories(${PROJ_NAME} PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
At this point it's still not working. This is because I'm passing two lists of files that are separated using a space ' ' character. After I joined the two lists into a single one using a ';' it started working.
add_executable(${PROJ_NAME} "${${PROJ_NAME}_SRC_FILES};${${PROJ_NAME}_HEADER_FILES}")

How to add entire path into IAR

I just start to use IAR Embedded workbench and meet an issue now. What I need to do is to make a project via IAR with some specific file(.h and .c).
In Eclipse I can add a directory, and then when it compiles, it will scan every sub-directories in the directory to find the included files. I did the same in IAR, but it didn't work. The IAR only scans the directory I added in the 'preprocess' TAG, and it never scans the sub folders in it. Is there any way that can help me to let the IAR scan the 'entire directory', not only the current path?
I'm not sure if my description is accurate or not. Please let me know and help me with this issue.
Thank you so much!!!!!
Your description of the IAR C and C++ include file search is correct: you must explicitly include the directory. The compiler does not search subdirectories.
If the number of subdirectories makes entry in the [IDE Options> Preprocessor > Additional include directories] entry table unwieldy, you can place them in a separate text file and add "-f " in the extra options. Note that using that parameter you may want to use the $PROJ_DIR$ as a root for a relative path.
$PROJ_DIR$ does not seem to get expanded if you put the include directories in a file and use -f

Why doesn't Xcode6 see included header files

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.

Eclipse C++ including header file from my source folder

I'm pretty new to C++ and Eclipse in general so I apologise if I'm missing something fairly obvious.
The problem I'm having is that I'm trying to include a header file in one of my source files but they're in different folders in my project directory. I have no idea how I should be including them. I've uploaded an image showing my problem with the header file I want to include highlighted.
If someone could tell me what '#include' statement I should be using them that would be brilliant.
Thanks!
There are a couple of different options to make this work. Simplest is to change the #include to
#include "../Statistics/Statistics.h"
This will work without any other modifications. However, if you move either file, or somehow change the relative path between the two, this will break.
Alternately, you can add the path to the Statistics folder to your compiler's include file search path. Right click on the project name, select Properties -> C/C++ Build -> Settings and then find the includes files path option for your compiler. For g++, it is -I<path/to/include/folder>. Adding this will make the #include statement work as you currently have it.
A very similar option to the second one is to add the path to the src folder (instead of the Statistics folder) to the includes search path. In this case, you'll have to change the statement to
#include "Statistics/Statistics.h"
When you create subfolders in your src folder then each cpp file is compiled in that folder it is located in. Thus, any "" includes need to specify the relative path to get from that folder to another.
In your case, to get from inside the FileInOut folder you need to go back one level and then into the Statistics folder
eg
#include "../Statistics/Statistics.h"
Another alternative is, if you are keeping your includes in your src directory, to add the src directory to the include path. Now when you include you need only specify the path from the src root.
eg.
#include "Statistics/Statistics.h"

How to search a file in subdirectories?

I have to create a program that search the file "letter.txt" in the subdirectories of a specific directory ( folderA in the example below ).
For example:
folderA/
folderA1/...
folderA2/...
folderA3/...
folderA4/letter.txt
folderA5/...
What API do I have to use to:
- list subdirectories of a specific directory ( folderA ),
- open each of these subdirectories ( folderA1, folderA2, folderA3, etc )
- search and open the file letter.txt ?
In raw Win32, this would be done using FindFirstFile, but you will have to code the recursion manually; it's going to be hard to get all the corner cases right (e.g. what happens if you have reparse points that create a cyclic directory structure?).
For more convenience you can use Boost.Filesystem; class recursive_directory_iterator does exactly what you want. In the past I have also used the recls library and I was quite satisfied -- it just works.
The best way I know how to do that task is to use the Boost.filesystem library.
http://www.boost.org/doc/libs/1_49_0/libs/filesystem/v3/doc/index.htm
It provides a directory iterator (and a recursive directory iterator) that allows you to iterate through files and directories in your directory looking for the file you need need.