Author Topic: how to create project given list of source files  (Read 3633 times)

ludoguri

  • Guest
how to create project given list of source files
« on: May 12, 2020, 09:28:58 am »
Hello. I have a text file containing list of Fortran source files than can be compiled into an executable using gfortran. Can I create create a project file by importing this list rather than typing the source file names manually?
« Last Edit: July 28, 2023, 03:55:16 pm by MortenMacFly »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: how to create project given list of source files
« Reply #1 on: May 12, 2020, 10:40:36 am »
No, as fas as I know. You can create and empty project and then use the "add recursive" command.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: how to create project given list of source files
« Reply #2 on: May 12, 2020, 01:50:24 pm »
You could probably create a squirrel script that does the job...

let me try...

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: how to create project given list of source files
« Reply #3 on: May 12, 2020, 02:14:16 pm »
OK, here is a basic script:

Code
local pm = GetProjectManager();
if (IsNull(pm))
{
    ShowError(_T("Could not query the project manager. Cannot continue."));
    return 0;
}

local p = pm.GetActiveProject();

// File with the source files separated by \n
// for example:
// '''''''''''''''''''
// a.cpp
// b.cpp
// '''''''''''''''''''
local filecontent = IO.ReadFileContents (_T("D:\\ddddd\\fileList.txt"));

// Split the files in lines
local fileList = GetArrayFromString(filecontent, _T("\n"), true);
print(_T("Files to load:"));
for(local i = 0; i < fileList.GetCount(); i++)
{
print(fileList.Item(i) + _T("\n"));   // Print the files in the list, as a check
}

// Base path, the files in the text files are relative in my case. If they are absolute you can remove this
local basePath = _T("D:\\ddddd\\src\\");
for(local i = 0; i < fileList.GetCount(); i++)
{
        // Create file path
local filePath = basePath + fileList.Item(i);
// Add to all build targets
for(local a = 0; a <= p.GetBuildTargetsCount(); a++)
    pm.AddFileToProject(filePath, p, a);
}
// Save the project. This triggers also an update of the project UI
pm.SaveAllProjects();

This works on windows, you have to replace the paths accordingly on linux...
the example file D:\ddddd\fileList.txt
Code
a.cpp
b.cpp
the two source files are in D:\ddddd\src\

To use the scirpt:
1) Create a text document and C&P the top script
2) Replace the paths in the script with the paths and files on your system
3) Save the text document, and rename it to "myImportScript.script"
4) Start codeblocks
5) Create or open the project, where the files should be imported
6) View->Scripting console
7) In the opening window select "Load from file" the second button near the command input field
8) Enjoy

[edit:] fix spelling
[edit2:] References for all this:
http://wiki.codeblocks.org/index.php/Scripting_Code::Blocks
http://wiki.codeblocks.org/index.php/Some_examples
http://wiki.codeblocks.org/index.php/Scripting_commands
http://www.squirrel-lang.org/
« Last Edit: May 12, 2020, 02:21:33 pm by BlueHazzard »