14 body +=
"#========================================\n";
15 body +=
"#\tAuteur : Pierre Aubert\n";
16 body +=
"#\tMail : pierre.aubert@lapp.in2p3.fr\n";
17 body +=
"#\tLicence : CeCILL-C\n";
18 body +=
"#========================================\n\n";
20 body +=
"#========================================\n";
21 body +=
"#\tThis file was generated automatically by phoenix_filegenerator https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/PhoenixFileGenerator\n";
22 body +=
"#\tusing phoenix_generator library https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/PhoenixGenerator\n";
23 body +=
"#\tYou should not modify this file\n";
24 body +=
"#========================================\n\n";
33 if(libName ==
"")
return "";
34 return "Find" + libName.
toUpper() +
".cmake";
47 else return "lib" + cmakeLib.
getName() +
".a";
56 if(listHeader.size() == 0lu || libPrefix ==
"")
return;
57 PString findHeaderVariable(libPrefix +
"_INCLUDE_DIR");
58 fs << std::endl << std::endl <<
"#Find the headers of the library " << libPrefix << std::endl;
60 fs <<
"find_path(" << findHeaderVariable << std::endl;
62 for(PVecPath::const_iterator it(listHeader.begin()); it != listHeader.end(); ++it){
63 fs <<
" " << it->
replace(
"${CMAKE_CURRENT_BINARY_DIR}/",
"").
replace(
"${CMAKE_CURRENT_SOURCE_DIR}/",
"");
67 bool isPHOENIXfind(libPrefix.
isSameBegining(
"PHOENIX_") && libPrefix !=
"PHOENIX_");
70 tmpPrefix =
"PHOENIX/PLIB_" + libPrefix.substr(8, libPrefix.size() - 8lu);
73 fs <<
"\tPATHS ${PHOENIX_PREFIX}/include/" << tmpPrefix <<
" ${CMAKE_INSTALL_PREFIX}/include/" << tmpPrefix << std::endl;
74 fs <<
"\t\t${CMAKE_INCLUDE_PATH}/"<<tmpPrefix<<
" /usr/include/"<<tmpPrefix<<
" /usr/local/include/"<<tmpPrefix<<
" $ENV{HOME}/usr/include/" << tmpPrefix << std::endl;
75 fs <<
")" << std::endl << std::endl;
77 fs <<
"if(" << findHeaderVariable <<
")" << std::endl;
78 fs <<
"\tmessage(STATUS \"Found "<<libPrefix<<
" headers : ${" << findHeaderVariable <<
"}\")" << std::endl;
79 fs <<
"else(" << findHeaderVariable <<
")" << std::endl;
80 fs <<
"\tmessage(FATAL_ERROR \""<<libPrefix<<
" headers not found\")" << std::endl;
81 fs <<
"endif(" << findHeaderVariable <<
")" << std::endl << std::endl;
82 fs <<
"include_directories(${" << findHeaderVariable <<
"})" << std::endl << std::endl << std::endl;
84 fs <<
"include_directories(${" << findHeaderVariable <<
"}/../)" << std::endl << std::endl << std::endl;
95 if(libPrefix ==
"" || fullNameLibrary ==
"")
return;
96 PString findLibraryVariable(libPrefix +
"_LIBRARY_DIR");
97 fs << std::endl << std::endl <<
"#Find the binary or the library " << libPrefix << std::endl;
99 fs <<
"set(LIBRARY_NAME \""<<fullNameLibrary<<
"\")" << std::endl;
100 fs <<
"if(APPLE)" << std::endl;
101 fs <<
"\tset(LIBRARY_NAME \""<<fullNameLibrary.
replace(
".so",
".dylib")<<
"\")" << std::endl;
102 fs <<
"endif()" << std::endl;
104 fs <<
"find_path(" << findLibraryVariable << std::endl;
105 fs <<
"\tNAMES ${LIBRARY_NAME}" << std::endl;
106 fs <<
"\tPATHS ${CMAKE_INSTALL_PREFIX}/lib ${CMAKE_INCLUDE_PATH}/lib /usr/lib /usr/local/lib /lib $ENV{HOME}/usr/lib" << std::endl;
107 fs <<
")" << std::endl << std::endl;
108 fs <<
"if(" << findLibraryVariable <<
")" << std::endl;
109 fs <<
"\tmessage(STATUS \"Found lib "<<libPrefix<<
" : ${" << findLibraryVariable <<
"}\")" << std::endl;
110 fs <<
"else(" << findLibraryVariable <<
")" << std::endl;
111 fs <<
"\tmessage(FATAL_ERROR \"lib "<<libPrefix<<
" not found\")" << std::endl;
112 fs <<
"endif(" << findLibraryVariable <<
")" << std::endl;
113 fs <<
"set("<<libPrefix<<
"_PREFIX \"${" << findLibraryVariable <<
"}/..\" CACHE STRING \"installtion prefix\")" << std::endl;
115 fs <<
"set("<<libPrefix<<
" "<<libName<<
" CACHE STRING \"library name\")" << std::endl;
117 fs <<
"set("<<libPrefix<<
"_FILE ${"<<findLibraryVariable<<
"}/"<<fullNameLibrary<<
" CACHE STRING \"library file\")" << std::endl;
119 fs <<
"set("<<libPrefix<<
"_FOUND \"YES\" CACHE STRING \"true if the library has been found\")" << std::endl;
120 fs <<
"link_directories(${" << findLibraryVariable <<
"})" << std::endl << std::endl << std::endl;
134 fs.open(findPackageFileName.c_str());
136 std::cerr <<
"saveCMakeLibraryFindPackageFile : can't open file '" << findPackageFileName <<
"'" << std::endl;
140 if(extraPreviousFileName !=
""){
147 if(extraFileName !=
""){
163 fs <<
"add_library(" << cmakeLib.
getName();
169 for(PVecPath::const_iterator it(listSources.begin()); it != listSources.end(); ++it){
170 fs <<
"\t" << *it << std::endl;
172 fs <<
")" << std::endl << std::endl;
174 if(listDependencies.size() != 0lu){
175 fs <<
"target_link_libraries(" << cmakeLib.
getName() << std::endl;
176 for(PVecString::const_iterator it(listDependencies.begin()); it != listDependencies.end(); ++it){
177 fs <<
"\t" << *it << std::endl;
179 fs <<
")" << std::endl << std::endl;
182 if(libInstall !=
""){
183 fs <<
"install(TARGETS "<<cmakeLib.
getName()<<
" LIBRARY DESTINATION "<<libInstall<<
" ARCHIVE DESTINATION "<<libInstall<<
")" << std::endl;
186 if(listHeaders.size() != 0lu){
187 fs <<
"set(headers" << cmakeLib.
getName()<<
" " << std::endl;
188 for(PVecPath::const_iterator it(listHeaders.begin()); it != listHeaders.end(); ++it){
189 fs <<
"\t" << *it << std::endl;
191 fs <<
")" << std::endl << std::endl;
192 fs <<
"install(FILES ${headers" << cmakeLib.
getName()<<
"} DESTINATION include/"<<cmakeLib.
getName().
toUpper()<<
")" << std::endl;
197 std::cerr <<
"saveCMakeLibrary : can't create the find_package cmake macro file" << std::endl;
211 std::cerr <<
"saveCMakeExecutable : no source or name for target" << std::endl;
216 fs <<
"add_executable(" << cmakeExecutable.
getName();
219 for(PVecPath::const_iterator it(listSources.begin()); it != listSources.end(); ++it){
220 fs <<
"\t" << *it << std::endl;
222 fs <<
")" << std::endl << std::endl;
224 if(listDependencies.size() != 0lu){
225 fs <<
"target_link_libraries(" << cmakeExecutable.
getName() << std::endl;
226 for(PVecString::const_iterator it(listDependencies.begin()); it != listDependencies.end(); ++it){
227 fs <<
"\t" << *it << std::endl;
229 fs <<
")" << std::endl << std::endl;
232 if(libInstall !=
""){
233 fs <<
"install(TARGETS "<<cmakeExecutable.
getName()<<
" RUNTIME DESTINATION "<<libInstall<<
" ARCHIVE DESTINATION "<<libInstall<<
")" << std::endl;
236 fs << std::endl << std::endl;
253 if(listPackages.size() == 0lu)
return true;
254 for(PVecString::const_iterator it(listPackages.begin()); it != listPackages.end(); ++it){
255 fs <<
"find_package("<<*it<<
" REQUIRED)" << std::endl;
257 fs << std::endl << std::endl;
267 if(listIncludeDirectories.size() == 0lu)
return true;
268 fs <<
"include_directories" << std::endl;
269 for(PVecPath::const_iterator it(listIncludeDirectories.begin()); it != listIncludeDirectories.end(); ++it){
270 fs << *it << std::endl;
272 fs <<
")" << std::endl;
273 fs << std::endl << std::endl;
283 if(listLinkDirectories.size() == 0lu)
return true;
284 fs <<
"link_directories" << std::endl;
285 for(PVecPath::const_iterator it(listLinkDirectories.begin()); it != listLinkDirectories.end(); ++it){
286 fs << *it << std::endl;
288 fs <<
")" << std::endl;
289 fs << std::endl << std::endl;
299 if(fileName ==
"")
return false;
301 fs.open(fileName.c_str());
303 std::cerr <<
"saveCMakeListsGenerator : can't open file '" << fileName <<
"'" << std::endl;
318 fs <<
"project(" << cmakeGenerator.
getProjectName() <<
")" << std::endl;
319 fs <<
"cmake_minimum_required(VERSION 3.0)" << std::endl << std::endl;
321 fs <<
"set(PHOENIX_PREFIX \"$ENV{HOME}/usr\" CACHE STRING \"PHOENIX prefix prefix\")" << std::endl;
322 fs <<
"set(CMAKE_INSTALL_PREFIX \"${PHOENIX_PREFIX}\")" << std::endl;
324 fs <<
"set(CMAKE_MODULE_PATH "<<cmakeGenerator.
getCmakeModulePath()<<
")" << std::endl;
330 const std::vector<PCMakeLibrary> & listLib = cmakeGenerator.
getListLibraries();
331 bool haveFindMacro(
false);
332 if(listLib.size() != 0lu){
333 for(std::vector<PCMakeLibrary>::const_iterator it(listLib.begin()); it != listLib.end(); ++it){
335 haveFindMacro |= it->getWantGenerateFindPackage();
338 const std::vector<PCMakeExecutable> & listExecutable = cmakeGenerator.
getListExecutable();
339 if(listExecutable.size() != 0lu){
340 for(std::vector<PCMakeExecutable>::const_iterator it(listExecutable.begin()); it != listExecutable.end(); ++it){
342 haveFindMacro |= it->getWantGenerateFindPackage();
346 fs <<
"install(FILES";
347 for(std::vector<PCMakeLibrary>::const_iterator it(listLib.begin()); it != listLib.end(); ++it){
348 if(!it->getWantGenerateFindPackage())
continue;
351 for(std::vector<PCMakeExecutable>::const_iterator it(listExecutable.begin()); it != listExecutable.end(); ++it){
352 if(!it->getWantGenerateFindPackage())
continue;
355 fs <<
" DESTINATION share/cmake)" << std::endl << std::endl;
358 fs <<
"if(SELF_TESTS_MODE)" << std::endl;
359 fs <<
"\tinclude(CTest)" << std::endl;
360 fs <<
"\tadd_subdirectory("<<cmakeGenerator.
getTestDirectory()<<
")" << std::endl;
361 fs <<
"endif()" << std::endl << std::endl;
363 fs << std::endl << std::endl << std::endl;
std::vector< PPath > PVecPath
std::vector< PString > PVecString
Describes a CMake executable.
const PString & getName() const
Gets the name of the PCMakeExecutable.
const PVecString & getListDependecies() const
Gets the listDependecies of the PCMakeExecutable.
const PPath & getInstallDirectory() const
Gets the installDirectory of the PCMakeExecutable.
const PString & getOtherCommandAfter() const
Gets the otherCommandAfter of the PCMakeExecutable.
const PString & getRemoveDefinitions() const
Gets the removeDefinitions of the PCMakeExecutable.
const PString & getAddDefinitions() const
Gets the addDefinitions of the PCMakeExecutable.
const PVecPath & getListSources() const
Gets the listSources of the PCMakeExecutable.
Describes a CMake library.
const PPath & getInstallDirectory() const
Gets the installDirectory of the PCMakeLibrary.
const PVecString & getListLibDependecies() const
Gets the listLibDependecies of the PCMakeLibrary.
const PVecPath & getListHeaders() const
Gets the listHeaders of the PCMakeLibrary.
const PVecPath & getListSources() const
Gets the listSources of the PCMakeLibrary.
const PString & getName() const
Gets the name of the PCMakeLibrary.
const PString & getRemoveDefinitions() const
Gets the removeDefinitions of the PCMakeLibrary.
bool getWantGenerateFindPackage() const
Gets the wantGenerateFindPackage of the PCMakeLibrary.
bool getIsShared() const
Gets the isShared of the PCMakeLibrary.
const PString & getOtherCommandAfter() const
Gets the otherCommandAfter of the PCMakeLibrary.
const PString & getAddDefinitions() const
Gets the addDefinitions of the PCMakeLibrary.
Describes a CMakeLists.txt file.
const PPath & getCmakeModulePath() const
Gets the cmakeModulePath of the PCMakeListsGenerator.
const PVecPath & getListIncludeDirectories() const
Gets the listIncludeDirectories of the PCMakeListsGenerator.
const PVecPath & getListLinkDirecories() const
Gets the listLinkDirecories of the PCMakeListsGenerator.
const PPath & getTestDirectory() const
Gets the testDirectory of the PCMakeListsGenerator.
const std::vector< PCMakeExecutable > & getListExecutable() const
Gets the listExecutable of the PCMakeListsGenerator.
const PVecString & getListPackage() const
Gets the listPackage of the PCMakeListsGenerator.
const PString & getProjectName() const
Gets the projectName of the PCMakeListsGenerator.
const std::vector< PCMakeLibrary > & getListLibraries() const
Gets the listLibraries of the PCMakeListsGenerator.
Path of a directory or a file.
PString loadFileContent() const
Get the file content in a PString.
PString replace(const PString &pattern, const PString &replaceStr) const
Replace a PString into an other PString.
PString toUpper() const
Convert std::string in upper case.
bool isSameBegining(const PString &beginStr) const
Say if the current PString has the same begining of beginStr.
bool saveCMakeLinkDirectories(std::ofstream &fs, const PVecPath &listLinkDirectories)
Saves the list of link directories.
PString getCMakeListsHeader()
Get the CMakeLists.txt header.
bool saveCMakeExecutable(std::ofstream &fs, const PCMakeExecutable &cmakeExecutable)
Saves a cmake executable in a file.
bool saveCMakeIncludeDirectories(std::ofstream &fs, const PVecPath &listIncludeDirectories)
Saves the list of include directories.
bool saveCMakeLibrary(std::ofstream &fs, const PCMakeLibrary &cmakeLib)
Saves a cmake library in a file.
void saveFindPackageHeader(std::ofstream &fs, const PString &libPrefix, const PVecPath &listHeader)
Saves the finder of the header.
bool saveCMakeLibraryFindPackageFile(const PCMakeLibrary &cmakeLib, const PPath &extraFileName, const PPath &extraPreviousFileName)
Saves the find_package cmake macro with the library file.
bool saveCMakeUsePackages(std::ofstream &fs, const PVecString &listPackages)
Saves the list of packages dependencies.
void saveFindPackageLibrary(std::ofstream &fs, const PString &libPrefix, const PString &libName, const PString &fullNameLibrary)
Saves the check for the binary library.
PString getFindPackageFileName(const PString &libName)
Gets the name of the find_package cmake macro with the library name.
PString getFullLibraryName(const PCMakeLibrary &cmakeLib)
Gets the name of the library binary file.
bool saveCMakeListsGenerator(const PPath &fileName, const PCMakeListsGenerator &cmakeGenerator)
Saves the PCMakeListsGenerator.