9#include "directory_replace_placeholder.h"
55 return (packageName.isSameBegining(
"Phoenix") || packageName.isSameBegining(
"phoenix"));
63 PString cmakeFindBody;
68 cmakeFindBody +=
"find_package("+pkgAttr.
getCmakeFind()+
")";
80 PString phoenixPullExtraModule;
84 phoenixPullExtraModule +=
"pull_extra_module(\""+pkgAttr.
getName()+
"\" \""+pkgAttr.
getUrl()+
"\")\n";
87 return phoenixPullExtraModule;
95 PString phoenixFindModule;
99 phoenixFindModule +=
" "+pkgAttr.
getName();
102 return phoenixFindModule;
110 PString phoenixGlobalDep;
111 phoenixGlobalDep +=
"set(" + projectConfig.
name.toUpper() +
"_TEST_DEPENDENCIES\n";
112 phoenixGlobalDep +=
"\t" + projectConfig.
name.toSnakeCase() +
"\n";
116 phoenixGlobalDep +=
"\t"+pkgAttr.
getCmakeLib()+
"\n";
119 phoenixGlobalDep +=
")";
120 return phoenixGlobalDep;
128 PString targetLinkBody;
129 targetLinkBody +=
"target_link_libraries("+projectConfig.
name.toSnakeCase()+
" ";
143 targetLinkBody +=
")\n";
144 return targetLinkBody;
155 PString pixi_name = pkgAttr.
getPixiName().toLower();
158 if(pixi_name ==
"")
continue;
159 else if(min_version.empty() && max_version.empty()){
160 pixiBody += pixi_name +
" = \"*\"\n";
161 }
else if(max_version.empty()){
162 pixiBody += pixi_name +
" = \"" + min_version +
"\"\n";
164 pixiBody += pixi_name +
" = \"" + min_version;
165 if(!min_version.empty() && !max_version.empty()) pixiBody +=
",";
166 pixiBody += max_version +
"\"\n";
177 PString packageMdList;
181 packageMdList +=
"- ["+pkgAttr.
getName()+
"]("+pkgAttr.
getUrl()+
")\n";
184 return packageMdList;
192 PString authorListPixi;
193 authorListPixi +=
"authors = [\n";
194 for(ProjectMembersMap::const_iterator it = projectConfig.
authorMap.begin(); it != projectConfig.
authorMap.end(); ++it){
198 authorListPixi +=
"]\n";
199 return authorListPixi;
207 PString projectAuthorList;
208 bool firstAuthor =
true;
209 for(ProjectMembersMap::const_iterator it = projectConfig.
authorMap.begin(); it != projectConfig.
authorMap.end(); ++it){
211 if(!firstAuthor) projectAuthorList +=
",\n";
212 projectAuthorList +=
" {\n";
213 projectAuthorList +=
" \"@type\": \"Person\",\n";
214 projectAuthorList +=
" \"givenName\": \"" + author.
getFirstName() +
"\",\n";
215 projectAuthorList +=
" \"familyName\": \"" + author.
getLastName() +
"\",\n";
216 projectAuthorList +=
" \"email\": \"" + author.
getEmail() +
"\",\n";
217 projectAuthorList +=
" \"affiliation\": {\n";
218 projectAuthorList +=
" \"@type\": \"Organization\",\n";
219 projectAuthorList +=
" \"name\": \"" + author.
getAffiliation() +
"\"\n";
220 projectAuthorList +=
" }\n";
221 projectAuthorList +=
" }";
224 return projectAuthorList;
232 PString projectContributorList;
233 bool firstContributor =
true;
236 if(!firstContributor) projectContributorList +=
",\n";
237 projectContributorList +=
" {\n";
238 projectContributorList +=
" \"@type\": \"Person\",\n";
239 projectContributorList +=
" \"givenName\": \"" + contributor.
getFirstName() +
"\",\n";
240 projectContributorList +=
" \"familyName\": \"" + contributor.
getLastName() +
"\",\n";
241 projectContributorList +=
" \"email\": \"" + contributor.
getEmail() +
"\",\n";
242 projectContributorList +=
" \"affiliation\": {\n";
243 projectContributorList +=
" \"@type\": \"Organization\",\n";
244 projectContributorList +=
" \"name\": \"" + contributor.
getAffiliation() +
"\"\n";
245 projectContributorList +=
" }\n";
246 projectContributorList +=
" }";
247 firstContributor =
false;
249 return projectContributorList;
259 maintainer +=
" \"@type\": \"Person\",\n";
260 maintainer +=
" \"givenName\": \"" + maintainerPerson.
getFirstName() +
"\",\n";
261 maintainer +=
" \"familyName\": \"" + maintainerPerson.
getLastName() +
"\",\n";
262 maintainer +=
" \"email\": \"" + maintainerPerson.
getEmail() +
"\",\n";
263 maintainer +=
" \"affiliation\": {\n";
264 maintainer +=
" \"@type\": \"Organization\",\n";
265 maintainer +=
" \"name\": \"" + maintainerPerson.
getAffiliation() +
"\"\n";
275 PString keywordsBody;
277 bool firstKeyword =
true;
278 for(std::vector<PString>::const_iterator it = projectConfig.
keywordList.begin(); it != projectConfig.
keywordList.end(); ++it){
279 if(!firstKeyword) keywordsBody +=
",\n";
280 keywordsBody +=
" \"" + *it +
"\"";
281 firstKeyword =
false;
294 PString nanobindSources;
295 nanobindSources +=
"# We are now ready to compile the actual extension module\n";
297 for(
const PPath & classConfigFile : vecClassConfigFile){
298 PPath baseFileName = classConfigFile.getFileName().eraseExtension();
299 PString bindingSource = baseFileName +
"_binding.cpp";
300 PString fileModuleName = baseFileName.toLower() +
"_module";
302 nanobindSources +=
"nanobind_add_module(\n";
303 nanobindSources +=
"\t" + fileModuleName +
" # Name of the module\n";
304 nanobindSources +=
"\tSTABLE_ABI # Compatible Python 3.12+ stable ABI\n";
305 nanobindSources +=
"\tNB_STATIC # Static linking\n";
306 nanobindSources +=
"\tLTO # Link-time optimization\n";
307 nanobindSources +=
"\t" + bindingSource +
" # Source file\n";
308 nanobindSources +=
")\n";
309 nanobindSources +=
"target_link_libraries(" + fileModuleName +
" PRIVATE " + projectConfig.
name.toSnakeCase() +
")\n";
310 nanobindSources +=
"install(TARGETS " + fileModuleName +
" LIBRARY DESTINATION ${LIBRARY_DIRECTORY} ARCHIVE DESTINATION ${LIBRARY_DIRECTORY})\n\n";
313 return nanobindSources;
335 const PString & phoenixFindModule,
const PString & phoenixGlobalDep,
const PString & targetLinkBody,
336 const PString & pixiBody,
const PString & markdownDepList,
const PString & authorListPixi,
337 const PString & projectAuthorList,
const PString & projectContributorList,
const PString & maintainer,
338 const PString & keywordsBody,
const PString & dateStr,
const PString & nanobindCMakeSources)
340 PMapString mapReplace;
342 mapReplace[
"xxxnanobind_sourcesxxx"] = nanobindCMakeSources;
344 mapReplace[
"XXXProjectNameXXX"] = projectConfig.
name;
345 mapReplace[
"XXXPROJECT_NAMEXXX"] = projectConfig.
name.toUpper();
346 mapReplace[
"xxxproject_namexxx"] = projectConfig.
name.toSnakeCase();
347 mapReplace[
"XXXProjectNameDescriptionXXX"] = projectConfig.
description;
348 mapReplace[
"XXXProjectNameUrlXXX"] = projectConfig.
url;
349 mapReplace[
"XXXProjectVersionXXX"] = projectConfig.
version;
350 mapReplace[
"XXXProjectNameHomepageUrlXXX"] = projectConfig.
url;
351 mapReplace[
"XXXProjectNameRunnerTagXXX"] = projectConfig.
runnerTag;
352 mapReplace[
"XXXProjectFindPackageDependenciesXXX"] = cmakeFindBody;
353 mapReplace[
"XXXProjectPhoenixDependenciesXXX"] = phoenixPullExtraModule;
354 mapReplace[
"XXXProjectNameCMakeFindDependenciesXXX"] = phoenixFindModule;
355 mapReplace[
"XXXProjectDependenciesCMakeVarXXX"] = phoenixGlobalDep;
356 mapReplace[
"XXXProjectNameTargetLinkLinDependenciesXXX"] = targetLinkBody;
358 mapReplace[
"xxxphoenixprojectpixipackagenamexxx"] = projectConfig.
name.toLower();
359 mapReplace[
"xxxprojectnamepixiextradependenciesxxx"] = pixiBody;
360 mapReplace[
"XXXProjectNameMarkdownListDependenciesXXX"] = markdownDepList;
361 mapReplace[
"XXXcreationDateXXX"] = dateStr;
362 mapReplace[
"XXXProjectAuthorListPixiXXX"] = authorListPixi;
363 mapReplace[
"XXXAuthorListXXX"] = projectAuthorList;
364 mapReplace[
"XXXContributorListXXX"] = projectContributorList;
365 mapReplace[
"XXXMaintainerXXX"] = maintainer;
366 mapReplace[
"XXXKeywordListsXXX"] = keywordsBody;
388 PString nanobindCMakeSources;
394 PString dateStr = ctime(&(timestamp = time(
nullptr)));
395 dateStr = dateStr.eraseLastChar(
"\n");
399 phoenixFindModule, phoenixGlobalDep, targetLinkBody,
400 pixiBody, markdownDepList, authorListPixi, projectAuthorList,
401 projectContributorList, maintainer, keywordsBody, dateStr, nanobindCMakeSources);
412 for(
const PPath & classConfigFile : vecClassConfigFile){
416 std::cerr <<
"simple_project_load_config : can't load file '" << classConfigFile <<
"'" << std::endl;
421 PPath destFile = pdataDir / classConfigFile.getFileName();
422 PString fileContent = classConfigFile.loadFileContent();
423 if(!destFile.saveFileContent(fileContent)){
424 std::cerr <<
"simple_project_load_config : cannot copy pdata file to project pdata directory '"<<destFile<<
"'" << std::endl;
506 std::cerr <<
"simple_project_generator : cannot parse project description file '"<<descriptionFile<<
"'" << std::endl;
511 std::cerr <<
"simple_project_generator : cannot find package info of project '"<<projectConfig.
name<<
"'" << std::endl;
516 PPath inputConfigPlaceholderDir = PPath(SYSTEM_INSTALL_DIR) / PPath(
"share") / PPath(
"PhoenixGenerator") / PPath(
"Projects") / PPath(projectType), outputPath(
"./");
517 if(!directory_replace_placeholder(outputPath, inputConfigPlaceholderDir, mapReplace)){
518 std::cerr <<
"simple_project_generator : cannot replace placeholder in project generation '"<<projectConfig.
name<<
"'" << std::endl;
521 PPath mainPath = PPath(
".") / PPath(projectConfig.
name);
522 PPath srcPath = mainPath / PPath(
"src"), pdataDir = mainPath / PPath(
"pdata");
523 if(!pdataDir.createDirectory()){
524 std::cerr <<
"simple_project_generator : cannot create pdata directory '"<<pdataDir<<
"'" << std::endl;
540 std::cerr <<
"simple_project_generator : cannot load config to generate project in '"<<srcPath<<
"'" << std::endl;
544 std::cerr <<
"simple_project_generator : cannot generate sources in '"<<srcPath<<
"'" << std::endl;
549 std::cerr <<
"simple_project_generator : cannot generate class generator script in pdata directory '"<<pdataDir<<
"'" << std::endl;
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
Class generator for Nanobind property trait.
Class generator for Nanobind property trait.
Class generator for Nanobind property trait.
Class generator for Nanobind property trait.
Class generator for Nanobind property trait.
Class generator for Nanobind property trait.
Class generator for Nanobind property trait.
Class to describe a basic class.
const PVecClassConfig & getVecClassConfig() const
Get the vector of all config class of the current pdata file.
const PPath & getFileName() const
Get the file name of the current PDataConfig.
const PVecPath & getVecInclude() const
Get the vector of all include files of the current pdata file.
Manager of the Trait backends.
void addTraitBackend()
Add a trait backend into the PTraitBackendManager.
Describes a package attributes.
const PString & getName() const
Gets the name of the PPackageAttribute.
const PString & getMaxVersion() const
Gets the maxVersion of the PPackageAttribute.
const PString & getUrl() const
Gets the url of the PPackageAttribute.
const PString & getCmakeFind() const
Gets the cmakeFind of the PPackageAttribute.
const PString & getCmakeLib() const
Gets the cmakeLib of the PPackageAttribute.
const PString & getMinVersion() const
Gets the minVersion of the PPackageAttribute.
const PString & getPixiName() const
Gets the pixiName of the PPackageAttribute.
Describes a package attributes.
const PString & getFirstName() const
Gets the firstName of the PProjectMembers.
const PString & getLastName() const
Gets the lastName of the PProjectMembers.
const PString & getEmail() const
Gets the email of the PProjectMembers.
const PString & getAffiliation() const
Gets the affiliation of the PProjectMembers.
Manager of the Trait backends.
void addTraitBackend()
Add a trait backend into the PTraitBackendManager.
Manager of the Trait backends.
void addTraitBackend()
Add a trait backend into the PWrapperTraitBackendManager.
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
bool generator_class_full(const PTraitBackendManager &manager, const ProjectParam &projectParam)
Generate the full sources and related unit tests from configuration.
bool generator_nanobind_full(const PNanobindTraitBackendManager &manager, const ProjectParam &projectParam)
Generate the full sources and related unit tests from configuration.
bool parserClassConfig(std::vector< PClassConfig > &listClassConfig, PVecPath &listInclude, const PPath &fileName)
Parser list class config.
bool project_generator_loadPackageInfo(ProjectConfig &config)
This function should load the package info file from share/PhoenixGenerator/Packages and retrieve the...
bool project_generator_loadConfig(ProjectConfig &config, const PPath &descriptionFile)
Load the project configuration.
bool generateClassGeneratorScript(const PVecPath &vecClassConfigFile, const PPath &scriptDir, const GeneratorMode &mode)
Generate a bash script to re generate all the classes from their pdata configuration files.
PMapString generateAllReplacementData(const ProjectConfig &projectConfig, const GeneratorMode &mode, const PVecPath &vecClassConfigFile)
Generate all replacement data for project generation.
bool simple_project_load_config(ProjectParam ¶m, const PPath &pdataDir, const PVecPath &vecClassConfigFile)
Load configuration pdata of generated sources.
PString generateAuthorListPixi(const ProjectConfig &projectConfig)
Generate author list for Pixi.
PString generateCmakeFindBody(const ProjectConfig &projectConfig)
Generate CMake find_package commands for non-Phoenix dependencies.
PString generateProjectContributorList(const ProjectConfig &projectConfig)
Generate project contributor list for codemeta.json.
bool simple_project_generate_source(const ProjectParam &projectParam)
Save generated sources of project.
bool generateNanobindClassesFull(const ProjectParam &projectParam)
Generate nanobind wrapper classes.
PString generateKeywordsBody(const ProjectConfig &projectConfig)
Generate keywords list for codemeta.json.
PString generateNanobindCmakeSources(const ProjectConfig &projectConfig, const PVecPath &vecClassConfigFile, const GeneratorMode &mode)
Generate the nanobind cmake sources list.
bool generateCppClassesFull(const ProjectParam &projectParam)
Generate C++ classes with all standard traits.
bool isPhoenixDependency(const PString &packageName)
Check if a package is a Phoenix dependency.
PString generatePhoenixFindModule(const ProjectConfig &projectConfig)
Generate Phoenix find module list.
PString generateMarkdownDepList(const ProjectConfig &projectConfig)
Generate markdown list of Phoenix dependencies.
PString generatePhoenixPullExtraModule(const ProjectConfig &projectConfig)
Generate Phoenix pull_extra_module commands.
PString generatePixiBody(const ProjectConfig &projectConfig)
Generate Pixi dependencies.
bool generateWrapperClassesFull(const ProjectParam &projectParam)
Generate wrapper classes.
bool simple_project_generator(const PPath &descriptionFile, const PVecPath &vecClassConfigFile, const PString &projectType, const GeneratorMode &mode)
Create a simple project from a configuration.
PString generateMaintainer(const ProjectConfig &projectConfig)
Generate maintainer information for codemeta.json.
PMapString generateReplacementMap(const ProjectConfig &projectConfig, const GeneratorMode &mode, const PString &cmakeFindBody, const PString &phoenixPullExtraModule, const PString &phoenixFindModule, const PString &phoenixGlobalDep, const PString &targetLinkBody, const PString &pixiBody, const PString &markdownDepList, const PString &authorListPixi, const PString &projectAuthorList, const PString &projectContributorList, const PString &maintainer, const PString &keywordsBody, const PString &dateStr, const PString &nanobindCMakeSources)
Generate the replacement map for placeholders.
PString generateTargetLinkBody(const ProjectConfig &projectConfig)
Generate target_link_libraries command.
PString generateProjectAuthorList(const ProjectConfig &projectConfig)
Generate project author list for codemeta.json.
PString generatePhoenixGlobalDep(const ProjectConfig &projectConfig)
Generate Phoenix global dependencies variable.
ProjectType::ProjectType type
Type of the project to be generated.
Configuration of the project.
PString description
Description of the project.
ProjectMembersMap contributorMap
Map of the contributors of the project.
PString name
Name of the project.
PackageMap mapDependencies
Map of all dependencies of the project with structure PPackageAttribute values.
ProjectMembersMap authorMap
Map of authors of the project.
PString runnerTag
Specific runner tag if needed (could be MUST_big_runner)
PString ciToolkitUrl
CI toolkit url.
PString ciToolkitVersion
Version of the Phoenix CI toolkit component (optional, defaults to 3.0.4)
PString version
Project version.
ProjectMembersMap maintainerMap
Map of maintainers of the project.
std::vector< PString > keywordList
List of keywords linked to the project.
Set of parameters to generate a project.
PPath outputProjectDir
Output path of the full project.
GeneratorMode mode
Mode to be used to generate the project.
PString version
Version of the project.
PPath outputTestDir
Output path of the unit tests.
PVecDataConfig vecDataConfig
Configuration of classes to be generated.
PString name
Name of the project.
PPath outputSourceDir
Output path of the sources.
bool wrapper_generator_class_full(const PWrapperTraitBackendManager &manager, const ProjectParam &projectParam)
Generate the full sources and related unit tests from configuration.