| 1 |
// OSRail -- a network enabled railroad operations simulator and utilities |
|---|
| 2 |
// Copyright (C) 2007,2008 Samuel E. Henley sehenley@comcast.net |
|---|
| 3 |
// |
|---|
| 4 |
// This program is free software; you can redistribute it and/or modify |
|---|
| 5 |
// it under the terms of the GNU General Public License as published by |
|---|
| 6 |
// the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 |
// (at your option) any later version. |
|---|
| 8 |
// |
|---|
| 9 |
// This program is distributed in the hope that it will be useful, |
|---|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 |
// GNU General Public License for more details. |
|---|
| 13 |
// |
|---|
| 14 |
// You should have received a copy of the GNU General Public License along |
|---|
| 15 |
// with this program; if not, write to the Free Software Foundation, Inc., |
|---|
| 16 |
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|---|
| 17 |
// |
|---|
| 18 |
// |
|---|
| 19 |
//---------------------------------------------------------------------- |
|---|
| 20 |
/// \file |
|---|
| 21 |
/// Implementation file for CodeBlocks Local (Project Files) Generator for CMake |
|---|
| 22 |
|
|---|
| 23 |
#include "cmGlobalCodeBlocksGenerator.h" |
|---|
| 24 |
#include "cmLocalCodeBlocksGenerator.h" |
|---|
| 25 |
#include "cmake.h" |
|---|
| 26 |
#include "cmMakefile.h" |
|---|
| 27 |
#include "cmSourceFile.h" |
|---|
| 28 |
#include "cmComputeLinkInformation.h" |
|---|
| 29 |
#include "cmTest.h" |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
using namespace codeblocksgenerator; |
|---|
| 33 |
|
|---|
| 34 |
void cmLocalCodeBlocksGenerator::Generate() |
|---|
| 35 |
{ |
|---|
| 36 |
|
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
void cmLocalCodeBlocksGenerator::ConfigureFinalPass() |
|---|
| 40 |
{ |
|---|
| 41 |
cmLocalGenerator::ConfigureFinalPass(); |
|---|
| 42 |
static_cast<cmGlobalCodeBlocksGenerator*>(GetGlobalGenerator())->gatherWorkspaceTargets( GetMakefile() ); |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
namespace codeblocksgenerator |
|---|
| 46 |
{ |
|---|
| 47 |
////////////////////////////////////// Project file ////////////////////////////////////////////////// |
|---|
| 48 |
/// Text buffer for project |
|---|
| 49 |
Buffer project; |
|---|
| 50 |
|
|---|
| 51 |
/// A map - file extenstion to folder used by writeVirtualFolders and Units |
|---|
| 52 |
std::map< std::string, std::string > virtual_folder_extension; |
|---|
| 53 |
|
|---|
| 54 |
/// Hold a search first directory from pch mode, must have build type added for each build configure. |
|---|
| 55 |
/// used by PCH and Compiler includes, points to object directory for PCH mode 1 |
|---|
| 56 |
std::string search_first_object_directory; |
|---|
| 57 |
|
|---|
| 58 |
/// Hold stripts |
|---|
| 59 |
std::vector< std::string > codeblocks_scripts; |
|---|
| 60 |
|
|---|
| 61 |
///Hold target* for dependents list |
|---|
| 62 |
std::vector< const cmTarget* > workspace_depends; |
|---|
| 63 |
|
|---|
| 64 |
bool isDepends( const std::string& sz ) |
|---|
| 65 |
{ |
|---|
| 66 |
for( size_t i=0; i<workspace_depends.size(); i++ ) |
|---|
| 67 |
{ |
|---|
| 68 |
if( sz == workspace_depends[i]->GetName() ) return true; |
|---|
| 69 |
} |
|---|
| 70 |
return false; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
///Holds the codeblocks binary directory for this generator (cmake home) |
|---|
| 74 |
std::string codeblocks_binary_directory; |
|---|
| 75 |
|
|---|
| 76 |
///Hold current build type or target type for this generator - changes for each build type. |
|---|
| 77 |
std::string current_build_type_name; |
|---|
| 78 |
|
|---|
| 79 |
///Holds the binary directory for ths project(cmake start) |
|---|
| 80 |
std::string project_binary_directory; |
|---|
| 81 |
|
|---|
| 82 |
///Hold any generated rpath for this target |
|---|
| 83 |
std::string rpath; |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
//------------------------------------ convert cmake list to strings ------------------------------------------------ |
|---|
| 87 |
/// Conver a cmake string to a vector of strings - can't use cmSystemTools |
|---|
| 88 |
void list2vector( const std::string sz, std::vector< std::string >& vector, bool clear=true ) |
|---|
| 89 |
{ |
|---|
| 90 |
if( clear )vector.clear(); |
|---|
| 91 |
|
|---|
| 92 |
size_t start = sz.find_first_not_of(" ;", 0 ); |
|---|
| 93 |
while( start != std::string::npos ) |
|---|
| 94 |
{ |
|---|
| 95 |
std::string name; |
|---|
| 96 |
size_t stop = sz.find_first_of(" ;", start ); |
|---|
| 97 |
|
|---|
| 98 |
if( stop != std::string::npos ) |
|---|
| 99 |
{ |
|---|
| 100 |
vector.push_back( sz.substr( start, stop - start )); |
|---|
| 101 |
start = sz.find_first_not_of(" ;", stop ); |
|---|
| 102 |
} |
|---|
| 103 |
else |
|---|
| 104 |
{ |
|---|
| 105 |
vector.push_back( sz.substr( start, sz.size() )); |
|---|
| 106 |
start = std::string::npos; |
|---|
| 107 |
} |
|---|
| 108 |
} |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
//------------------------------------ convert a set to cmake list ------------------------------------------------ |
|---|
| 112 |
/// Convert a set to a simi-colon cmake string |
|---|
| 113 |
void set2list( std::set< std::string >& set, std::string& result, bool clear=true ) |
|---|
| 114 |
{ |
|---|
| 115 |
if( clear )result.clear(); |
|---|
| 116 |
std::set< std::string >::iterator i = set.begin(); |
|---|
| 117 |
while( i != set.end() ) |
|---|
| 118 |
{ |
|---|
| 119 |
if( !result.empty() )result+= ';'; |
|---|
| 120 |
result += *i++; |
|---|
| 121 |
} |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
//------------------------------------ convert vector to cmake list ------------------------------------------------ |
|---|
| 125 |
/// Convert a vector to simi-colon cmake string |
|---|
| 126 |
void vector2list( const std::vector< std::string >& vector, std::string& result, bool clear=true ) |
|---|
| 127 |
{ |
|---|
| 128 |
if( clear )result.clear(); |
|---|
| 129 |
for( size_t i=0; i< vector.size(); i++ ) |
|---|
| 130 |
{ |
|---|
| 131 |
if( !result.empty() )result+= ';'; |
|---|
| 132 |
result += vector[i]; |
|---|
| 133 |
} |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
//------------------------------------ Build Section Build Target Types ------------------------------------------------ |
|---|
| 137 |
/// Get a vector of CMake build types |
|---|
| 138 |
void getBuilds( cmMakefile* mf, std::vector< std::string>& builds ) |
|---|
| 139 |
{ |
|---|
| 140 |
const char* p = mf->GetDefinition( "CMAKE_CONFIGURATION_TYPES" ); |
|---|
| 141 |
if( p ) |
|---|
| 142 |
{ |
|---|
| 143 |
std::string sz = p; |
|---|
| 144 |
list2vector( sz, builds ); |
|---|
| 145 |
} |
|---|
| 146 |
else |
|---|
| 147 |
{ |
|---|
| 148 |
builds.push_back( "RelWithDebInfo" ); //default build for cmake |
|---|
| 149 |
} |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
//------------------------------------ get a property target, global order ------------------------------------------------ |
|---|
| 155 |
/// Get a property - in target, then directory, then global - order. |
|---|
| 156 |
const char* getProperty( cmMakefile* mf, const cmTarget& target, const char* property ) |
|---|
| 157 |
{ |
|---|
| 158 |
const char* p = const_cast<cmTarget&>(target).GetProperty( property, cmProperty::TARGET ); |
|---|
| 159 |
if( !p ) p = mf->GetProperty( property, cmProperty::DIRECTORY ); |
|---|
| 160 |
// I would work up the chain of makefiles but codeblocks dosn't have sub-projects. |
|---|
| 161 |
if( !p ) p = mf->GetCMakeInstance()->GetProperty( property, cmProperty::GLOBAL ); |
|---|
| 162 |
|
|---|
| 163 |
return p; |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
const char* getArchiveOutputDirectory( cmMakefile* mf, const cmTarget& target ) |
|---|
| 167 |
{ |
|---|
| 168 |
bool in_try_compile = mf->GetCMakeInstance()->GetIsInTryCompile() != 0; |
|---|
| 169 |
|
|---|
| 170 |
const char* p = const_cast<cmTarget&>(target).GetProperty("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET ); |
|---|
| 171 |
|
|---|
| 172 |
if( !p ) |
|---|
| 173 |
{ |
|---|
| 174 |
p = mf->GetDefinition( "CMAKE_ARCHIVE_OUTPUT_DIRECTORY" ); |
|---|
| 175 |
} |
|---|
| 176 |
|
|---|
| 177 |
if( !p ) |
|---|
| 178 |
{ |
|---|
| 179 |
p = mf->GetDefinition( "LIBRARY_OUTPUT_PATH" ); |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
if( !p ) |
|---|
| 183 |
{ |
|---|
| 184 |
static std::string sz; |
|---|
| 185 |
sz = codeblocks_binary_directory; |
|---|
| 186 |
if( !in_try_compile ) |
|---|
| 187 |
{ |
|---|
| 188 |
sz += "/bin/lib"; |
|---|
| 189 |
} |
|---|
| 190 |
return sz.c_str(); |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
return p; |
|---|
| 194 |
|
|---|
| 195 |
} |
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
const char* getSharedLibraryOutputDirectory( cmMakefile* mf, const cmTarget& target ) |
|---|
| 199 |
{ |
|---|
| 200 |
|
|---|
| 201 |
static std::string sz; |
|---|
| 202 |
bool in_try_compile = mf->GetCMakeInstance()->GetIsInTryCompile() != 0; |
|---|
| 203 |
|
|---|
| 204 |
#ifdef WIN32 |
|---|
| 205 |
const char* p = mf->GetDefinition( "CMAKE_RUNTIME_OUTPUT_DIRECTORY" ); |
|---|
| 206 |
#else //Linux |
|---|
| 207 |
const char* p = mf->GetDefinition( "LIBRARY_OUTPUT_PATH" ); |
|---|
| 208 |
#endif |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
if( !p ) |
|---|
| 212 |
{ |
|---|
| 213 |
p = const_cast<cmTarget&>(target).GetProperty( "LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET ); |
|---|
| 214 |
} |
|---|
| 215 |
|
|---|
| 216 |
if( !p ) |
|---|
| 217 |
{ |
|---|
| 218 |
p = mf->GetDefinition( "CMAKE_LIBRARY_OUTPUT_DIRECTORY" ); |
|---|
| 219 |
} |
|---|
| 220 |
|
|---|
| 221 |
if( !p ) |
|---|
| 222 |
{ |
|---|
| 223 |
|
|---|
| 224 |
sz = codeblocks_binary_directory; |
|---|
| 225 |
if( !in_try_compile ) |
|---|
| 226 |
{ |
|---|
| 227 |
#ifdef WIN32 |
|---|
| 228 |
sz += "/bin"; |
|---|
| 229 |
#else //Linux |
|---|
| 230 |
sz += "/bin/lib"; |
|---|
| 231 |
#endif |
|---|
| 232 |
} |
|---|
| 233 |
} |
|---|
| 234 |
else sz = p; |
|---|
| 235 |
|
|---|
| 236 |
#ifdef WIN32 |
|---|
| 237 |
sz += '/'; |
|---|
| 238 |
sz += current_build_type_name; |
|---|
| 239 |
#endif //WIN32 |
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
return sz.c_str(); |
|---|
| 244 |
} |
|---|
| 245 |
|
|---|
| 246 |
const char* getRunTimeOutputDirectory( cmMakefile* mf, const cmTarget& target ) |
|---|
| 247 |
{ |
|---|
| 248 |
bool in_try_compile = mf->GetCMakeInstance()->GetIsInTryCompile() != 0; |
|---|
| 249 |
|
|---|
| 250 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET ); |
|---|
| 251 |
|
|---|
| 252 |
if( !p ) |
|---|
| 253 |
{ |
|---|
| 254 |
p = mf->GetDefinition( "CMAKE_RUNTIME_OUTPUT_DIRECTORY" ); |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
if( !p ) |
|---|
| 258 |
{ |
|---|
| 259 |
p = mf->GetDefinition( "EXECUTABLE_OUTPUT_PATH" ); |
|---|
| 260 |
} |
|---|
| 261 |
|
|---|
| 262 |
if( !p ) |
|---|
| 263 |
{ |
|---|
| 264 |
static std::string sz; |
|---|
| 265 |
sz = codeblocks_binary_directory; |
|---|
| 266 |
if( !in_try_compile ) |
|---|
| 267 |
{ |
|---|
| 268 |
sz += "/bin"; |
|---|
| 269 |
} |
|---|
| 270 |
return sz.c_str(); |
|---|
| 271 |
} |
|---|
| 272 |
|
|---|
| 273 |
return p; |
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
//------------------------------------ Project Header ------------------------------------------------ |
|---|
| 277 |
//Write the project header |
|---|
| 278 |
//<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> |
|---|
| 279 |
//<CodeBlocks_project_file> |
|---|
| 280 |
// <FileVersion major="1" minor="6" /> |
|---|
| 281 |
/// Write a CodeBlocks Project Header and Trailer |
|---|
| 282 |
std::string writeProjectHeader( const std::string& codeblocks_binary_directory, const std::string& name ) |
|---|
| 283 |
{ |
|---|
| 284 |
project.clear(); |
|---|
| 285 |
project << less << "?xml version=" << quote << "1.0" << quote << " encoding=" |
|---|
| 286 |
<< quote << "UTF-8" << quote << " standalone=" << quote << "yes" << quote << '?' << greater << endl; |
|---|
| 287 |
project << less << "CodeBlocks_project_file" << greater << endl; |
|---|
| 288 |
project << advance << less << "FileVersion major=" << quote << '1' << quote |
|---|
| 289 |
<< " minor=" << quote << '6' << quote << endelement << endl << retreat; |
|---|
| 290 |
project << less << '/' << "CodeBlocks_project_file" << greater << endl; |
|---|
| 291 |
|
|---|
| 292 |
std::string project_file = codeblocks_binary_directory; |
|---|
| 293 |
project_file += '/'; |
|---|
| 294 |
project_file += name; |
|---|
| 295 |
project_file += ".cbp"; |
|---|
| 296 |
project.writeBuffer( project_file ); |
|---|
| 297 |
|
|---|
| 298 |
return project_file; |
|---|
| 299 |
} |
|---|
| 300 |
|
|---|
| 301 |
//------------------------------------ Project Title ------------------------------------------------ |
|---|
| 302 |
/// Write Project Title |
|---|
| 303 |
void writeProjectTitleOption( const cmTarget& target ) |
|---|
| 304 |
{ |
|---|
| 305 |
project << advance << less << "Option title=" << quote << target.GetName() << ' '; |
|---|
| 306 |
switch( target.GetType() ) |
|---|
| 307 |
{ |
|---|
| 308 |
|
|---|
| 309 |
case cmTarget::EXECUTABLE : project << " Project"; break; |
|---|
| 310 |
case cmTarget::STATIC_LIBRARY : project << " Static Library"; break; |
|---|
| 311 |
case cmTarget::SHARED_LIBRARY : project << " Shared Library"; break; |
|---|
| 312 |
case cmTarget::MODULE_LIBRARY : project << " Module Library"; break; |
|---|
| 313 |
case cmTarget::UTILITY : project << " Utility Command"; break; |
|---|
| 314 |
case cmTarget::GLOBAL_TARGET : project << "Utility Command"; break; |
|---|
| 315 |
case cmTarget::INSTALL_FILES : project << "Install Files Project"; break; |
|---|
| 316 |
case cmTarget::INSTALL_PROGRAMS : project << "Install Programs Project"; break; |
|---|
| 317 |
case cmTarget::INSTALL_DIRECTORY : project << "Install Directories Project"; break; |
|---|
| 318 |
case cmTarget::UNKNOWN_LIBRARY : |
|---|
| 319 |
default: |
|---|
| 320 |
project << "Unknown Project Type"; break; |
|---|
| 321 |
|
|---|
| 322 |
} |
|---|
| 323 |
project << quote << endelement << endl << retreat; |
|---|
| 324 |
} |
|---|
| 325 |
|
|---|
| 326 |
//------------------------------------ Project Platforms ------------------------------------------------ |
|---|
| 327 |
/// Write Project platform Option |
|---|
| 328 |
void writePlatformsOption( cmMakefile* mf ) |
|---|
| 329 |
{ |
|---|
| 330 |
std::string platform; |
|---|
| 331 |
if( mf->IsDefinitionSet( "UNIX" ) )platform = "Unix"; |
|---|
| 332 |
else if( mf->IsDefinitionSet( "WIN32" )) platform = "Windows"; |
|---|
| 333 |
else platform = "All"; |
|---|
| 334 |
project << advance << less << "Option platform=" << quote << platform << quote << endelement << endl << retreat; |
|---|
| 335 |
} |
|---|
| 336 |
|
|---|
| 337 |
//------------------------------------ Extra Commands Target and Project and Utilities ------------------------------------------------ |
|---|
| 338 |
|
|---|
| 339 |
/// Write a custom command for project or target |
|---|
| 340 |
void writeCommands( cmMakefile* mf, const cmTarget& target, const cmCustomCommand& command, const char* label ) |
|---|
| 341 |
{ |
|---|
| 342 |
|
|---|
| 343 |
const cmCustomCommandLines& commandline = command.GetCommandLines(); |
|---|
| 344 |
|
|---|
| 345 |
for( size_t j=0; j<commandline.size(); j++ ) |
|---|
| 346 |
{ |
|---|
| 347 |
cmCustomCommandLine line = commandline[j]; |
|---|
| 348 |
if( command.GetWorkingDirectory() ) |
|---|
| 349 |
{ |
|---|
| 350 |
//must change to working codeblocks_binary_directory before command - use cmake |
|---|
| 351 |
std::string make_command = mf->GetRequiredDefinition( "CMAKE_COMMAND" ); |
|---|
| 352 |
project << advance << less << label << quote; |
|---|
| 353 |
std::string sz = command.GetWorkingDirectory(); |
|---|
| 354 |
project << make_command << " -E chdir " << sz << ' '; |
|---|
| 355 |
} |
|---|
| 356 |
else project << advance << less << label << quote; |
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
for( size_t k=0; k<line.size(); k++ ) |
|---|
| 360 |
{ |
|---|
| 361 |
if( k )project << ' '; |
|---|
| 362 |
std::string sz = line[k]; |
|---|
| 363 |
|
|---|
| 364 |
project << sz; |
|---|
| 365 |
} |
|---|
| 366 |
project << quote << endelement << endl << retreat; |
|---|
| 367 |
} |
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
} |
|---|
| 372 |
|
|---|
| 373 |
/// Write all custom commands |
|---|
| 374 |
void writeCommands( cmMakefile* mf, const cmTarget& target, std::vector<cmCustomCommand> const& commands, const char* label ) |
|---|
| 375 |
{ |
|---|
| 376 |
for( size_t i=0; i< commands.size(); i++ ) |
|---|
| 377 |
{ |
|---|
| 378 |
writeCommands( mf, target, commands[i], label ); |
|---|
| 379 |
} |
|---|
| 380 |
} |
|---|
| 381 |
|
|---|
| 382 |
/// Write pre and post build Target custom commands |
|---|
| 383 |
void writeTargetExtraCommands( cmMakefile* mf, const cmTarget& target ) |
|---|
| 384 |
{ |
|---|
| 385 |
std::vector<cmCustomCommand> const& prebuild = const_cast<cmTarget&>(target).GetPreBuildCommands(); |
|---|
| 386 |
std::vector<cmCustomCommand> const& postbuild = const_cast<cmTarget&>(target).GetPostBuildCommands(); |
|---|
| 387 |
|
|---|
| 388 |
if( !prebuild.empty() || !postbuild.empty() ) |
|---|
| 389 |
{ |
|---|
| 390 |
project << advance << "<ExtraCommands>" << endl; |
|---|
| 391 |
/// \note custom commands are found in two places in the |
|---|
| 392 |
/// target - prebuild, postbuild, prelink command are |
|---|
| 393 |
/// part of the target builds - utility commands are hung |
|---|
| 394 |
/// on a source file - the utility command has two source files |
|---|
| 395 |
/// after target.TraceDependencies( 0 ) is run, the first |
|---|
| 396 |
/// is a source file with the name of the target, |
|---|
| 397 |
/// the second source file has the name of the target.rule |
|---|
| 398 |
/// and contains the command that applies to utilities. |
|---|
| 399 |
|
|---|
| 400 |
// Check for the normal build extra commands |
|---|
| 401 |
|
|---|
| 402 |
if( !prebuild.empty() )writeCommands( mf, target, prebuild, "Add before=" ); |
|---|
| 403 |
// No pre-link for codeblocks as of 8 Feb 2009 |
|---|
| 404 |
|
|---|
| 405 |
if( !postbuild.empty() )writeCommands( mf, target, postbuild, "Add after=" ); |
|---|
| 406 |
|
|---|
| 407 |
project << less << "/ExtraCommands" << greater << endl << retreat; |
|---|
| 408 |
} |
|---|
| 409 |
} |
|---|
| 410 |
|
|---|
| 411 |
/// Write Source file custom commands |
|---|
| 412 |
void writeExtraCommands( cmMakefile* mf, const cmTarget& target ) |
|---|
| 413 |
{ |
|---|
| 414 |
|
|---|
| 415 |
// Check for the utility commands |
|---|
| 416 |
bool mode = false; |
|---|
| 417 |
std::vector<cmSourceFile*> const sources = const_cast<cmTarget&>(target).GetSourceFiles(); |
|---|
| 418 |
for( size_t i=0; i<sources.size(); i++ ) |
|---|
| 419 |
{ |
|---|
| 420 |
|
|---|
| 421 |
if( sources[i]->GetPropertyAsBool( "CODEBLOCKS_NO_GENERATE" ))continue; |
|---|
| 422 |
|
|---|
| 423 |
const cmCustomCommand* custom_command = sources[i]->GetCustomCommand(); |
|---|
| 424 |
if( custom_command ) |
|---|
| 425 |
{ |
|---|
| 426 |
project << advance << redirect; |
|---|
| 427 |
|
|---|
| 428 |
if( !mode ) |
|---|
| 429 |
{ |
|---|
| 430 |
project << advance << less << "Mode before=" << quote << "always" << quote << endelement << endl << retreat; |
|---|
| 431 |
mode = true; |
|---|
| 432 |
} |
|---|
| 433 |
writeCommands( mf, target, *custom_command, "Add before=" ); |
|---|
| 434 |
} |
|---|
| 435 |
} |
|---|
| 436 |
|
|---|
| 437 |
if( project.isHold() ) |
|---|
| 438 |
{ |
|---|
| 439 |
project << direct << "<ExtraCommands>" << endl << flush; |
|---|
| 440 |
project << less << "/ExtraCommands" << greater << endl << retreat; |
|---|
| 441 |
} |
|---|
| 442 |
else project << retreat << direct; |
|---|
| 443 |
|
|---|
| 444 |
} |
|---|
| 445 |
|
|---|
| 446 |
//------------------------------------ Target Section Utilities ------------------------------------------------ |
|---|
| 447 |
/// Write the Target Section of a CMake utility Command. |
|---|
| 448 |
void writeTargetUtility( cmMakefile* mf, const cmTarget& target ) |
|---|
| 449 |
{ |
|---|
| 450 |
project << advance << less << "Target title=" << quote << current_build_type_name << quote << greater << endl; |
|---|
| 451 |
writePlatformsOption( mf ); |
|---|
| 452 |
project << advance << less << "Option type=" << quote << "4" << quote << endelement << endl << retreat; |
|---|
| 453 |
writeExtraCommands( mf, target ); |
|---|
| 454 |
project << less << "/Target" << greater << endl << retreat; |
|---|
| 455 |
} |
|---|
| 456 |
|
|---|
| 457 |
//------------------------------------ Build Section Utilities ------------------------------------------------ |
|---|
| 458 |
/// Write the Build Section of a CMake utility Command. |
|---|
| 459 |
void writeBuildUtility( cmMakefile* mf, const cmTarget& target ) |
|---|
| 460 |
{ |
|---|
| 461 |
|
|---|
| 462 |
project << advance << less << "Build" << greater << endl; |
|---|
| 463 |
//for each build type |
|---|
| 464 |
std::vector< std::string > build; |
|---|
| 465 |
getBuilds( mf, build ); |
|---|
| 466 |
|
|---|
| 467 |
for( size_t i=0; i<build.size(); i++ ) |
|---|
| 468 |
{ |
|---|
| 469 |
current_build_type_name = build[i]; |
|---|
| 470 |
writeTargetUtility( mf, target ); |
|---|
| 471 |
} |
|---|
| 472 |
|
|---|
| 473 |
project << less << "/Build" << greater << endl << retreat; |
|---|
| 474 |
} |
|---|
| 475 |
|
|---|
| 476 |
//------------------------------------ Project Section Utilities ------------------------------------------------ |
|---|
| 477 |
/// Write the Project Section of a CMake utility Command. |
|---|
| 478 |
void writeUtilityProject( cmMakefile* mf, const cmTarget& target, const std::string& workspace_directory, const std::string& project_file ) |
|---|
| 479 |
{ |
|---|
| 480 |
project.clear(); |
|---|
| 481 |
project << less << "?xml version=" << quote << "1.0" << quote << " encoding=" |
|---|
| 482 |
<< quote << "UTF-8" << quote << " standalone=" << quote << "yes" << quote << '?' << greater << endl; |
|---|
| 483 |
project << less << "CodeBlocks_project_file" << greater << endl; |
|---|
| 484 |
project << advance << less << "FileVersion major=" << quote << '1' << quote |
|---|
| 485 |
<< " minor=" << quote << '6' << quote << endelement << endl << retreat; |
|---|
| 486 |
|
|---|
| 487 |
codeblocks_binary_directory = workspace_directory; |
|---|
| 488 |
project << advance << less << "Project" << greater << endl; |
|---|
| 489 |
writeProjectTitleOption( target ); |
|---|
| 490 |
writePlatformsOption( mf ); |
|---|
| 491 |
writeBuildUtility( mf, target ); |
|---|
| 492 |
project << less << "/Project" << greater << endl << retreat; |
|---|
| 493 |
|
|---|
| 494 |
project << less << '/' << "CodeBlocks_project_file" << greater << endl; |
|---|
| 495 |
|
|---|
| 496 |
project.writeBuffer( project_file ); |
|---|
| 497 |
} |
|---|
| 498 |
|
|---|
| 499 |
void writeCommandProject( cmMakefile* mf, const std::string& command, const std::string& title, const std::string& project_file ) |
|---|
| 500 |
{ |
|---|
| 501 |
project.clear(); |
|---|
| 502 |
project << less << "?xml version=" << quote << "1.0" << quote << " encoding=" |
|---|
| 503 |
<< quote << "UTF-8" << quote << " standalone=" << quote << "yes" << quote << '?' << greater << endl; |
|---|
| 504 |
project << less << "CodeBlocks_project_file" << greater << endl; |
|---|
| 505 |
project << advance << less << "FileVersion major=" << quote << '1' << quote |
|---|
| 506 |
<< " minor=" << quote << '6' << quote << endelement << endl << retreat; |
|---|
| 507 |
|
|---|
| 508 |
project << advance << less << "Project" << greater << endl; |
|---|
| 509 |
project << advance << less << "Option title=" << quote << title; |
|---|
| 510 |
project << quote << endelement << endl << retreat; |
|---|
| 511 |
project << advance << less << "Option platform=" << quote << "All" << quote << endelement << endl << retreat; |
|---|
| 512 |
project << advance << less << "Build" << greater << endl; |
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
// for each build type |
|---|
| 516 |
std::vector< std::string > build; |
|---|
| 517 |
getBuilds( mf, build ); |
|---|
| 518 |
|
|---|
| 519 |
for( size_t i=0; i<build.size(); i++ ) |
|---|
| 520 |
{ |
|---|
| 521 |
current_build_type_name = build[i]; |
|---|
| 522 |
project << advance << less << "Target title=" << quote << current_build_type_name << quote << greater << endl; |
|---|
| 523 |
project << advance << less << "Option platform=" << quote << "All" << quote << endelement << endl << retreat; |
|---|
| 524 |
project << advance << less << "Option type=" << quote << "4" << quote << endelement << endl << retreat; |
|---|
| 525 |
|
|---|
| 526 |
project << advance << "<ExtraCommands>" << endl << flush; |
|---|
| 527 |
project << advance << less << "Mode before=" << quote << "always" << quote << endelement << endl << retreat; |
|---|
| 528 |
project << advance << less << "Add before=" << quote; |
|---|
| 529 |
project << command; |
|---|
| 530 |
project << quote << endelement << endl << retreat; |
|---|
| 531 |
project << less << "/ExtraCommands" << greater << endl << retreat; |
|---|
| 532 |
|
|---|
| 533 |
project << less << "/Target" << greater << endl << retreat; |
|---|
| 534 |
} |
|---|
| 535 |
|
|---|
| 536 |
project << less << "/Build" << greater << endl << retreat; |
|---|
| 537 |
project << less << "/Project" << greater << endl << retreat; |
|---|
| 538 |
|
|---|
| 539 |
project << less << '/' << "CodeBlocks_project_file" << greater << endl; |
|---|
| 540 |
|
|---|
| 541 |
//if( !project.insertBuffer( "</CodeBlocks_project_file>", project_file ) ) throw program_error_insert_project(); |
|---|
| 542 |
|
|---|
| 543 |
project.writeBuffer( project_file ); |
|---|
| 544 |
|
|---|
| 545 |
} |
|---|
| 546 |
//------------------------------------ Target Section Program Parameters ------------------------------------------------ |
|---|
| 547 |
|
|---|
| 548 |
/// \note Target property CODEBLOCKS_EXECUTION_PARAMETERS sets command line prameters for executable |
|---|
| 549 |
/// under codeblocks. |
|---|
| 550 |
/// Write Execution parameters for the Target Section of a CMake Program or Library |
|---|
| 551 |
void writeExecutionParameters( cmMakefile* mf, const cmTarget& target ) |
|---|
| 552 |
{ |
|---|
| 553 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_EXECUTION_PARAMETERS", cmProperty::TARGET ); |
|---|
| 554 |
|
|---|
| 555 |
if( p ) |
|---|
| 556 |
{ |
|---|
| 557 |
if( convertTargetType( target.GetType() ) & Executable ) |
|---|
| 558 |
{ |
|---|
| 559 |
std::vector< std::string > vector; |
|---|
| 560 |
std::string sz( p ); |
|---|
| 561 |
list2vector( sz, vector ); |
|---|
| 562 |
|
|---|
| 563 |
project << advance << less << "Option parameters=" << quote; |
|---|
| 564 |
for( int i=0; i<vector.size(); ++i ) |
|---|
| 565 |
{ |
|---|
| 566 |
project << ' '; |
|---|
| 567 |
project << vector[i]; |
|---|
| 568 |
} |
|---|
| 569 |
|
|---|
| 570 |
project << quote << endelement << endl << retreat; |
|---|
| 571 |
} |
|---|
| 572 |
else |
|---|
| 573 |
{ |
|---|
| 574 |
/// \todo warning - parameters for non-executable |
|---|
| 575 |
} |
|---|
| 576 |
} |
|---|
| 577 |
} |
|---|
| 578 |
|
|---|
| 579 |
//------------------------------------ Target Section Program Console Runner ------------------------------------------------ |
|---|
| 580 |
|
|---|
| 581 |
/// \note Target property CODEBLOCKS_USE_CONSOLE_RUNNER - run a console program under codeblocks and |
|---|
| 582 |
/// wait for a key to close. |
|---|
| 583 |
|
|---|
| 584 |
/// Write Use Console Runner for the Target Section of a CMake Program |
|---|
| 585 |
void writeConsoleRunner( cmMakefile* mf, const cmTarget& target ) |
|---|
| 586 |
{ |
|---|
| 587 |
bool use_console_runner = |
|---|
| 588 |
cmSystemTools::IsOn( const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_USE_CONSOLE_RUNNER", cmProperty::TARGET )); |
|---|
| 589 |
|
|---|
| 590 |
if( use_console_runner ) |
|---|
| 591 |
{ |
|---|
| 592 |
if( convertTargetType( target.GetType() ) & Executable ) |
|---|
| 593 |
{ |
|---|
| 594 |
project << advance << less << "Option use_console_runner=" << quote << "1" << quote << endelement << endl << retreat; |
|---|
| 595 |
} |
|---|
| 596 |
else |
|---|
| 597 |
{ |
|---|
| 598 |
/// \todo warning - console runner set for non-executable |
|---|
| 599 |
} |
|---|
| 600 |
} |
|---|
| 601 |
} |
|---|
| 602 |
|
|---|
| 603 |
//------------------------------------ Target Section Program Host Application ------------------------------------------------ |
|---|
| 604 |
|
|---|
| 605 |
/// \note Target property CODEBLOCKS_HOST_APPLICATION - run this program under codeblocks for dll/shared libraries |
|---|
| 606 |
|
|---|
| 607 |
/// Write Host Application for the Target Section of a CMake Library |
|---|
| 608 |
void writeHostApplication( cmMakefile* mf, const cmTarget& target ) |
|---|
| 609 |
{ |
|---|
| 610 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_HOST_APPLICATION", cmProperty::TARGET ); |
|---|
| 611 |
|
|---|
| 612 |
if( p ) |
|---|
| 613 |
{ |
|---|
| 614 |
|
|---|
| 615 |
if( convertTargetType( target.GetType() ) & (Shared_library|Module_library) ) |
|---|
| 616 |
{ |
|---|
| 617 |
project << advance << less << "Option host_application=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 618 |
} |
|---|
| 619 |
else |
|---|
| 620 |
{ |
|---|
| 621 |
/// \todo warning - host application only effective for shared library/dll |
|---|
| 622 |
} |
|---|
| 623 |
} |
|---|
| 624 |
} |
|---|
| 625 |
|
|---|
| 626 |
//------------------------------------ Target Section Program Output Type ------------------------------------------------ |
|---|
| 627 |
/// Write Output Type for the Target Section of a CMake Program or Library |
|---|
| 628 |
void writeOutputType( cmMakefile* mf, const cmTarget& target ) |
|---|
| 629 |
{ |
|---|
| 630 |
std::string type; |
|---|
| 631 |
switch( target.GetType() ) |
|---|
| 632 |
{ |
|---|
| 633 |
case cmTarget::EXECUTABLE : type = "1"; break; |
|---|
| 634 |
case cmTarget::MODULE_LIBRARY : |
|---|
| 635 |
case cmTarget::STATIC_LIBRARY : type = "2"; break; |
|---|
| 636 |
case cmTarget::SHARED_LIBRARY : type = "3"; break; |
|---|
| 637 |
default: |
|---|
| 638 |
type = "4"; |
|---|
| 639 |
} |
|---|
| 640 |
project << advance << less << "Option type=" << quote << type << quote << endelement << endl << retreat; |
|---|
| 641 |
} |
|---|
| 642 |
|
|---|
| 643 |
//------------------------------------ Target Section Additional Outputs ------------------------------------------------ |
|---|
| 644 |
/// Write Addition file dependences for the Target Section of a CMake Program or Library |
|---|
| 645 |
void writeAdditionalOutputs( cmMakefile* mf, const cmTarget& target ) |
|---|
| 646 |
{ |
|---|
| 647 |
std::string result; |
|---|
| 648 |
|
|---|
| 649 |
// std::vector<cmCustomCommand> const& prebuild = const_cast<cmTarget&>(target).GetPreBuildCommands(); |
|---|
| 650 |
// for( size_t i=0; i<prebuild.size(); i++ ) |
|---|
| 651 |
// { |
|---|
| 652 |
// const cmCustomCommand& command = prebuild[i]; |
|---|
| 653 |
// |
|---|
| 654 |
// const cmCustomCommandLines& command_line = command.GetCommandLines(); |
|---|
| 655 |
// |
|---|
| 656 |
// for( size_t j=0; j<command_line.size(); j++ ) |
|---|
| 657 |
// { |
|---|
| 658 |
// cmCustomCommandLine line = command_line[j]; |
|---|
| 659 |
// for( size_t k=0; k<line.size(); k++ ) |
|---|
| 660 |
// { |
|---|
| 661 |
// result = line[k]; |
|---|
| 662 |
// } |
|---|
| 663 |
// } |
|---|
| 664 |
// |
|---|
| 665 |
// } |
|---|
| 666 |
|
|---|
| 667 |
// Find custom command outputs |
|---|
| 668 |
|
|---|
| 669 |
cmTargets& targets = mf->GetTargets(); |
|---|
| 670 |
cmTargets::iterator it = targets.begin(); |
|---|
| 671 |
std::string cmake_path = mf->GetHomeOutputDirectory(); |
|---|
| 672 |
|
|---|
| 673 |
while( it != targets.end() ) |
|---|
| 674 |
{ |
|---|
| 675 |
|
|---|
| 676 |
cmTarget& target = it->second; |
|---|
| 677 |
std::vector<cmSourceFile*> const sources = const_cast<cmTarget&>(target).GetSourceFiles(); |
|---|
| 678 |
for( size_t i=0; i<sources.size(); i++ ) |
|---|
| 679 |
{ |
|---|
| 680 |
|
|---|
| 681 |
if( sources[i]->GetPropertyAsBool( "CODEBLOCKS_NO_GENERATE" ))continue; |
|---|
| 682 |
|
|---|
| 683 |
const cmCustomCommand* command = sources[i]->GetCustomCommand(); |
|---|
| 684 |
if( command ) |
|---|
| 685 |
{ |
|---|
| 686 |
const cmCustomCommandLines& command_line = command->GetCommandLines(); |
|---|
| 687 |
for( size_t j=0; j<command_line.size(); j++ ) |
|---|
| 688 |
{ |
|---|
| 689 |
cmCustomCommandLine line = command_line[j]; |
|---|
| 690 |
for( size_t k=0; k<line.size(); k++ ) |
|---|
| 691 |
{ |
|---|
| 692 |
std::string param =line[k]; |
|---|
| 693 |
if( param.find( cmake_path ) != std::string::npos ) |
|---|
| 694 |
{ |
|---|
| 695 |
size_t ix = param.find( codeblocks_binary_directory ); |
|---|
| 696 |
if( ix != 0 && ix != std::string::npos ) |
|---|
| 697 |
{ |
|---|
| 698 |
//remove flags |
|---|
| 699 |
param.erase( 0, ix ); |
|---|
| 700 |
} |
|---|
| 701 |
if( !result.empty() )result += ';'; |
|---|
| 702 |
result += param; |
|---|
| 703 |
} |
|---|
| 704 |
|
|---|
| 705 |
} |
|---|
| 706 |
} |
|---|
| 707 |
} |
|---|
| 708 |
|
|---|
| 709 |
} |
|---|
| 710 |
it++; |
|---|
| 711 |
} |
|---|
| 712 |
|
|---|
| 713 |
if( !result.empty() ) |
|---|
| 714 |
{ |
|---|
| 715 |
project << advance << less << "Option additional_output=" << quote << result << quote << endelement << endl << retreat; |
|---|
| 716 |
} |
|---|
| 717 |
} |
|---|
| 718 |
|
|---|
| 719 |
//------------------------------------ Target Section External Dependencies ------------------------------------------------ |
|---|
| 720 |
/// Write external file dependencies |
|---|
| 721 |
void writeExternalDependencies( cmMakefile* mf, const cmTarget& target ) |
|---|
| 722 |
{ |
|---|
| 723 |
// Find dependent projects and add there output files |
|---|
| 724 |
// add output names for each project in our workspace |
|---|
| 725 |
std::set< std::string > heap; |
|---|
| 726 |
|
|---|
| 727 |
if( !workspace_depends.empty() ) |
|---|
| 728 |
{ |
|---|
| 729 |
std::string result; |
|---|
| 730 |
for( size_t i=0; i<workspace_depends.size(); i++ ) |
|---|
| 731 |
{ |
|---|
| 732 |
std::string name = const_cast<cmTarget*>(workspace_depends[i])->GetFullPath( current_build_type_name.c_str() ); |
|---|
| 733 |
// if( current_build_type_name == "Debug" ) |
|---|
| 734 |
// { |
|---|
| 735 |
// //Our libraries add a debug DEBUG_POSTFIX |
|---|
| 736 |
// std::string postfix; |
|---|
| 737 |
// const char* p = const_cast<cmTarget&>(target).GetProperty( "DEBUG_POSTFIX", cmProperty::TARGET ); |
|---|
| 738 |
// if( !p )postfix = "_d"; // Default |
|---|
| 739 |
// else postfix = p; |
|---|
| 740 |
// |
|---|
| 741 |
// size_t ix = name.rfind( '.' ); |
|---|
| 742 |
// if( ix != std::string::npos ) |
|---|
| 743 |
// { |
|---|
| 744 |
// name.insert( ix, postfix ); |
|---|
| 745 |
// } |
|---|
| 746 |
// else |
|---|
| 747 |
// { |
|---|
| 748 |
// //warning building a library with no extension? |
|---|
| 749 |
// name += postfix; |
|---|
| 750 |
// } |
|---|
| 751 |
// } |
|---|
| 752 |
|
|---|
| 753 |
heap.insert( name ); |
|---|
| 754 |
} |
|---|
| 755 |
|
|---|
| 756 |
std::set< std::string >::iterator it = heap.begin(); |
|---|
| 757 |
while( it != heap.end() ) |
|---|
| 758 |
{ |
|---|
| 759 |
if( !result.empty() ) result += ';'; |
|---|
| 760 |
std::string path = *it++; |
|---|
| 761 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), path.c_str() ); |
|---|
| 762 |
result += rel_path; |
|---|
| 763 |
} |
|---|
| 764 |
|
|---|
| 765 |
if ( !result.empty() ) |
|---|
| 766 |
{ |
|---|
| 767 |
project << advance << less << "Option external_deps=" << quote << result << quote << endelement << endl << retreat; |
|---|
| 768 |
} |
|---|
| 769 |
} |
|---|
| 770 |
} |
|---|
| 771 |
|
|---|
| 772 |
//------------------------------------ Target Section Objects ------------------------------------------------ |
|---|
| 773 |
/// Write directory for objects |
|---|
| 774 |
/// |
|---|
| 775 |
// Object output directory = project_file - project.cbp + build |
|---|
| 776 |
void writeObjectOutput( cmMakefile* mf, const cmTarget& target ) |
|---|
| 777 |
{ |
|---|
| 778 |
std::string output = project_binary_directory; |
|---|
| 779 |
output += current_build_type_name; |
|---|
| 780 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), output.c_str() ); |
|---|
| 781 |
project << advance << less << "Option object_output=" << quote << rel_path << quote << endelement << endl << retreat; |
|---|
| 782 |
} |
|---|
| 783 |
|
|---|
| 784 |
//------------------------------------ Target Section Workin Directory ------------------------------------------------ |
|---|
| 785 |
/// Write the executable working directory |
|---|
| 786 |
void writeWorkingDirectory( cmMakefile* mf, const cmTarget& target ) |
|---|
| 787 |
{ |
|---|
| 788 |
std::string path; |
|---|
| 789 |
path = codeblocks_binary_directory + "/bin/" + current_build_type_name; |
|---|
| 790 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), path.c_str() ); |
|---|
| 791 |
project << advance << less << "Option working_dir=" << quote << rel_path << quote << endelement << endl << retreat; |
|---|
| 792 |
} |
|---|
| 793 |
|
|---|
| 794 |
//------------------------------------ Target Section Program Output Executable Target------------------------------------------------ |
|---|
| 795 |
/// Write the output file name and path |
|---|
| 796 |
void writeOutputExecitable( cmMakefile* mf, const cmTarget& target ) |
|---|
| 797 |
{ |
|---|
| 798 |
std::string name = target.GetName(); |
|---|
| 799 |
std::string result; |
|---|
| 800 |
// std::string result = const_cast<cmTarget&>(target).GetFullPath(current_build_type_name.c_str()); |
|---|
| 801 |
|
|---|
| 802 |
bool in_try_compile = mf->GetCMakeInstance()->GetIsInTryCompile() != 0; |
|---|
| 803 |
|
|---|
| 804 |
std::string execution_output_path = getRunTimeOutputDirectory( mf, target ); |
|---|
| 805 |
//Check if a test program. |
|---|
| 806 |
std::map<cmStdString, cmTest*>& tests = mf->GetTests(); |
|---|
| 807 |
|
|---|
| 808 |
if( mf->GetCMakeInstance()->GetIsInTryCompile() != 0 ) |
|---|
| 809 |
{ |
|---|
| 810 |
result = name; |
|---|
| 811 |
} |
|---|
| 812 |
else if( !tests.empty() ) |
|---|
| 813 |
{ |
|---|
| 814 |
std::map<cmStdString, cmTest*>::iterator i = tests.begin(); |
|---|
| 815 |
while( i != tests.end() ) |
|---|
| 816 |
{ |
|---|
| 817 |
std::vector<std::string> const& command = i->second->GetCommand(); |
|---|
| 818 |
if( !command.empty() ) |
|---|
| 819 |
{ |
|---|
| 820 |
std::string test_name = command[0]; |
|---|
| 821 |
size_t ix = test_name.rfind( name ); |
|---|
| 822 |
if( ix != std::string::npos ) |
|---|
| 823 |
{ |
|---|
| 824 |
test_name.insert( ix, "$(TARGET_NAME)/" ); |
|---|
| 825 |
result = test_name; |
|---|
| 826 |
break; |
|---|
| 827 |
} |
|---|
| 828 |
} |
|---|
| 829 |
i++; |
|---|
| 830 |
} |
|---|
| 831 |
} |
|---|
| 832 |
|
|---|
| 833 |
|
|---|
| 834 |
if( result.empty() ) |
|---|
| 835 |
{ |
|---|
| 836 |
if( execution_output_path.length() > 0 )result = execution_output_path += '/'; |
|---|
| 837 |
|
|---|
| 838 |
result += current_build_type_name + '/' + name; |
|---|
| 839 |
|
|---|
| 840 |
} |
|---|
| 841 |
|
|---|
| 842 |
std::string rel_path; |
|---|
| 843 |
if( in_try_compile ) |
|---|
| 844 |
{ |
|---|
| 845 |
rel_path = result; |
|---|
| 846 |
} |
|---|
| 847 |
else |
|---|
| 848 |
{ |
|---|
| 849 |
rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), result.c_str() ); |
|---|
| 850 |
} |
|---|
| 851 |
|
|---|
| 852 |
|
|---|
| 853 |
project << advance << less << "Option output=" << quote << rel_path << quote |
|---|
| 854 |
<< " prefix_auto=" << quote<< '1' << quote |
|---|
| 855 |
<< " extension_auto=" << quote << '1' << quote |
|---|
| 856 |
<< endelement << endl << retreat; |
|---|
| 857 |
|
|---|
| 858 |
|
|---|
| 859 |
} |
|---|
| 860 |
|
|---|
| 861 |
//------------------------------------ Target Section Program Output Static Target------------------------------------------------ |
|---|
| 862 |
|
|---|
| 863 |
/// Write the output file name and path |
|---|
| 864 |
void writeOutputStaticLibrary( cmMakefile* mf, const cmTarget& target ) |
|---|
| 865 |
{ |
|---|
| 866 |
|
|---|
| 867 |
std::string name = target.GetName(); |
|---|
| 868 |
std::string result; |
|---|
| 869 |
// std::string result = const_cast<cmTarget&>(target).GetFullPath(current_build_type_name.c_str()); |
|---|
| 870 |
|
|---|
| 871 |
bool in_try_compile = mf->GetCMakeInstance()->GetIsInTryCompile() != 0; |
|---|
| 872 |
|
|---|
| 873 |
|
|---|
| 874 |
if( current_build_type_name == "Debug" && !in_try_compile ) |
|---|
| 875 |
{ |
|---|
| 876 |
std::string postfix; |
|---|
| 877 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "DEBUG_POSTFIX", cmProperty::TARGET ); |
|---|
| 878 |
if( !p )postfix = "_d"; // Default |
|---|
| 879 |
else postfix = p; |
|---|
| 880 |
name += postfix; |
|---|
| 881 |
} |
|---|
| 882 |
|
|---|
| 883 |
std::string libaray_output_path = getArchiveOutputDirectory( mf, target ); |
|---|
| 884 |
|
|---|
| 885 |
if( libaray_output_path.length() > 0 )result = libaray_output_path + '/'; //else will put it in the top directory |
|---|
| 886 |
|
|---|
| 887 |
result += name; |
|---|
| 888 |
|
|---|
| 889 |
if( !result.empty() ) |
|---|
| 890 |
{ |
|---|
| 891 |
|
|---|
| 892 |
std::string rel_path; |
|---|
| 893 |
if( in_try_compile ) |
|---|
| 894 |
{ |
|---|
| 895 |
rel_path = result; |
|---|
| 896 |
} |
|---|
| 897 |
else |
|---|
| 898 |
{ |
|---|
| 899 |
rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), result.c_str() ); |
|---|
| 900 |
} |
|---|
| 901 |
|
|---|
| 902 |
|
|---|
| 903 |
project << advance << less << "Option output=" << quote << rel_path << quote |
|---|
| 904 |
<< " prefix_auto=" << quote<< '1' << quote |
|---|
| 905 |
<< " extension_auto=" << quote << '1' << quote |
|---|
| 906 |
<< endelement << endl << retreat; |
|---|
| 907 |
} |
|---|
| 908 |
|
|---|
| 909 |
|
|---|
| 910 |
|
|---|
| 911 |
} |
|---|
| 912 |
//------------------------------------ Target Section Program Output Shared Target------------------------------------------------ |
|---|
| 913 |
|
|---|
| 914 |
/// Write the output file name and path |
|---|
| 915 |
void writeOutputSharedLibrary( cmMakefile* mf, const cmTarget& target ) |
|---|
| 916 |
{ |
|---|
| 917 |
|
|---|
| 918 |
std::string name = target.GetName(); |
|---|
| 919 |
std::string result; |
|---|
| 920 |
// std::string result = const_cast<cmTarget&>(target).GetFullPath(current_build_type_name.c_str()); |
|---|
| 921 |
|
|---|
| 922 |
bool in_try_compile = mf->GetCMakeInstance()->GetIsInTryCompile() != 0; |
|---|
| 923 |
|
|---|
| 924 |
char prefix = '1'; |
|---|
| 925 |
|
|---|
| 926 |
if( current_build_type_name == "Debug" && !in_try_compile ) |
|---|
| 927 |
{ |
|---|
| 928 |
std::string postfix; |
|---|
| 929 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "DEBUG_POSTFIX", cmProperty::TARGET ); |
|---|
| 930 |
if( !p )postfix = "_d"; // Default |
|---|
| 931 |
else postfix = p; |
|---|
| 932 |
name += postfix; |
|---|
| 933 |
} |
|---|
| 934 |
|
|---|
| 935 |
std::string libaray_output_path = getSharedLibraryOutputDirectory( mf, target ); |
|---|
| 936 |
|
|---|
| 937 |
if( libaray_output_path.length() > 0 )result = libaray_output_path + '/'; |
|---|
| 938 |
|
|---|
| 939 |
if(convertTargetType( target.GetType()) & (Shared_library|Module_library) ) |
|---|
| 940 |
{ |
|---|
| 941 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "PREFIX", cmProperty::TARGET ); |
|---|
| 942 |
if( !p ) |
|---|
| 943 |
{ |
|---|
| 944 |
p = mf->GetDefinition("CMAKE_SHARED_LIBRARY_PREFIX"); |
|---|
| 945 |
} |
|---|
| 946 |
if( p ) |
|---|
| 947 |
{ |
|---|
| 948 |
result += p; |
|---|
| 949 |
prefix = '0'; |
|---|
| 950 |
} |
|---|
| 951 |
else prefix = '1'; |
|---|
| 952 |
} |
|---|
| 953 |
|
|---|
| 954 |
if( !result.empty() ) |
|---|
| 955 |
{ |
|---|
| 956 |
|
|---|
| 957 |
result += name; |
|---|
| 958 |
|
|---|
| 959 |
std::string rel_path; |
|---|
| 960 |
if( in_try_compile ) |
|---|
| 961 |
{ |
|---|
| 962 |
rel_path = result; |
|---|
| 963 |
} |
|---|
| 964 |
else |
|---|
| 965 |
{ |
|---|
| 966 |
rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), result.c_str() ); |
|---|
| 967 |
} |
|---|
| 968 |
|
|---|
| 969 |
|
|---|
| 970 |
project << advance << less << "Option output=" << quote << rel_path << quote |
|---|
| 971 |
<< " prefix_auto=" << quote<< prefix << quote |
|---|
| 972 |
<< " extension_auto=" << quote << '1' << quote |
|---|
| 973 |
<< endelement << endl << retreat; |
|---|
| 974 |
} |
|---|
| 975 |
|
|---|
| 976 |
|
|---|
| 977 |
|
|---|
| 978 |
|
|---|
| 979 |
} |
|---|
| 980 |
|
|---|
| 981 |
|
|---|
| 982 |
// --------------------------------------rpath----------------------------------------------------- |
|---|
| 983 |
|
|---|
| 984 |
|
|---|
| 985 |
void storeRPath( cmMakefile* mf, const cmTarget& target ) |
|---|
| 986 |
{ |
|---|
| 987 |
//CMAKE_SKIP_BUILD_RPATH |
|---|
| 988 |
if( cmSystemTools::IsOn( mf->GetDefinition( "CMAKE_SKIP_BUILD_RPATH" )) )return; |
|---|
| 989 |
|
|---|
| 990 |
if( cmSystemTools::IsOn( mf->GetDefinition( "CMAKE_BUILD_WITH_INSTALL_RPATH" )) ) |
|---|
| 991 |
{ |
|---|
| 992 |
const char* p = mf->GetDefinition( "CMAKE_BUILD_WITH_INSTALL_RPATH" ); |
|---|
| 993 |
if( p )rpath = p; |
|---|
| 994 |
return; |
|---|
| 995 |
} |
|---|
| 996 |
|
|---|
| 997 |
cmComputeLinkInformation* li = const_cast<cmTarget&>(target).GetLinkInformation( current_build_type_name.c_str() ); |
|---|
| 998 |
if( !li ) return; |
|---|
| 999 |
|
|---|
| 1000 |
std::string sz = li->GetRPathString( false ); |
|---|
| 1001 |
if( !sz.empty() ) |
|---|
| 1002 |
{ |
|---|
| 1003 |
rpath = li->GetRuntimeFlag(); |
|---|
| 1004 |
rpath += sz; |
|---|
| 1005 |
} |
|---|
| 1006 |
} |
|---|
| 1007 |
|
|---|
| 1008 |
//------------------------------------ Target Section Program Output ------------------------------------------------ |
|---|
| 1009 |
|
|---|
| 1010 |
/// Write the output file name and path |
|---|
| 1011 |
void writeOutput( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1012 |
{ |
|---|
| 1013 |
|
|---|
| 1014 |
if( convertTargetType( target.GetType()) & ( Shared_library|Module_library) ) |
|---|
| 1015 |
{ |
|---|
| 1016 |
storeRPath( mf, target ); |
|---|
| 1017 |
writeOutputSharedLibrary( mf, target ); |
|---|
| 1018 |
} |
|---|
| 1019 |
else if( convertTargetType( target.GetType()) & Static_library ) |
|---|
| 1020 |
{ |
|---|
| 1021 |
writeOutputStaticLibrary( mf, target ); |
|---|
| 1022 |
} |
|---|
| 1023 |
else if( convertTargetType( target.GetType() ) & Executable ) |
|---|
| 1024 |
{ |
|---|
| 1025 |
storeRPath( mf, target ); |
|---|
| 1026 |
writeOutputExecitable( mf, target ); |
|---|
| 1027 |
} |
|---|
| 1028 |
else |
|---|
| 1029 |
{ |
|---|
| 1030 |
/// \todo error in program - lost build type |
|---|
| 1031 |
} |
|---|
| 1032 |
|
|---|
| 1033 |
} |
|---|
| 1034 |
|
|---|
| 1035 |
|
|---|
| 1036 |
|
|---|
| 1037 |
//------------------------------------ Target Section Create Def File ------------------------------------------------ |
|---|
| 1038 |
|
|---|
| 1039 |
/// \note Target property CODEBLOCKS_CREATE_DEF_FILE creates a def file for the windows linker. |
|---|
| 1040 |
/// Write a def file for windows dlls |
|---|
| 1041 |
void writeCreateDEFFile( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1042 |
{ |
|---|
| 1043 |
bool create_def_file = |
|---|
| 1044 |
cmSystemTools::IsOn( const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_CREATE_DEF_FILE", cmProperty::TARGET )); |
|---|
| 1045 |
|
|---|
| 1046 |
if( create_def_file ) |
|---|
| 1047 |
{ |
|---|
| 1048 |
if( convertTargetType( target.GetType() ) & (Shared_library|Module_library) ) |
|---|
| 1049 |
{ |
|---|
| 1050 |
project << advance << less << "Option createDefFile=" << quote << "1" << quote << endelement << endl << retreat; |
|---|
| 1051 |
} |
|---|
| 1052 |
else |
|---|
| 1053 |
{ |
|---|
| 1054 |
/// \todo warning - property only meaningful for a dll under windows - no warning unde linux - |
|---|
| 1055 |
} |
|---|
| 1056 |
} |
|---|
| 1057 |
} |
|---|
| 1058 |
|
|---|
| 1059 |
//------------------------------------ Target Section Create Import Library ------------------------------------------------ |
|---|
| 1060 |
|
|---|
| 1061 |
/// \note Target property CODEBLOCKS_CREATE_IMPORT_LIBRARY - create an import library for the windows linker |
|---|
| 1062 |
|
|---|
| 1063 |
/// Write an import library for windows dlls |
|---|
| 1064 |
void writeCreateImportLibrary( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1065 |
{ |
|---|
| 1066 |
bool create_import_library = |
|---|
| 1067 |
cmSystemTools::IsOn( const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_CREATE_IMPORT_LIBRARY", cmProperty::TARGET )); |
|---|
| 1068 |
|
|---|
| 1069 |
if( create_import_library ) |
|---|
| 1070 |
{ |
|---|
| 1071 |
if( convertTargetType( target.GetType() ) & (Shared_library|Module_library) ) |
|---|
| 1072 |
{ |
|---|
| 1073 |
project << advance << less << "Option createStaticLib=" << quote << "1" << quote << endelement << endl << retreat; |
|---|
| 1074 |
} |
|---|
| 1075 |
else |
|---|
| 1076 |
{ |
|---|
| 1077 |
/// \todo warning - property only meaningful for a dll under windows - no warning unde linux - |
|---|
| 1078 |
} |
|---|
| 1079 |
} |
|---|
| 1080 |
} |
|---|
| 1081 |
|
|---|
| 1082 |
//------------------------------------ Target Section Compiler Relation ------------------------------------------------ |
|---|
| 1083 |
/// \note Target property CODEBLOCKS_COMPILER_OPTIONS_PRIORITY sets the relative order/priority of link directories, |
|---|
| 1084 |
/// The meaning in CMake is between makefile settings and build type settings. |
|---|
| 1085 |
/// - not supported by CMake and will lead to different builds between this local generator and the main local generator. |
|---|
| 1086 |
|
|---|
| 1087 |
/// Write a priority value for Compiler Options |
|---|
| 1088 |
void writeCompilerRelation( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1089 |
{ |
|---|
| 1090 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_COMPILER_OPTIONS_PRIORITY", cmProperty::TARGET ); |
|---|
| 1091 |
if( p ) |
|---|
| 1092 |
{ |
|---|
| 1093 |
project << advance << less << "Option projectompilerOptionsRelation=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1094 |
} |
|---|
| 1095 |
} |
|---|
| 1096 |
|
|---|
| 1097 |
//------------------------------------ Target Section Linker Relation ------------------------------------------------ |
|---|
| 1098 |
/// \note Target property CODEBLOCKS_LINKER_OPTIONS_PRIORITY sets the relative order/priority of link directories, |
|---|
| 1099 |
/// The meaning in CMake is betwen makefile settings and build type settings. |
|---|
| 1100 |
/// - not supported by CMake and will lead to different builds between this generator and the main generator. |
|---|
| 1101 |
|
|---|
| 1102 |
/// Write a priority value Linker Options |
|---|
| 1103 |
void writeLinkerOptionRelation( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1104 |
{ |
|---|
| 1105 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_LINKER_OPTIONS_PRIORITY", cmProperty::TARGET ); |
|---|
| 1106 |
if( p ) |
|---|
| 1107 |
{ |
|---|
| 1108 |
project << advance << less << "Option projectLinkerOptionsRelation=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1109 |
} |
|---|
| 1110 |
} |
|---|
| 1111 |
|
|---|
| 1112 |
//------------------------------------ Target Section Compiler Includes Relation ------------------------------------------------ |
|---|
| 1113 |
/// \note Target property CODEBLOCKS_COMPILER_INCLUDES_PRIORITY sets the relative order/priority of link directories, |
|---|
| 1114 |
/// The meaning in CMake is betwen makefile settings and build type settings. |
|---|
| 1115 |
/// - not supported by CMake and will lead to different builds between this generator and the main generator. |
|---|
| 1116 |
|
|---|
| 1117 |
/// Write a priority value Compiler Includes Options |
|---|
| 1118 |
void writeIncludeDirectoryRelation( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1119 |
{ |
|---|
| 1120 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_COMPILER_INCLUDES_PRIORITY", cmProperty::TARGET ); |
|---|
| 1121 |
if( p ) |
|---|
| 1122 |
{ |
|---|
| 1123 |
project << advance << less << "Option projectIncludeDirsRelation=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1124 |
} |
|---|
| 1125 |
} |
|---|
| 1126 |
|
|---|
| 1127 |
//------------------------------------ Target Section Resource Compiler Includes Relation ------------------------------------------------ |
|---|
| 1128 |
/// \note Target property CODEBLOCKS_RESOURCE_INCLUDES_PRIORITY sets the relative order/priority of link directories, |
|---|
| 1129 |
/// The meaning in CMake is betwen makefile settings and build type settings. |
|---|
| 1130 |
/// - not supported by CMake and will lead to different builds between this generator and the main generator. |
|---|
| 1131 |
|
|---|
| 1132 |
/// Write a pirority value for Resource Includes Option |
|---|
| 1133 |
void writeResourceIncludeDirectoryRelation( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1134 |
{ |
|---|
| 1135 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_RESOURCE_INCLUDES_PRIORITY", cmProperty::TARGET ); |
|---|
| 1136 |
if( p ) |
|---|
| 1137 |
{ |
|---|
| 1138 |
project << advance << less << "Option projectResourceIncludeDirsRelation=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1139 |
} |
|---|
| 1140 |
} |
|---|
| 1141 |
|
|---|
| 1142 |
//------------------------------------ Target Section Linker Includes Relation ------------------------------------------------ |
|---|
| 1143 |
/// \note Target property CODEBLOCKS_LINKER_INCLUDES_PRIORITY sets the relative order/priority of link directories, |
|---|
| 1144 |
/// The meaning in CMake is between makefile settings and build type settings. |
|---|
| 1145 |
/// - not supported by CMake and will lead to different builds between this generator and the main generator. |
|---|
| 1146 |
|
|---|
| 1147 |
/// Write a priority value for Linker Include Options |
|---|
| 1148 |
void writeLibraryDirectoryRelation( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1149 |
{ |
|---|
| 1150 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_LINKER_INCLUDES_PRIORITY", cmProperty::TARGET ); |
|---|
| 1151 |
if( p ) |
|---|
| 1152 |
{ |
|---|
| 1153 |
project << advance << less << "Option projectLibDirsRelation=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1154 |
} |
|---|
| 1155 |
} |
|---|
| 1156 |
|
|---|
| 1157 |
//------------------------------------ Target Section Scripts ------------------------------------------------ |
|---|
| 1158 |
|
|---|
| 1159 |
/// \note Target property CODEBLOCKS_SCRIPT - run a target level codeblocks script |
|---|
| 1160 |
|
|---|
| 1161 |
/// Add any CodeBlocks scripts to a Target |
|---|
| 1162 |
void writeTargetScripts( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1163 |
{ |
|---|
| 1164 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_SCRIPT", cmProperty::TARGET ); |
|---|
| 1165 |
|
|---|
| 1166 |
if( p ) |
|---|
| 1167 |
{ |
|---|
| 1168 |
std::string script = p; |
|---|
| 1169 |
codeblocks_scripts.push_back( script ); |
|---|
| 1170 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), script.c_str() ); |
|---|
| 1171 |
project << advance << less << "Script file=" << quote << rel_path << quote << endelement << endl << retreat; |
|---|
| 1172 |
} |
|---|
| 1173 |
} |
|---|
| 1174 |
|
|---|
| 1175 |
//------------------------------------ Target Section Compiler Options ------------------------------------------------ |
|---|
| 1176 |
|
|---|
| 1177 |
/// Write target level compiler options and defines |
|---|
| 1178 |
void writeTargetCompilerOptions( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1179 |
{ |
|---|
| 1180 |
|
|---|
| 1181 |
std::set< cmStdString > languages; |
|---|
| 1182 |
target.GetLanguages( languages ); |
|---|
| 1183 |
std::string build = cmSystemTools::UpperCase( current_build_type_name ); |
|---|
| 1184 |
std::set< cmStdString >::iterator it = languages.begin(); |
|---|
| 1185 |
std::string tag; |
|---|
| 1186 |
while( it != languages.end() ) |
|---|
| 1187 |
{ |
|---|
| 1188 |
std::string result; |
|---|
| 1189 |
tag = "CMAKE_"; |
|---|
| 1190 |
tag += *it; |
|---|
| 1191 |
tag += "_FLAGS_"; |
|---|
| 1192 |
tag += build; |
|---|
| 1193 |
|
|---|
| 1194 |
const char* p = mf->GetDefinition( tag.c_str() ); |
|---|
| 1195 |
if( p && strlen(p) > 0 )result += p; |
|---|
| 1196 |
|
|---|
| 1197 |
if( convertTargetType( target.GetType() ) & Shared_library ) |
|---|
| 1198 |
{ |
|---|
| 1199 |
tag = "CMAKE_SHARED_LIBRARY_"; |
|---|
| 1200 |
tag += *it; |
|---|
| 1201 |
tag += "_FLAGS_"; |
|---|
| 1202 |
tag += build; |
|---|
| 1203 |
|
|---|
| 1204 |
p = mf->GetDefinition( tag.c_str() ); |
|---|
| 1205 |
if( p && strlen(p) > 0 ) |
|---|
| 1206 |
{ |
|---|
| 1207 |
result += ' '; |
|---|
| 1208 |
result += p; |
|---|
| 1209 |
} |
|---|
| 1210 |
} |
|---|
| 1211 |
|
|---|
| 1212 |
if( convertTargetType( target.GetType() ) & Module_library ) |
|---|
| 1213 |
{ |
|---|
| 1214 |
tag = "CMAKE_MODULE_LIBRARY_"; |
|---|
| 1215 |
tag += *it; |
|---|
| 1216 |
tag += "_FLAGS_"; |
|---|
| 1217 |
tag += build; |
|---|
| 1218 |
|
|---|
| 1219 |
p = mf->GetDefinition( tag.c_str() ); |
|---|
| 1220 |
if( p && strlen(p) > 0 ) |
|---|
| 1221 |
{ |
|---|
| 1222 |
result += ' '; |
|---|
| 1223 |
result += p; |
|---|
| 1224 |
} |
|---|
| 1225 |
|
|---|
| 1226 |
} |
|---|
| 1227 |
|
|---|
| 1228 |
|
|---|
| 1229 |
std::vector<std::string> flags; |
|---|
| 1230 |
list2vector( result, flags ); |
|---|
| 1231 |
for( size_t i=0; i<flags.size(); i++ ) |
|---|
| 1232 |
{ |
|---|
| 1233 |
project << advance << less << "Add option=" << quote << flags[i] << quote << endelement << endl << retreat; |
|---|
| 1234 |
} |
|---|
| 1235 |
|
|---|
| 1236 |
|
|---|
| 1237 |
|
|---|
| 1238 |
bool in_try_compile = mf->GetCMakeInstance()->GetIsInTryCompile() != 0; |
|---|
| 1239 |
if( !in_try_compile ) //Used for something else in try compile. |
|---|
| 1240 |
{ |
|---|
| 1241 |
|
|---|
| 1242 |
|
|---|
| 1243 |
/// Common define flags in a CMake project |
|---|
| 1244 |
tag = "COMPILE_DEFINITIONS_"; |
|---|
| 1245 |
tag += build; |
|---|
| 1246 |
|
|---|
| 1247 |
|
|---|
| 1248 |
p = mf->GetProperty(tag.c_str(), cmProperty::DIRECTORY ); |
|---|
| 1249 |
if( p ) |
|---|
| 1250 |
{ |
|---|
| 1251 |
std::string sz = p; |
|---|
| 1252 |
std::vector< std::string > flags; |
|---|
| 1253 |
list2vector( sz, flags ); |
|---|
| 1254 |
project << advance << less << "Add option=" << quote; |
|---|
| 1255 |
for( size_t i =0; i<flags.size(); i++ ) |
|---|
| 1256 |
{ |
|---|
| 1257 |
if( i ) project << ' '; |
|---|
| 1258 |
project << "-D"; |
|---|
| 1259 |
project << flags[i]; |
|---|
| 1260 |
} |
|---|
| 1261 |
|
|---|
| 1262 |
project << quote << endelement << endl << retreat; |
|---|
| 1263 |
} |
|---|
| 1264 |
|
|---|
| 1265 |
p = const_cast<cmTarget&>(target).GetProperty(tag.c_str(), cmProperty::TARGET); |
|---|
| 1266 |
if( p ) |
|---|
| 1267 |
{ |
|---|
| 1268 |
std::string sz = p; |
|---|
| 1269 |
std::vector< std::string > flags; |
|---|
| 1270 |
list2vector( sz, flags ); |
|---|
| 1271 |
project << advance << less << "Add option=" << quote; |
|---|
| 1272 |
for( size_t i =0; i<flags.size(); i++ ) |
|---|
| 1273 |
{ |
|---|
| 1274 |
if( i ) project << ' '; |
|---|
| 1275 |
project << "-D"; |
|---|
| 1276 |
project << flags[i]; |
|---|
| 1277 |
} |
|---|
| 1278 |
|
|---|
| 1279 |
project << quote << endelement << endl << retreat; |
|---|
| 1280 |
|
|---|
| 1281 |
} |
|---|
| 1282 |
} |
|---|
| 1283 |
|
|---|
| 1284 |
|
|---|
| 1285 |
it++; //Next language? |
|---|
| 1286 |
} |
|---|
| 1287 |
|
|---|
| 1288 |
} |
|---|
| 1289 |
|
|---|
| 1290 |
//------------------------------------ Target Section Compiler Includes Options ------------------------------------------------ |
|---|
| 1291 |
/// Write Target level includes |
|---|
| 1292 |
void writeTargetAddCompilerDirectories( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1293 |
{ |
|---|
| 1294 |
/// \note CMake assumes that includes go with any target in the project file |
|---|
| 1295 |
} |
|---|
| 1296 |
|
|---|
| 1297 |
//------------------------------------ Target Section Compiler ------------------------------------------------ |
|---|
| 1298 |
|
|---|
| 1299 |
void writeTargetCompilerSettings( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1300 |
{ |
|---|
| 1301 |
project << redirect << advance; |
|---|
| 1302 |
writeTargetCompilerOptions( mf, target ); |
|---|
| 1303 |
writeTargetAddCompilerDirectories( mf, target ); |
|---|
| 1304 |
if( project.isHold() ) |
|---|
| 1305 |
{ |
|---|
| 1306 |
project << retreat << direct << advance << less << "Compiler" << greater << endl << flush; |
|---|
| 1307 |
project << less << '/' << "Compiler" << greater << endl << retreat; |
|---|
| 1308 |
} |
|---|
| 1309 |
else project << retreat << direct; |
|---|
| 1310 |
} |
|---|
| 1311 |
|
|---|
| 1312 |
//------------------------------------ Target Section Linker Options ------------------------------------------------ |
|---|
| 1313 |
|
|---|
| 1314 |
void writeTargetLinkerOptions( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1315 |
{ |
|---|
| 1316 |
std::set< cmStdString > languages; |
|---|
| 1317 |
std::string build = cmSystemTools::UpperCase( current_build_type_name ); |
|---|
| 1318 |
std::string tag; |
|---|
| 1319 |
|
|---|
| 1320 |
|
|---|
| 1321 |
tag = "LINK_FLAGS_"; |
|---|
| 1322 |
tag += build; |
|---|
| 1323 |
const char* p = const_cast<cmTarget&>(target).GetProperty( tag.c_str(), cmProperty::TARGET ); |
|---|
| 1324 |
if( p ) |
|---|
| 1325 |
{ |
|---|
| 1326 |
project << advance << less << "Add option=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1327 |
} |
|---|
| 1328 |
|
|---|
| 1329 |
|
|---|
| 1330 |
if( convertTargetType( target.GetType() ) & Executable ) |
|---|
| 1331 |
{ |
|---|
| 1332 |
|
|---|
| 1333 |
tag = "CMAKE_EXE_LINKER_FLAGS_"; |
|---|
| 1334 |
tag += build; |
|---|
| 1335 |
|
|---|
| 1336 |
const char* p = mf->GetDefinition( tag.c_str() ); |
|---|
| 1337 |
if( p && strlen(p) > 0 ) |
|---|
| 1338 |
{ |
|---|
| 1339 |
project << advance << less << "Add option=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1340 |
} |
|---|
| 1341 |
} |
|---|
| 1342 |
|
|---|
| 1343 |
|
|---|
| 1344 |
if( convertTargetType( target.GetType() ) & Shared_library ) |
|---|
| 1345 |
{ |
|---|
| 1346 |
tag = "CMAKE_SHARED_LINKER_FLAGS_"; |
|---|
| 1347 |
tag += build; |
|---|
| 1348 |
|
|---|
| 1349 |
const char* p = mf->GetDefinition( tag.c_str() ); |
|---|
| 1350 |
if( p && strlen(p) > 0 ) |
|---|
| 1351 |
{ |
|---|
| 1352 |
project << advance << less << "Add option=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1353 |
} |
|---|
| 1354 |
} |
|---|
| 1355 |
|
|---|
| 1356 |
|
|---|
| 1357 |
if( convertTargetType( target.GetType() ) & Module_library ) |
|---|
| 1358 |
{ |
|---|
| 1359 |
tag = "CMAKE_MODULE_LINKER_FLAGS_"; |
|---|
| 1360 |
tag += build; |
|---|
| 1361 |
|
|---|
| 1362 |
const char* p = mf->GetDefinition( tag.c_str() ); |
|---|
| 1363 |
if( p && strlen(p) > 0 ) |
|---|
| 1364 |
{ |
|---|
| 1365 |
project << advance << less << "Add option=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1366 |
} |
|---|
| 1367 |
} |
|---|
| 1368 |
|
|---|
| 1369 |
} |
|---|
| 1370 |
|
|---|
| 1371 |
//------------------------------------ Target Section Linker Includes ------------------------------------------------ |
|---|
| 1372 |
|
|---|
| 1373 |
/// Write target level linker includes |
|---|
| 1374 |
void writeTargetAddLinkerDirectories( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1375 |
{ |
|---|
| 1376 |
const std::vector<std::string>& link_directories = const_cast<cmTarget&>(target).GetLinkDirectories(); |
|---|
| 1377 |
|
|---|
| 1378 |
for( size_t i=0; i<link_directories.size(); i++ ) |
|---|
| 1379 |
{ |
|---|
| 1380 |
if( !link_directories[i].empty() ) |
|---|
| 1381 |
{ |
|---|
| 1382 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), link_directories[i].c_str() ); |
|---|
| 1383 |
project << advance << less << "Add directory=" << quote << rel_path << quote << endelement << endl << retreat; |
|---|
| 1384 |
} |
|---|
| 1385 |
} |
|---|
| 1386 |
|
|---|
| 1387 |
} |
|---|
| 1388 |
|
|---|
| 1389 |
//------------------------------------ Target Section Linker Libraries ------------------------------------------------ |
|---|
| 1390 |
/// Write Libraries |
|---|
| 1391 |
void writeTargetAddLinkerLibraries( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1392 |
{ |
|---|
| 1393 |
std::vector< std::string > heap; |
|---|
| 1394 |
|
|---|
| 1395 |
const cmTarget::LinkLibraryVectorType& libraries = target.GetOriginalLinkLibraries(); |
|---|
| 1396 |
for( size_t i=0; i<libraries.size(); i++ ) |
|---|
| 1397 |
{ |
|---|
| 1398 |
std::pair< std::string, cmTarget::LinkLibraryType> library = libraries[i]; |
|---|
| 1399 |
std::string result = library.first; |
|---|
| 1400 |
|
|---|
| 1401 |
/* if( isDepends( result ) ) |
|---|
| 1402 |
{ |
|---|
| 1403 |
// A library that we build |
|---|
| 1404 |
if( current_build_type_name == "Debug" ) |
|---|
| 1405 |
{ |
|---|
| 1406 |
std::string postfix; |
|---|
| 1407 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "DEBUG_POSTFIX", cmProperty::TARGET ); |
|---|
| 1408 |
if( !p )postfix = "_d"; // Default |
|---|
| 1409 |
else postfix = p; |
|---|
| 1410 |
result += postfix; |
|---|
| 1411 |
} |
|---|
| 1412 |
|
|---|
| 1413 |
heap.push_back( result ); |
|---|
| 1414 |
|
|---|
| 1415 |
} |
|---|
| 1416 |
// a debug library |
|---|
| 1417 |
else */ if( current_build_type_name == "Debug" && library.second == cmTarget::DEBUG ) |
|---|
| 1418 |
{ |
|---|
| 1419 |
heap.push_back( result ); |
|---|
| 1420 |
} |
|---|
| 1421 |
// an optimized library |
|---|
| 1422 |
else if( current_build_type_name != "Debug" && library.second == cmTarget::OPTIMIZED ) |
|---|
| 1423 |
{ |
|---|
| 1424 |
heap.push_back( result ); |
|---|
| 1425 |
} |
|---|
| 1426 |
// any library |
|---|
| 1427 |
else if( library.second == cmTarget::GENERAL ) |
|---|
| 1428 |
{ |
|---|
| 1429 |
heap.push_back( result ); |
|---|
| 1430 |
} |
|---|
| 1431 |
} |
|---|
| 1432 |
|
|---|
| 1433 |
std::vector< std::string >::iterator it = heap.begin(); |
|---|
| 1434 |
while( it != heap.end() ) |
|---|
| 1435 |
{ |
|---|
| 1436 |
project << advance << less << "Add library=" << quote << *it++ << quote << endelement << endl << retreat; |
|---|
| 1437 |
|
|---|
| 1438 |
} |
|---|
| 1439 |
|
|---|
| 1440 |
} |
|---|
| 1441 |
|
|---|
| 1442 |
//------------------------------------ Target Section Linker ------------------------------------------------ |
|---|
| 1443 |
|
|---|
| 1444 |
void writeTargetLinkerSettings( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1445 |
{ |
|---|
| 1446 |
project << redirect << advance; |
|---|
| 1447 |
writeTargetLinkerOptions( mf, target ); |
|---|
| 1448 |
|
|---|
| 1449 |
// if( const_cast<cmTarget&>(target).GetType() != cmTarget::STATIC_LIBRARY ) |
|---|
| 1450 |
// { |
|---|
| 1451 |
writeTargetAddLinkerDirectories( mf, target ); |
|---|
| 1452 |
writeTargetAddLinkerLibraries( mf, target ); |
|---|
| 1453 |
// } |
|---|
| 1454 |
|
|---|
| 1455 |
if( project.isHold() ) |
|---|
| 1456 |
{ |
|---|
| 1457 |
project << retreat << direct << advance << less << "Linker" << greater << endl << flush; |
|---|
| 1458 |
project << less << '/' << "Linker" << greater << endl << retreat; |
|---|
| 1459 |
} |
|---|
| 1460 |
else project << retreat << direct; |
|---|
| 1461 |
} |
|---|
| 1462 |
|
|---|
| 1463 |
//------------------------------------ Target Section Resource Includes ------------------------------------------------ |
|---|
| 1464 |
/// \note Target property CODEBLOCKS_RESOURCE_INCLUDE_DIRECTORIES is a list of resource include directories |
|---|
| 1465 |
|
|---|
| 1466 |
void writeTargetAddResourceCompilerDirectories( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1467 |
{ |
|---|
| 1468 |
std::vector< std::string > resource; |
|---|
| 1469 |
std::vector< std::string > directories; |
|---|
| 1470 |
|
|---|
| 1471 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_RESOURCE_INCLUDE_DIRECTORIES", cmProperty::TARGET ); |
|---|
| 1472 |
if( p ) |
|---|
| 1473 |
{ |
|---|
| 1474 |
list2vector( p, resource ); |
|---|
| 1475 |
} |
|---|
| 1476 |
|
|---|
| 1477 |
for( size_t i=0; i<resource.size(); i++ ) |
|---|
| 1478 |
{ |
|---|
| 1479 |
std::string sz = resource[i]; |
|---|
| 1480 |
directories.push_back( sz ); |
|---|
| 1481 |
} |
|---|
| 1482 |
|
|---|
| 1483 |
//Purge |
|---|
| 1484 |
sort( directories.begin(), directories.end() ); |
|---|
| 1485 |
std::vector< std::string >::iterator end = std::unique( directories.begin(), directories.end() ); |
|---|
| 1486 |
directories.erase( end, directories.end() ); |
|---|
| 1487 |
|
|---|
| 1488 |
for( size_t j=0; j<directories.size(); j++ ) |
|---|
| 1489 |
{ |
|---|
| 1490 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), directories[j].c_str() ); |
|---|
| 1491 |
project << advance << less << "Add directory=" << quote << rel_path << quote << endelement << endl << retreat; |
|---|
| 1492 |
} |
|---|
| 1493 |
} |
|---|
| 1494 |
|
|---|
| 1495 |
//------------------------------------ Target Section Resource ------------------------------------------------ |
|---|
| 1496 |
|
|---|
| 1497 |
/// Write resouce section for target |
|---|
| 1498 |
void writeTargetResourceCompilerSettings( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1499 |
{ |
|---|
| 1500 |
project << advance << redirect; |
|---|
| 1501 |
writeTargetAddResourceCompilerDirectories( mf, target ); |
|---|
| 1502 |
if( project.isHold() ) |
|---|
| 1503 |
{ |
|---|
| 1504 |
project << direct << less << "ResourceCompiler" << greater << endl << flush; |
|---|
| 1505 |
project << less << '/' << "ResourceCompiler" << greater << endl; |
|---|
| 1506 |
} |
|---|
| 1507 |
else project << direct; |
|---|
| 1508 |
|
|---|
| 1509 |
project << retreat; |
|---|
| 1510 |
} |
|---|
| 1511 |
|
|---|
| 1512 |
//------------------------------------ Project and Target Section Compiler Id ------------------------------------------------ |
|---|
| 1513 |
|
|---|
| 1514 |
// const char* generator_table[][2] = |
|---|
| 1515 |
// { |
|---|
| 1516 |
// { "Borland Makefiles", "bcc" }, //Borland C++ Compiler (5.5, 5.82) |
|---|
| 1517 |
// { "CodeBlocks", "gcc" }, // this IDE any of |
|---|
| 1518 |
// { "MSYS Makefiles", "gcc" }, |
|---|
| 1519 |
// { "MinGW Makefiles", "gcc" }, |
|---|
| 1520 |
// { "NMake Makefiles", "msvctk" }, //Microsoft Visual C++ Toolkit 2003 |
|---|
| 1521 |
// { "Unix Makefiles", "gcc" }, |
|---|
| 1522 |
// { "Visual Studio 6", "msvctk" }, |
|---|
| 1523 |
// { "Visual Studio 7", "msvctk" }, |
|---|
| 1524 |
// { "Visual Studio .net 2003", "msvctk" }, |
|---|
| 1525 |
// { "Visual Studio 8 2005", "msvc8" }, //Microsoft Visual C++ 2005/2008 |
|---|
| 1526 |
// { "Visual Studio 8 2005 Win64", "msvc8" }, |
|---|
| 1527 |
// { "Visula Studio 9 2008", "msvc8" }, |
|---|
| 1528 |
// { "Visula Studio 9 2008 Win64", "msvc8" }, |
|---|
| 1529 |
// { "Watcom WMake", "ow" }, //OpenWatcom (W32) Compiler |
|---|
| 1530 |
// { "Codeblocks - MinGW Makefiles", "gcc" }, |
|---|
| 1531 |
// { "Codeblocks - Unix Makefiles", "gcc" }, |
|---|
| 1532 |
// { "Eclipse - MinGW Makefiles", "gcc" }, |
|---|
| 1533 |
// { "Eclipse - NMake Makefiles", "gcc" }, |
|---|
| 1534 |
// { "Eclipse - Unix Makefiles", "gcc" }, |
|---|
| 1535 |
// { 0, "cygwin" }, //Cygwin GCC |
|---|
| 1536 |
// { 0, "dmc" }, //Digital Mars Compiler |
|---|
| 1537 |
// { 0, "dmd" }, //Digital Mars D Compiler |
|---|
| 1538 |
// { 0, "gdc" }, //GDC D Compiler |
|---|
| 1539 |
// { 0, "arm-elf-gcc" }, //GNU ARM GCC Compiler |
|---|
| 1540 |
// { 0, "avr-gcc" }, //GNU AVR GCC Compiler |
|---|
| 1541 |
// { 0, "ppc-gcc" }, //GNU GCC Compiler for PowerPC |
|---|
| 1542 |
// { 0, "tricore-gcc" }, //GNU GCC Compiler for TriCore |
|---|
| 1543 |
// { 0, "msp430-gcc" }, //GNU GCC Compiler for MSP430 |
|---|
| 1544 |
// { 0, "icc" }, //Intel C/C++ Compiler |
|---|
| 1545 |
// { 0, "mingw32-gcc" }, //MinGW |
|---|
| 1546 |
// { 0, "sdcc" }, //SDCC Compiler |
|---|
| 1547 |
// { 0, "tcc" }, //Tiny C Compiler |
|---|
| 1548 |
// }; |
|---|
| 1549 |
// |
|---|
| 1550 |
// const int size_generator_table = sizeof( generator_table ) / ( 2 * sizeof( const char*)); |
|---|
| 1551 |
|
|---|
| 1552 |
std::string getCompilerName( cmMakefile* mf ) |
|---|
| 1553 |
{ |
|---|
| 1554 |
std::string compiler = "gcc"; |
|---|
| 1555 |
|
|---|
| 1556 |
|
|---|
| 1557 |
if( !cmSystemTools::IsOn( mf->GetDefinition( "CMAKE_COMPULER_IS_GNUCXX" )) ) |
|---|
| 1558 |
{ |
|---|
| 1559 |
/// \todo other compilers |
|---|
| 1560 |
const char* pcxx = mf->GetDefinition( "CMAKE_CXX_COMPILER" ); |
|---|
| 1561 |
const char* pc = mf->GetDefinition( "CMAKE_C_COMPILER" ); |
|---|
| 1562 |
|
|---|
| 1563 |
bool unixx = cmSystemTools::IsOn( mf->GetDefinition( "UNIX" )); |
|---|
| 1564 |
bool win32 = cmSystemTools::IsOn( mf->GetDefinition( "WIN32" )); |
|---|
| 1565 |
bool cygwin = cmSystemTools::IsOn( mf->GetDefinition( "CYGWIN" )); |
|---|
| 1566 |
bool msvc = cmSystemTools::IsOn( mf->GetDefinition( "MSVC" )); |
|---|
| 1567 |
bool msvc80 = cmSystemTools::IsOn( mf->GetDefinition( "MSVC80" )); |
|---|
| 1568 |
|
|---|
| 1569 |
} |
|---|
| 1570 |
|
|---|
| 1571 |
return compiler; |
|---|
| 1572 |
} |
|---|
| 1573 |
|
|---|
| 1574 |
|
|---|
| 1575 |
/// Write Compiler ID for target and project |
|---|
| 1576 |
void writeCompilerId( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1577 |
{ |
|---|
| 1578 |
std::string compiler = getCompilerName( mf ); |
|---|
| 1579 |
|
|---|
| 1580 |
project << advance << less << "Option compiler=" << quote << compiler << quote << endelement << endl << retreat; |
|---|
| 1581 |
} |
|---|
| 1582 |
|
|---|
| 1583 |
|
|---|
| 1584 |
//------------------------------------ Project Object Names ------------------------------------------------ |
|---|
| 1585 |
/// \note from CMake documentation "CMake computes for every source file an object file name |
|---|
| 1586 |
/// that is unique to the source file and deterministic with respect to the full path to the source file." |
|---|
| 1587 |
/// |
|---|
| 1588 |
|
|---|
| 1589 |
/// \note Global/Directory/Target property CODEBLOCKS_USE_EXTENDED_OBJECT_NAMES add the source file extension to objects |
|---|
| 1590 |
/// Write Extended object name flag for project |
|---|
| 1591 |
void writeExtendedObjectNames( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1592 |
{ |
|---|
| 1593 |
if( cmSystemTools::IsOn( getProperty( mf, target, "CODEBLOCKS_USE_EXTENDED_OBJECT_NAMES" )) ) |
|---|
| 1594 |
{ |
|---|
| 1595 |
project << advance << less << "Option extended_obj_names=" << quote << "1" << quote << endelement << endl << retreat; |
|---|
| 1596 |
} |
|---|
| 1597 |
} |
|---|
| 1598 |
|
|---|
| 1599 |
//------------------------------------ Project Note CData ------------------------------------------------ |
|---|
| 1600 |
|
|---|
| 1601 |
/// \note Target property CODEBLOCKS_NOTE sets a note for a project |
|---|
| 1602 |
|
|---|
| 1603 |
/// Write note for project |
|---|
| 1604 |
void writeNoteCData( const char* note ) |
|---|
| 1605 |
{ |
|---|
| 1606 |
|
|---|
| 1607 |
|
|---|
| 1608 |
std::string text; |
|---|
| 1609 |
|
|---|
| 1610 |
if( note )text = note; |
|---|
| 1611 |
else text = "-- Set Target Property CODEBLOCKS_NOTE ---"; |
|---|
| 1612 |
|
|---|
| 1613 |
|
|---|
| 1614 |
project << advance << less << "notes" << greater << endl; |
|---|
| 1615 |
project << advance << less << '!' << "[CDATA[" << endl; |
|---|
| 1616 |
project << text; |
|---|
| 1617 |
project << "]]" << greater << endl << retreat; |
|---|
| 1618 |
project << less << '/' << "notes" << greater << endl << retreat; |
|---|
| 1619 |
} |
|---|
| 1620 |
|
|---|
| 1621 |
//------------------------------------ Project Notes ------------------------------------------------ |
|---|
| 1622 |
|
|---|
| 1623 |
/// \note Target property CODEBLOCKS_SHOW_NOTE displays a note for a project |
|---|
| 1624 |
|
|---|
| 1625 |
// Write note and show note for project |
|---|
| 1626 |
void writeNotes( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1627 |
{ |
|---|
| 1628 |
const char* note = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_NOTE", cmProperty::TARGET ); |
|---|
| 1629 |
const char* sw = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_SHOW_NOTE", cmProperty::TARGET ); |
|---|
| 1630 |
|
|---|
| 1631 |
if( note || sw ) |
|---|
| 1632 |
{ |
|---|
| 1633 |
std::string is; |
|---|
| 1634 |
if( cmSystemTools::IsOn( sw ) )is = "1"; |
|---|
| 1635 |
else is = "0"; |
|---|
| 1636 |
|
|---|
| 1637 |
project << advance << less << "Option show_notes=" << quote << is << quote << greater << endl; |
|---|
| 1638 |
writeNoteCData( note ); |
|---|
| 1639 |
project << less << '/' << "Option" << greater << endl << retreat; |
|---|
| 1640 |
} |
|---|
| 1641 |
} |
|---|
| 1642 |
|
|---|
| 1643 |
//------------------------------------ Project PCH ------------------------------------------------ |
|---|
| 1644 |
|
|---|
| 1645 |
/// \note Global/Directory/Target property CODEBLOCKS_PCH_MODE={ 0, 1, 2 } - Generate in a directory alongside header, |
|---|
| 1646 |
/// in object directory, or default to alongside header. Generator will add the directory for option |
|---|
| 1647 |
/// 1 to the top of the compiler include list. |
|---|
| 1648 |
|
|---|
| 1649 |
/// Write Pre-Compiled Header Flag for project section |
|---|
| 1650 |
void writePCH( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1651 |
{ |
|---|
| 1652 |
project << advance << less << "Option pch_mode="; |
|---|
| 1653 |
const char* p = getProperty( mf, target, "CODEBLOCKS_PCH_MODE" ); |
|---|
| 1654 |
if( !p ) p = "2"; |
|---|
| 1655 |
project << quote << p << quote << endelement << endl << retreat; |
|---|
| 1656 |
if( strcmp( p, "1" ) == 0 ) |
|---|
| 1657 |
{ |
|---|
| 1658 |
search_first_object_directory = const_cast<cmTarget&>(target).GetDirectory(); //must have build added, this is the object codeblocks_binary_directory |
|---|
| 1659 |
} |
|---|
| 1660 |
|
|---|
| 1661 |
|
|---|
| 1662 |
} |
|---|
| 1663 |
|
|---|
| 1664 |
//------------------------------------ Project Default Target (Build Type ) ------------------------------------------------ |
|---|
| 1665 |
|
|---|
| 1666 |
/// \note Target property CODEBLOCKS_DEFAULT_BUILD sets the default build type for the codeblocks ide |
|---|
| 1667 |
|
|---|
| 1668 |
/// Write the Default Build Type for project section |
|---|
| 1669 |
void writeDefaultTarget( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1670 |
{ |
|---|
| 1671 |
std::vector< std::string > builds; |
|---|
| 1672 |
getBuilds( mf, builds ); |
|---|
| 1673 |
if( builds.empty() )builds.push_back( "RelWithDebInfo" ); //default build for cmake |
|---|
| 1674 |
std::string default_target; |
|---|
| 1675 |
|
|---|
| 1676 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_DEFAULT_BUILD", cmProperty::TARGET ); |
|---|
| 1677 |
|
|---|
| 1678 |
|
|---|
| 1679 |
if( p ) |
|---|
| 1680 |
{ |
|---|
| 1681 |
if( std::find( builds.begin(), builds.end(), p ) != builds.end() )default_target = p; |
|---|
| 1682 |
} |
|---|
| 1683 |
else |
|---|
| 1684 |
{ |
|---|
| 1685 |
default_target = builds[0]; |
|---|
| 1686 |
} |
|---|
| 1687 |
|
|---|
| 1688 |
if( default_target.empty() ) |
|---|
| 1689 |
{ |
|---|
| 1690 |
/// \todo warning - target type not in "CMAKE_CONFIGURATION_TYPES" |
|---|
| 1691 |
default_target = "RelWithDebInfo"; //cmake default build |
|---|
| 1692 |
} |
|---|
| 1693 |
|
|---|
| 1694 |
project << advance << less << "Option default_target=" << quote << default_target << quote << endelement << endl << retreat; |
|---|
| 1695 |
} |
|---|
| 1696 |
|
|---|
| 1697 |
//------------------------------------ Project Virtual Targets Alias------------------------------------------------ |
|---|
| 1698 |
|
|---|
| 1699 |
|
|---|
| 1700 |
/// Write Alias for a Build Type for the Project Section |
|---|
| 1701 |
void writeAlias( const std::string& alias, const std::string& targets ) |
|---|
| 1702 |
{ |
|---|
| 1703 |
if( targets.empty() ) |
|---|
| 1704 |
{ |
|---|
| 1705 |
/// \todo warning alias with no targets |
|---|
| 1706 |
} |
|---|
| 1707 |
else |
|---|
| 1708 |
{ |
|---|
| 1709 |
project << advance << less << "Add alias=" << quote << alias << quote |
|---|
| 1710 |
<< " targets=" << quote << targets << quote << endelement << endl << retreat; |
|---|
| 1711 |
} |
|---|
| 1712 |
} |
|---|
| 1713 |
|
|---|
| 1714 |
//------------------------------------ Project Virtual Targets ------------------------------------------------ |
|---|
| 1715 |
|
|---|
| 1716 |
/// \note Target property CODEBLOCKS_VIRTUAL_BUILDS sets a list of virtual build types for a project file |
|---|
| 1717 |
/// As an Example All RelWithDebInfo Debug Release MinSizeRel Development Debug The build types must |
|---|
| 1718 |
/// be in CMAKE_BUILD_TYPES or it will be considered as an alias and probably fail. |
|---|
| 1719 |
|
|---|
| 1720 |
/// Write list of Alias for a Build Type for the Project Section |
|---|
| 1721 |
void writeVirtualTargets( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1722 |
{ |
|---|
| 1723 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_VIRTUAL_BUILDS", cmProperty::TARGET ); |
|---|
| 1724 |
if( p ) |
|---|
| 1725 |
{ |
|---|
| 1726 |
project << advance << less << "VirtualTargets" << greater << endl; |
|---|
| 1727 |
|
|---|
| 1728 |
std::vector<std::string> names; |
|---|
| 1729 |
list2vector( p, names ); |
|---|
| 1730 |
//get each build type |
|---|
| 1731 |
std::vector< std::string > builds; |
|---|
| 1732 |
getBuilds( mf, builds ); |
|---|
| 1733 |
|
|---|
| 1734 |
std::string targets; |
|---|
| 1735 |
std::string alias; |
|---|
| 1736 |
|
|---|
| 1737 |
for( size_t i=0; i<names.size(); i++ ) |
|---|
| 1738 |
{ |
|---|
| 1739 |
if( std::count( builds.begin(), builds.end(), names[i] ) == 0 ) |
|---|
| 1740 |
{ |
|---|
| 1741 |
if( !alias.empty() )writeAlias( alias, targets ); |
|---|
| 1742 |
alias = names[i]; |
|---|
| 1743 |
targets.clear(); |
|---|
| 1744 |
} |
|---|
| 1745 |
else |
|---|
| 1746 |
{ |
|---|
| 1747 |
if( !targets.empty() ) targets += ';'; |
|---|
| 1748 |
targets += names[i]; |
|---|
| 1749 |
} |
|---|
| 1750 |
} |
|---|
| 1751 |
|
|---|
| 1752 |
if( !alias.empty() )writeAlias( alias, targets ); |
|---|
| 1753 |
|
|---|
| 1754 |
project << less << '/' << "VirtualTargets" << greater << endl << retreat; |
|---|
| 1755 |
} |
|---|
| 1756 |
} |
|---|
| 1757 |
|
|---|
| 1758 |
|
|---|
| 1759 |
//------------------------------------ Project Compiler Options ------------------------------------------------ |
|---|
| 1760 |
/// Write Compiler flags for the project section |
|---|
| 1761 |
void writeCompilerOptions( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1762 |
{ |
|---|
| 1763 |
std::set< cmStdString > languages; |
|---|
| 1764 |
target.GetLanguages( languages ); |
|---|
| 1765 |
std::set< cmStdString >::iterator it = languages.begin(); |
|---|
| 1766 |
std::string tag; |
|---|
| 1767 |
while( it != languages.end() ) |
|---|
| 1768 |
{ |
|---|
| 1769 |
std::string result; |
|---|
| 1770 |
tag = "CMAKE_"; |
|---|
| 1771 |
tag += *it; |
|---|
| 1772 |
tag += "_FLAGS"; |
|---|
| 1773 |
|
|---|
| 1774 |
const char* p = mf->GetDefinition( tag.c_str() ); |
|---|
| 1775 |
if( p && strlen(p) > 0 )result += p; |
|---|
| 1776 |
|
|---|
| 1777 |
|
|---|
| 1778 |
if( convertTargetType( target.GetType() ) & Shared_library ) |
|---|
| 1779 |
{ |
|---|
| 1780 |
tag = "CMAKE_SHARED_LIBRARY_"; |
|---|
| 1781 |
tag += *it; |
|---|
| 1782 |
tag += "_FLAGS"; |
|---|
| 1783 |
|
|---|
| 1784 |
p = mf->GetDefinition( tag.c_str() ); |
|---|
| 1785 |
if( p && strlen(p) > 0 ) |
|---|
| 1786 |
{ |
|---|
| 1787 |
result += ' '; |
|---|
| 1788 |
result += p; |
|---|
| 1789 |
} |
|---|
| 1790 |
} |
|---|
| 1791 |
|
|---|
| 1792 |
if( convertTargetType( target.GetType() ) & Module_library ) |
|---|
| 1793 |
{ |
|---|
| 1794 |
tag = "CMAKE_MODULE_LIBRARY_"; |
|---|
| 1795 |
tag += *it; |
|---|
| 1796 |
tag += "_FLAGS"; |
|---|
| 1797 |
|
|---|
| 1798 |
p = mf->GetDefinition( tag.c_str() ); |
|---|
| 1799 |
if( p && strlen(p) > 0 ) |
|---|
| 1800 |
{ |
|---|
| 1801 |
result += ' '; |
|---|
| 1802 |
result += p; |
|---|
| 1803 |
} |
|---|
| 1804 |
|
|---|
| 1805 |
} |
|---|
| 1806 |
|
|---|
| 1807 |
std::vector<std::string> flags; |
|---|
| 1808 |
list2vector( result, flags ); |
|---|
| 1809 |
for( size_t i=0; i<flags.size(); i++ ) |
|---|
| 1810 |
{ |
|---|
| 1811 |
project << advance << less << "Add option=" << quote << flags[i] << quote << endelement << endl << retreat; |
|---|
| 1812 |
} |
|---|
| 1813 |
|
|---|
| 1814 |
|
|---|
| 1815 |
|
|---|
| 1816 |
p = mf->GetDefineFlags(); |
|---|
| 1817 |
|
|---|
| 1818 |
if( p && strlen(p) > 0 ) |
|---|
| 1819 |
{ |
|---|
| 1820 |
project << advance << less << "Add option=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1821 |
} |
|---|
| 1822 |
|
|---|
| 1823 |
bool in_try_compile = mf->GetCMakeInstance()->GetIsInTryCompile() != 0; |
|---|
| 1824 |
if( !in_try_compile ) //Used for something else in try compile. |
|---|
| 1825 |
{ |
|---|
| 1826 |
|
|---|
| 1827 |
p = mf->GetProperty("COMPILE_DEFINITIONS"); |
|---|
| 1828 |
if( p ) |
|---|
| 1829 |
{ |
|---|
| 1830 |
std::string sz = p; |
|---|
| 1831 |
std::vector< std::string > flags; |
|---|
| 1832 |
list2vector( sz, flags ); |
|---|
| 1833 |
project << advance << less << "Add option=" << quote; |
|---|
| 1834 |
for( size_t i =0; i<flags.size(); i++ ) |
|---|
| 1835 |
{ |
|---|
| 1836 |
if( i ) project << ' '; |
|---|
| 1837 |
project << "-D"; |
|---|
| 1838 |
project << flags[i]; |
|---|
| 1839 |
} |
|---|
| 1840 |
|
|---|
| 1841 |
project << quote << endelement << endl << retreat; |
|---|
| 1842 |
|
|---|
| 1843 |
} |
|---|
| 1844 |
} |
|---|
| 1845 |
|
|---|
| 1846 |
/// \todo check C and CXX or Fortran flags ????? under a workspace/project/target hierarchy. |
|---|
| 1847 |
it++; //Next language? |
|---|
| 1848 |
} |
|---|
| 1849 |
|
|---|
| 1850 |
} |
|---|
| 1851 |
|
|---|
| 1852 |
//------------------------------------ Project Compiler Includes Options ------------------------------------------------ |
|---|
| 1853 |
/// Write project level compiler includes |
|---|
| 1854 |
void writeAddCompilerDirectories( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1855 |
{ |
|---|
| 1856 |
const std::vector< std::string >& includes = mf->GetIncludeDirectories(); |
|---|
| 1857 |
for( size_t i=0; i<includes.size(); i++ ) |
|---|
| 1858 |
{ |
|---|
| 1859 |
if( !includes[i].empty() ) |
|---|
| 1860 |
{ |
|---|
| 1861 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), includes[i].c_str() ); |
|---|
| 1862 |
project << advance << less << "Add directory=" << quote << rel_path << quote << endelement << endl << retreat; |
|---|
| 1863 |
} |
|---|
| 1864 |
} |
|---|
| 1865 |
} |
|---|
| 1866 |
|
|---|
| 1867 |
//------------------------------------ Project Compiler Section ------------------------------------------------ |
|---|
| 1868 |
|
|---|
| 1869 |
void writeCompiler( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1870 |
{ |
|---|
| 1871 |
project << advance << redirect; |
|---|
| 1872 |
writeCompilerOptions( mf, target ); |
|---|
| 1873 |
writeAddCompilerDirectories( mf, target ); |
|---|
| 1874 |
if( project.isHold() ) |
|---|
| 1875 |
{ |
|---|
| 1876 |
project << direct << less << "Compiler" << greater << endl << flush; |
|---|
| 1877 |
project << less << '/' << "Compiler" << greater << endl; |
|---|
| 1878 |
} |
|---|
| 1879 |
|
|---|
| 1880 |
project << retreat; |
|---|
| 1881 |
} |
|---|
| 1882 |
|
|---|
| 1883 |
//------------------------------------ Project Linker Options ------------------------------------------------ |
|---|
| 1884 |
|
|---|
| 1885 |
void writeLinkerOptions( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1886 |
{ |
|---|
| 1887 |
|
|---|
| 1888 |
//SET(CMAKE_DL_LIBS "dl") |
|---|
| 1889 |
//SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC") |
|---|
| 1890 |
//SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") |
|---|
| 1891 |
//SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-rdynamic") |
|---|
| 1892 |
//SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,") |
|---|
| 1893 |
//SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":") |
|---|
| 1894 |
//SET(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,") |
|---|
| 1895 |
//SET(CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG "-Wl,-soname,") |
|---|
| 1896 |
|
|---|
| 1897 |
std::set< cmStdString > languages; |
|---|
| 1898 |
std::string tag; |
|---|
| 1899 |
|
|---|
| 1900 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "LINK_FLAGS", cmProperty::TARGET ); |
|---|
| 1901 |
if( p ) |
|---|
| 1902 |
{ |
|---|
| 1903 |
project << advance << less << "Add option=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1904 |
} |
|---|
| 1905 |
|
|---|
| 1906 |
if( convertTargetType( target.GetType() ) & Executable ) |
|---|
| 1907 |
{ |
|---|
| 1908 |
|
|---|
| 1909 |
tag = "CMAKE_EXE_LINKER_FLAGS"; |
|---|
| 1910 |
|
|---|
| 1911 |
const char* p = mf->GetDefinition( tag.c_str() ); |
|---|
| 1912 |
if( p && strlen(p) > 0 ) |
|---|
| 1913 |
{ |
|---|
| 1914 |
project << advance << less << "Add option=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1915 |
} |
|---|
| 1916 |
} |
|---|
| 1917 |
|
|---|
| 1918 |
|
|---|
| 1919 |
if( convertTargetType( target.GetType() ) & Shared_library ) |
|---|
| 1920 |
{ |
|---|
| 1921 |
tag = "CMAKE_SHARED_LINKER_FLAGS"; |
|---|
| 1922 |
|
|---|
| 1923 |
const char* p = mf->GetDefinition( tag.c_str() ); |
|---|
| 1924 |
if( p && strlen(p) > 0 ) |
|---|
| 1925 |
{ |
|---|
| 1926 |
project << advance << less << "Add option=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1927 |
} |
|---|
| 1928 |
} |
|---|
| 1929 |
|
|---|
| 1930 |
|
|---|
| 1931 |
if( convertTargetType( target.GetType() ) & Module_library ) |
|---|
| 1932 |
{ |
|---|
| 1933 |
tag = "CMAKE_MODULE_LINKER_FLAGS_"; |
|---|
| 1934 |
|
|---|
| 1935 |
const char* p = mf->GetDefinition( tag.c_str() ); |
|---|
| 1936 |
if( p && strlen(p) > 0 ) |
|---|
| 1937 |
{ |
|---|
| 1938 |
project << advance << less << "Add option=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 1939 |
} |
|---|
| 1940 |
} |
|---|
| 1941 |
|
|---|
| 1942 |
// user allowed rpath |
|---|
| 1943 |
if( !rpath.empty() ) |
|---|
| 1944 |
{ |
|---|
| 1945 |
project << advance << less << "Add option=" << quote << rpath << quote << endelement << endl << retreat; |
|---|
| 1946 |
} |
|---|
| 1947 |
|
|---|
| 1948 |
|
|---|
| 1949 |
|
|---|
| 1950 |
|
|---|
| 1951 |
} |
|---|
| 1952 |
|
|---|
| 1953 |
//------------------------------------ Project Linker Includes ------------------------------------------------ |
|---|
| 1954 |
/// Write project level Linker Includes |
|---|
| 1955 |
void writeAddLinkerDirectories( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1956 |
{ |
|---|
| 1957 |
const std::vector<std::string>& link_directories = mf->GetLinkDirectories(); |
|---|
| 1958 |
|
|---|
| 1959 |
for( size_t i=0; i<link_directories.size(); i++ ) |
|---|
| 1960 |
{ |
|---|
| 1961 |
if( !link_directories[i].empty() ) |
|---|
| 1962 |
{ |
|---|
| 1963 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), link_directories[i].c_str() ); |
|---|
| 1964 |
project << advance << less << "Add directory=" << quote << rel_path << quote << endelement << endl << retreat; |
|---|
| 1965 |
} |
|---|
| 1966 |
} |
|---|
| 1967 |
} |
|---|
| 1968 |
|
|---|
| 1969 |
//------------------------------------ Project Linker Libraries ------------------------------------------------ |
|---|
| 1970 |
/// Only Target level libraries in CMake |
|---|
| 1971 |
void writeAddLinkerLibraries( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1972 |
{ |
|---|
| 1973 |
|
|---|
| 1974 |
} |
|---|
| 1975 |
|
|---|
| 1976 |
//------------------------------------ Project Linker Section ------------------------------------------------ |
|---|
| 1977 |
|
|---|
| 1978 |
void writeLinker( cmMakefile* mf, const cmTarget& target ) |
|---|
| 1979 |
{ |
|---|
| 1980 |
project << advance << redirect; |
|---|
| 1981 |
writeLinkerOptions( mf, target ); |
|---|
| 1982 |
if( const_cast<cmTarget&>(target).GetType() != cmTarget::STATIC_LIBRARY ) |
|---|
| 1983 |
{ |
|---|
| 1984 |
writeAddLinkerDirectories( mf, target ); |
|---|
| 1985 |
writeAddLinkerLibraries( mf, target ); |
|---|
| 1986 |
} |
|---|
| 1987 |
|
|---|
| 1988 |
if( project.isHold() ) |
|---|
| 1989 |
{ |
|---|
| 1990 |
project << direct << less << "Linker" << greater << endl << flush; |
|---|
| 1991 |
project << less << '/' << "Linker" << greater << endl; |
|---|
| 1992 |
} |
|---|
| 1993 |
else project << direct; |
|---|
| 1994 |
|
|---|
| 1995 |
project << retreat; |
|---|
| 1996 |
} |
|---|
| 1997 |
|
|---|
| 1998 |
//------------------------------------ Project Resource Includes ------------------------------------------------ |
|---|
| 1999 |
/// Write resource directories fot Directory and global |
|---|
| 2000 |
void writeAddResourceCompilerDirectories( cmMakefile* mf, const cmTarget& target ) |
|---|
| 2001 |
{ |
|---|
| 2002 |
std::vector< std::string > resource; |
|---|
| 2003 |
std::vector< std::string > directories; |
|---|
| 2004 |
|
|---|
| 2005 |
const char* p = mf->GetProperty( "CODEBLOCKS_RESOURCE_INCLUDE_DIRECTORIES", cmProperty::DIRECTORY ); |
|---|
| 2006 |
if( p ) |
|---|
| 2007 |
{ |
|---|
| 2008 |
list2vector( p, resource, false ); |
|---|
| 2009 |
} |
|---|
| 2010 |
|
|---|
| 2011 |
// Should be in workspace but codeblocks only allows projects under a workspace. |
|---|
| 2012 |
if( !p ) |
|---|
| 2013 |
{ |
|---|
| 2014 |
p = mf->GetCMakeInstance()->GetProperty( "CODEBLOCKS_RESOURCE_INCLUDE_DIRECTORIES", cmProperty::GLOBAL ); |
|---|
| 2015 |
|
|---|
| 2016 |
if( p ) |
|---|
| 2017 |
{ |
|---|
| 2018 |
list2vector( p, resource, false ); |
|---|
| 2019 |
} |
|---|
| 2020 |
} |
|---|
| 2021 |
|
|---|
| 2022 |
for( size_t i=0; i<resource.size(); i++ ) |
|---|
| 2023 |
{ |
|---|
| 2024 |
std::string sz = resource[i]; |
|---|
| 2025 |
directories.push_back( sz ); |
|---|
| 2026 |
} |
|---|
| 2027 |
|
|---|
| 2028 |
//Purge |
|---|
| 2029 |
sort( directories.begin(), directories.end() ); |
|---|
| 2030 |
std::vector< std::string >::iterator end = std::unique( directories.begin(), directories.end() ); |
|---|
| 2031 |
directories.erase( end, directories.end() ); |
|---|
| 2032 |
|
|---|
| 2033 |
for( size_t j=0; j<directories.size(); j++ ) |
|---|
| 2034 |
{ |
|---|
| 2035 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), directories[j].c_str() ); |
|---|
| 2036 |
project << advance << less << "Add directory=" << quote << rel_path << quote << endelement << endl << retreat; |
|---|
| 2037 |
} |
|---|
| 2038 |
} |
|---|
| 2039 |
|
|---|
| 2040 |
//------------------------------------ Project Resource Compiler Section ------------------------------------------------ |
|---|
| 2041 |
/// Write resource for project section |
|---|
| 2042 |
void writeResourceCompiler( cmMakefile* mf, const cmTarget& target ) |
|---|
| 2043 |
{ |
|---|
| 2044 |
project << advance << redirect; |
|---|
| 2045 |
writeAddResourceCompilerDirectories( mf, target ); |
|---|
| 2046 |
if( project.isHold() ) |
|---|
| 2047 |
{ |
|---|
| 2048 |
project << direct << less << "ResourceCompiler" << greater << endl << flush; |
|---|
| 2049 |
project << less << '/' << "ResourceCompiler" << greater << endl; |
|---|
| 2050 |
} |
|---|
| 2051 |
else project << direct; |
|---|
| 2052 |
|
|---|
| 2053 |
project << retreat; |
|---|
| 2054 |
} |
|---|
| 2055 |
|
|---|
| 2056 |
//------------------------------------ Project Unit Section ------------------------------------------------ |
|---|
| 2057 |
/// Write Compile for Unit section |
|---|
| 2058 |
void writeUnitCompilerVar( cmMakefile* mf, const cmTarget& target, cmSourceFile* source ) |
|---|
| 2059 |
{ |
|---|
| 2060 |
// const char* p = source->GetLanguage(); |
|---|
| 2061 |
// if( p ) |
|---|
| 2062 |
// { |
|---|
| 2063 |
// |
|---|
| 2064 |
// std::string language = p; |
|---|
| 2065 |
// if( language.compare( "CXX" ) == 0 )language = "CPP"; |
|---|
| 2066 |
// |
|---|
| 2067 |
// if( language.compare( "CPP" ) == 0 |
|---|
| 2068 |
// || language.compare( "C" ) == 0 |
|---|
| 2069 |
// || language.compare( "WINDRES" ) == 0 ) |
|---|
| 2070 |
// project << advance << less << "Option compilerVar=" << quote << language << quote << endelement << endl << retreat; |
|---|
| 2071 |
// } |
|---|
| 2072 |
} |
|---|
| 2073 |
|
|---|
| 2074 |
/// BuildCommand - undocumented used for individual source file flags and includes. |
|---|
| 2075 |
|
|---|
| 2076 |
void writeUnitBuildCommand( cmMakefile* mf, const cmTarget& target, cmSourceFile* source ) |
|---|
| 2077 |
{ |
|---|
| 2078 |
// const char* p = source->GetLanguage(); |
|---|
| 2079 |
|
|---|
| 2080 |
const char* p = source->GetProperty( "COMPILE_FLAGS" ); |
|---|
| 2081 |
if( p ) |
|---|
| 2082 |
{ |
|---|
| 2083 |
|
|---|
| 2084 |
std::string compiler = getCompilerName( mf ); |
|---|
| 2085 |
|
|---|
| 2086 |
std::vector<std::string> flags; |
|---|
| 2087 |
std::string result = p; |
|---|
| 2088 |
list2vector( result, flags ); |
|---|
| 2089 |
|
|---|
| 2090 |
|
|---|
| 2091 |
if( flags.size() > 0 ) |
|---|
| 2092 |
{ |
|---|
| 2093 |
project << advance << less << "Option compiler=" << quote << compiler << quote << " use=\"1\" " << "buildCommand=" << quote |
|---|
| 2094 |
<< "$compiler " << "$options "; |
|---|
| 2095 |
|
|---|
| 2096 |
|
|---|
| 2097 |
for( size_t i=0; i<flags.size(); i++ ) |
|---|
| 2098 |
{ |
|---|
| 2099 |
if( flags[i].find("-I") == 0 ) |
|---|
| 2100 |
{ |
|---|
| 2101 |
std::string path = flags[i].substr( 2 ); |
|---|
| 2102 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), path.c_str() ); |
|---|
| 2103 |
project << "-I" << rel_path << " "; |
|---|
| 2104 |
} |
|---|
| 2105 |
else |
|---|
| 2106 |
{ |
|---|
| 2107 |
project << flags[i] << " "; |
|---|
| 2108 |
|
|---|
| 2109 |
} |
|---|
| 2110 |
|
|---|
| 2111 |
|
|---|
| 2112 |
} |
|---|
| 2113 |
|
|---|
| 2114 |
project << "$includes -c $file -o $object" << quote << endelement << endl << retreat; |
|---|
| 2115 |
|
|---|
| 2116 |
} |
|---|
| 2117 |
} |
|---|
| 2118 |
|
|---|
| 2119 |
} |
|---|
| 2120 |
|
|---|
| 2121 |
|
|---|
| 2122 |
/// \note Source file property CODEBLOCKS_SOURCE_NO_COMPILE - Do not compile this file |
|---|
| 2123 |
/// could be supported with the cmake property EXTERNAL_OBJECT |
|---|
| 2124 |
|
|---|
| 2125 |
/// Write Compiler enable/diable for Unit section |
|---|
| 2126 |
void writeUnitCompiler( cmMakefile* mf, const cmTarget& target, cmSourceFile* source ) |
|---|
| 2127 |
{ |
|---|
| 2128 |
const char* p = source->GetProperty( "CODEBLOCKS_SOURCE_NO_COMPILE" ); |
|---|
| 2129 |
if( !p ) source->GetProperty( "EXTERNAL_OBJECT" ); |
|---|
| 2130 |
if( cmSystemTools::IsOn( p ) ) |
|---|
| 2131 |
{ |
|---|
| 2132 |
project << advance << less << "Option compile=" << quote << '0' << quote << endelement << endl << retreat; |
|---|
| 2133 |
} |
|---|
| 2134 |
} |
|---|
| 2135 |
|
|---|
| 2136 |
/// \note Source file property CODEBLOCKS_SOURCE_NO_LINK - Do not link this file |
|---|
| 2137 |
/// could be supported with the cmake property SYMBOLIC |
|---|
| 2138 |
|
|---|
| 2139 |
/// Write Linker enable/diable for Unit section |
|---|
| 2140 |
void writeUnitLink( cmMakefile* mf, const cmTarget& target, cmSourceFile* source ) |
|---|
| 2141 |
{ |
|---|
| 2142 |
const char* p = source->GetProperty( "CODEBLOCKS_SOURCE_NO_LINK" ); |
|---|
| 2143 |
if( !p ) source->GetProperty( "SYMBOLIC" ); |
|---|
| 2144 |
if( cmSystemTools::IsOn( p ) ) |
|---|
| 2145 |
{ |
|---|
| 2146 |
project << advance << less << "Option link=" << quote << '0' << quote << endelement << endl << retreat; |
|---|
| 2147 |
} |
|---|
| 2148 |
} |
|---|
| 2149 |
|
|---|
| 2150 |
/// \note Source file property CODEBLOCKS_SOURCE_WEIGHT (number) - Lower number files are |
|---|
| 2151 |
/// compiled first. |
|---|
| 2152 |
|
|---|
| 2153 |
/// Write Source file priority for Unit section |
|---|
| 2154 |
void writeUnitWeight( cmMakefile* mf, const cmTarget& target, cmSourceFile* source ) |
|---|
| 2155 |
{ |
|---|
| 2156 |
const char* p = source->GetProperty( "CODEBLOCKS_SOURCE_WEIGHT" ); |
|---|
| 2157 |
if( p ) |
|---|
| 2158 |
{ |
|---|
| 2159 |
project << advance << less << "Option weight=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 2160 |
} |
|---|
| 2161 |
} |
|---|
| 2162 |
|
|---|
| 2163 |
|
|---|
| 2164 |
/// \note Source file property CODEBLOCKS_VIRTUAL_FOLDER (Folder name only) |
|---|
| 2165 |
/// will override all virtual folder properties - a folder is created and the source |
|---|
| 2166 |
/// is placed under it. |
|---|
| 2167 |
|
|---|
| 2168 |
/// Write Virtual Folders for Unit section |
|---|
| 2169 |
void writeUnitVirtualFolder( cmMakefile* mf, const cmTarget& target, cmSourceFile* source ) |
|---|
| 2170 |
{ |
|---|
| 2171 |
const char* p = source->GetProperty( "CODEBLOCKS_VIRTUAL_FOLDER" ); |
|---|
| 2172 |
|
|---|
| 2173 |
if( p ) |
|---|
| 2174 |
{ |
|---|
| 2175 |
// The folder should exist - set in writeVirtualFolders |
|---|
| 2176 |
// Put it in a spacfic folder |
|---|
| 2177 |
project << advance << less << "Option virtualFolder=" << quote << p << quote << endelement << endl << retreat; |
|---|
| 2178 |
} |
|---|
| 2179 |
else if( !virtual_folder_extension.empty() ) |
|---|
| 2180 |
{ |
|---|
| 2181 |
if( cmSystemTools::IsOn( source->GetProperty( "GENERATED" )) ) |
|---|
| 2182 |
{ |
|---|
| 2183 |
project << advance << less << "Option virtualFolder=" << quote << "Generated" << quote << endelement << endl << retreat; |
|---|
| 2184 |
} |
|---|
| 2185 |
else |
|---|
| 2186 |
{ |
|---|
| 2187 |
// not generated put it in by extension |
|---|
| 2188 |
std::string ext = source->GetExtension(); |
|---|
| 2189 |
if( virtual_folder_extension.count( ext ) != 0 ) |
|---|
| 2190 |
{ |
|---|
| 2191 |
project << advance << less << "Option virtualFolder=" << quote << virtual_folder_extension[ext] << quote << endelement << endl << retreat; |
|---|
| 2192 |
} |
|---|
| 2193 |
} |
|---|
| 2194 |
|
|---|
| 2195 |
} |
|---|
| 2196 |
|
|---|
| 2197 |
//Not using virtual folders exit |
|---|
| 2198 |
|
|---|
| 2199 |
|
|---|
| 2200 |
} |
|---|
| 2201 |
|
|---|
| 2202 |
/// \note Source file property CODEBLOCKS_SOURCE_TARGETS is a list of targets |
|---|
| 2203 |
/// that this source file is attached, no CODEBLOCKS_SOURCE_TARGETS property |
|---|
| 2204 |
/// attaches this file to all build targets. This is not support in cmake and |
|---|
| 2205 |
/// the makefile generator used will include the source in all targets. It can |
|---|
| 2206 |
/// be used to keep two groups of builds, for example Linux_Debug and Win32_debug |
|---|
| 2207 |
/// in the same CodeBlocks project file. |
|---|
| 2208 |
|
|---|
| 2209 |
/// Write Target property for Unit section. |
|---|
| 2210 |
void writeUnitTarget( cmMakefile* mf, const cmTarget& target, cmSourceFile* source ) |
|---|
| 2211 |
{ |
|---|
| 2212 |
const char* p = source->GetProperty( "CODEBLOCKS_SOURCE_TARGETS" ); |
|---|
| 2213 |
|
|---|
| 2214 |
if( p ) |
|---|
| 2215 |
{ |
|---|
| 2216 |
std::vector< std::string > arg; |
|---|
| 2217 |
list2vector( p, arg ); |
|---|
| 2218 |
for( size_t i=0; i<arg.size(); i++ ) |
|---|
| 2219 |
project << advance << less << "Option target=" << quote << arg[i] << quote << endelement << endl << retreat; |
|---|
| 2220 |
} |
|---|
| 2221 |
|
|---|
| 2222 |
} |
|---|
| 2223 |
|
|---|
| 2224 |
/// \note Global/Director/Target property CODEBLOCKS_GENERATED_FILES = is a list |
|---|
| 2225 |
/// of files that are generate by other targets to be include in this project file. |
|---|
| 2226 |
/// Files are cumulative from global to target. |
|---|
| 2227 |
|
|---|
| 2228 |
/// Write Generated Source for Unit section. |
|---|
| 2229 |
void writeGeneratedSources( cmMakefile* mf, const cmTarget& target ) |
|---|
| 2230 |
{ |
|---|
| 2231 |
std::vector< std::string> generated; |
|---|
| 2232 |
|
|---|
| 2233 |
if( getProperty( mf, target, "CODEBLOCKS_GENERATED_FILES" ) ) //there is a configuration file |
|---|
| 2234 |
{ |
|---|
| 2235 |
//files are cumulative |
|---|
| 2236 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_GENERATED_FILES", cmProperty::TARGET ); |
|---|
| 2237 |
if( p ) |
|---|
| 2238 |
{ |
|---|
| 2239 |
list2vector( p, generated, false ); |
|---|
| 2240 |
} |
|---|
| 2241 |
|
|---|
| 2242 |
p = mf->GetProperty( "CODEBLOCKS_GENERATED_FILES", cmProperty::DIRECTORY ); |
|---|
| 2243 |
if( p ) |
|---|
| 2244 |
{ |
|---|
| 2245 |
list2vector( p, generated, false ); |
|---|
| 2246 |
} |
|---|
| 2247 |
|
|---|
| 2248 |
// Should be in workspace but codeblocks only allows projects under a workspace. |
|---|
| 2249 |
p = mf->GetCMakeInstance()->GetProperty( "CODEBLOCKS_GENERATED_FILES", cmProperty::GLOBAL ); |
|---|
| 2250 |
if( p ) |
|---|
| 2251 |
{ |
|---|
| 2252 |
list2vector( p, generated, false ); |
|---|
| 2253 |
} |
|---|
| 2254 |
} |
|---|
| 2255 |
|
|---|
| 2256 |
//Purge |
|---|
| 2257 |
sort( generated.begin(), generated.end() ); |
|---|
| 2258 |
std::vector< std::string>::iterator end = std::unique( generated.begin(), generated.end() ); |
|---|
| 2259 |
generated.erase( end, generated.end() ); |
|---|
| 2260 |
|
|---|
| 2261 |
//Purge any of may own source/project |
|---|
| 2262 |
std::vector<cmSourceFile*> const sources = const_cast<cmTarget&>(target).GetSourceFiles(); |
|---|
| 2263 |
for( size_t i=0; i<sources.size(); i++ ) |
|---|
| 2264 |
{ |
|---|
| 2265 |
if( cmSystemTools::IsOn( sources[i]->GetProperty( "GENERATED" )) ) |
|---|
| 2266 |
{ |
|---|
| 2267 |
const std::string path = sources[i]->GetFullPath(); |
|---|
| 2268 |
std::vector<std::string>::iterator found = std::find( generated.begin(), generated.end(), path ); |
|---|
| 2269 |
if( found != generated.end() ) |
|---|
| 2270 |
{ |
|---|
| 2271 |
generated.erase( found ); |
|---|
| 2272 |
} |
|---|
| 2273 |
|
|---|
| 2274 |
} |
|---|
| 2275 |
} |
|---|
| 2276 |
|
|---|
| 2277 |
for( size_t i=0; i<generated.size(); i++ ) |
|---|
| 2278 |
{ |
|---|
| 2279 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), generated[i].c_str() ); |
|---|
| 2280 |
project << advance << less << "Unit filename=" << quote << rel_path << quote << greater << endl; |
|---|
| 2281 |
project << advance << less << "Option compile=" << quote << '0' << quote << endelement << endl << retreat; |
|---|
| 2282 |
project << advance << less << "Option link=" << quote << '0' << quote << endelement << endl << retreat; |
|---|
| 2283 |
if( !virtual_folder_extension.empty() ) |
|---|
| 2284 |
{ |
|---|
| 2285 |
project << advance << less << "Option virtualFolder=" << quote << "Generated" << quote << endelement << endl << retreat; |
|---|
| 2286 |
} |
|---|
| 2287 |
project << less << '/' << "Unit" << greater << endl << retreat; |
|---|
| 2288 |
} |
|---|
| 2289 |
|
|---|
| 2290 |
|
|---|
| 2291 |
|
|---|
| 2292 |
} |
|---|
| 2293 |
|
|---|
| 2294 |
/// \note Global/Director/Target property CODEBLOCKS_SCRIPT_FILES = is a list |
|---|
| 2295 |
/// of files that are scripts - Files are cumulative from global to target. |
|---|
| 2296 |
|
|---|
| 2297 |
/// Write Script files for Virtual folder section of project |
|---|
| 2298 |
void writeScriptSources( cmMakefile* mf, const cmTarget& target ) |
|---|
| 2299 |
{ |
|---|
| 2300 |
if( getProperty( mf, target, "CODEBLOCKS_SCRIPT_FILES" ) ) //there is a configuration file |
|---|
| 2301 |
{ |
|---|
| 2302 |
//files are cumulative |
|---|
| 2303 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_SCRIPT_FILES", cmProperty::TARGET ); |
|---|
| 2304 |
if( p ) |
|---|
| 2305 |
{ |
|---|
| 2306 |
list2vector( p, codeblocks_scripts, false ); |
|---|
| 2307 |
} |
|---|
| 2308 |
|
|---|
| 2309 |
p = mf->GetProperty( "CODEBLOCKS_SCRIPT_FILES", cmProperty::DIRECTORY ); |
|---|
| 2310 |
if( p ) |
|---|
| 2311 |
{ |
|---|
| 2312 |
list2vector( p, codeblocks_scripts, false ); |
|---|
| 2313 |
} |
|---|
| 2314 |
|
|---|
| 2315 |
// Should be in workspace but codeblocks only allows projects under a workspace. |
|---|
| 2316 |
p = mf->GetCMakeInstance()->GetProperty( "CODEBLOCKS_SCRIPT_FILES", cmProperty::GLOBAL ); |
|---|
| 2317 |
if( p ) |
|---|
| 2318 |
{ |
|---|
| 2319 |
list2vector( p, codeblocks_scripts, false ); |
|---|
| 2320 |
} |
|---|
| 2321 |
} |
|---|
| 2322 |
|
|---|
| 2323 |
//makefile always one script |
|---|
| 2324 |
//Purge |
|---|
| 2325 |
sort( codeblocks_scripts.begin(), codeblocks_scripts.end() ); |
|---|
| 2326 |
std::vector< std::string>::iterator end = std::unique( codeblocks_scripts.begin(), codeblocks_scripts.end() ); |
|---|
| 2327 |
codeblocks_scripts.erase( end, codeblocks_scripts.end() ); |
|---|
| 2328 |
|
|---|
| 2329 |
for( size_t i=0; i<codeblocks_scripts.size(); i++ ) |
|---|
| 2330 |
{ |
|---|
| 2331 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), codeblocks_scripts[i].c_str() ); |
|---|
| 2332 |
project << advance << less << "Unit filename=" << quote << rel_path << quote << greater << endl; |
|---|
| 2333 |
project << advance << less << "Option compile=" << quote << '0' << quote << endelement << endl << retreat; |
|---|
| 2334 |
project << advance << less << "Option link=" << quote << '0' << quote << endelement << endl << retreat; |
|---|
| 2335 |
if( !virtual_folder_extension.empty() ) |
|---|
| 2336 |
{ |
|---|
| 2337 |
project << advance << less << "Option virtualFolder=" << quote << "Scripts" << quote << endelement << endl << retreat; |
|---|
| 2338 |
} |
|---|
| 2339 |
project << less << '/' << "Unit" << greater << endl << retreat; |
|---|
| 2340 |
} |
|---|
| 2341 |
|
|---|
| 2342 |
|
|---|
| 2343 |
|
|---|
| 2344 |
} |
|---|
| 2345 |
|
|---|
| 2346 |
/// \note Global/Director/Target property CODEBLOCKS_CONFIGURED_FILES = is a list |
|---|
| 2347 |
/// of files that are the source for a generated source file or script - this is a clue |
|---|
| 2348 |
/// to programmer not to edit a generated file but edit it's source and re-configure. |
|---|
| 2349 |
/// Files are cumulative from global to target. |
|---|
| 2350 |
|
|---|
| 2351 |
/// Write Configure files for Virtual folder section of project |
|---|
| 2352 |
void writeConfigurationSources( cmMakefile* mf, const cmTarget& target ) |
|---|
| 2353 |
{ |
|---|
| 2354 |
if( getProperty( mf, target, "CODEBLOCKS_CONFIGURED_FILES" ) ) //there is a configuration file |
|---|
| 2355 |
{ |
|---|
| 2356 |
//files are cumulative |
|---|
| 2357 |
std::vector< std::string > configure; |
|---|
| 2358 |
|
|---|
| 2359 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_CONFIGURED_FILES", cmProperty::TARGET ); |
|---|
| 2360 |
if( p ) |
|---|
| 2361 |
{ |
|---|
| 2362 |
list2vector( p, configure ); |
|---|
| 2363 |
} |
|---|
| 2364 |
|
|---|
| 2365 |
p = mf->GetProperty( "CODEBLOCKS_CONFIGURED_FILES", cmProperty::DIRECTORY ); |
|---|
| 2366 |
if( p ) |
|---|
| 2367 |
{ |
|---|
| 2368 |
list2vector( p, configure, false ); |
|---|
| 2369 |
} |
|---|
| 2370 |
|
|---|
| 2371 |
// Should be in workspace but codeblocks only allows projects under a workspace. |
|---|
| 2372 |
p = mf->GetCMakeInstance()->GetProperty( "CODEBLOCKS_CONFIGURED_FILES", cmProperty::GLOBAL ); |
|---|
| 2373 |
if( p ) |
|---|
| 2374 |
{ |
|---|
| 2375 |
list2vector( p, configure, false ); |
|---|
| 2376 |
} |
|---|
| 2377 |
|
|---|
| 2378 |
//Purge |
|---|
| 2379 |
sort( configure.begin(), configure.end() ); |
|---|
| 2380 |
std::vector< std::string>::iterator end = std::unique( configure.begin(), configure.end() ); |
|---|
| 2381 |
configure.erase( end, configure.end() ); |
|---|
| 2382 |
|
|---|
| 2383 |
for( size_t i=0; i<configure.size(); i++ ) |
|---|
| 2384 |
{ |
|---|
| 2385 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), configure[i].c_str() ); |
|---|
| 2386 |
project << advance << less << "Unit filename=" << quote << rel_path << quote << greater << endl; |
|---|
| 2387 |
project << advance << less << "Option compile=" << quote << '0' << quote << endelement << endl << retreat; |
|---|
| 2388 |
project << advance << less << "Option link=" << quote << '0' << quote << endelement << endl << retreat; |
|---|
| 2389 |
if( !virtual_folder_extension.empty() ) |
|---|
| 2390 |
{ |
|---|
| 2391 |
project << advance << less << "Option virtualFolder=" << quote << "Configure" << quote << endelement << endl << retreat; |
|---|
| 2392 |
} |
|---|
| 2393 |
project << less << '/' << "Unit" << greater << endl << retreat; |
|---|
| 2394 |
} |
|---|
| 2395 |
} |
|---|
| 2396 |
} |
|---|
| 2397 |
|
|---|
| 2398 |
/// \note Global/Director/Target property CODEBLOCKS_RESOURCE_FILES = is a list |
|---|
| 2399 |
/// of files that are the source for a generated resources - Files are cumulative |
|---|
| 2400 |
/// from global to target. |
|---|
| 2401 |
|
|---|
| 2402 |
/// Write Resource files for Virtual folder section of project |
|---|
| 2403 |
void writeResourceSources( cmMakefile* mf, const cmTarget& target ) |
|---|
| 2404 |
{ |
|---|
| 2405 |
if( getProperty( mf, target, "CODEBLOCKS_RESOURCE_FILES" ) ) //there is a configuration file |
|---|
| 2406 |
{ |
|---|
| 2407 |
//files are cumulative |
|---|
| 2408 |
std::vector< std::string > resource; |
|---|
| 2409 |
|
|---|
| 2410 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_RESOURCE_FILES", cmProperty::TARGET ); |
|---|
| 2411 |
if( p ) |
|---|
| 2412 |
{ |
|---|
| 2413 |
list2vector( p, resource ); |
|---|
| 2414 |
} |
|---|
| 2415 |
|
|---|
| 2416 |
p = mf->GetProperty( "CODEBLOCKS_RESOURCE_FILES", cmProperty::DIRECTORY ); |
|---|
| 2417 |
if( p ) |
|---|
| 2418 |
{ |
|---|
| 2419 |
list2vector( p, resource, false ); |
|---|
| 2420 |
} |
|---|
| 2421 |
|
|---|
| 2422 |
// Should be in workspace but codeblocks only allows projects under a workspace. |
|---|
| 2423 |
p = mf->GetCMakeInstance()->GetProperty( "CODEBLOCKS_RESOURCE_FILES", cmProperty::GLOBAL ); |
|---|
| 2424 |
if( p ) |
|---|
| 2425 |
{ |
|---|
| 2426 |
list2vector( p, resource, false ); |
|---|
| 2427 |
} |
|---|
| 2428 |
|
|---|
| 2429 |
//Purge |
|---|
| 2430 |
sort( resource.begin(), resource.end() ); |
|---|
| 2431 |
std::vector< std::string>::iterator end = std::unique( resource.begin(), resource.end() ); |
|---|
| 2432 |
resource.erase( end, resource.end() ); |
|---|
| 2433 |
|
|---|
| 2434 |
for( size_t i=0; i<resource.size(); i++ ) |
|---|
| 2435 |
{ |
|---|
| 2436 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), resource[i].c_str() ); |
|---|
| 2437 |
project << advance << less << "Unit filename=" << quote << rel_path << quote << greater << endl; |
|---|
| 2438 |
project << advance << less << "Option compile=" << quote << '0' << quote << endelement << endl << retreat; |
|---|
| 2439 |
project << advance << less << "Option link=" << quote << '0' << quote << endelement << endl << retreat; |
|---|
| 2440 |
if( !virtual_folder_extension.empty() ) |
|---|
| 2441 |
{ |
|---|
| 2442 |
project << advance << less << "Option virtualFolder=" << quote << "Resources" << quote << endelement << endl << retreat; |
|---|
| 2443 |
} |
|---|
| 2444 |
project << less << '/' << "Unit" << greater << endl << retreat; |
|---|
| 2445 |
} |
|---|
| 2446 |
} |
|---|
| 2447 |
} |
|---|
| 2448 |
|
|---|
| 2449 |
/// Write Units section. |
|---|
| 2450 |
void writeUnits( cmMakefile* mf, const cmTarget& target ) |
|---|
| 2451 |
{ |
|---|
| 2452 |
//for each project file |
|---|
| 2453 |
std::vector<cmSourceFile*> const sources = const_cast<cmTarget&>(target).GetSourceFiles(); |
|---|
| 2454 |
for( size_t i=0; i<sources.size(); i++ ) |
|---|
| 2455 |
{ |
|---|
| 2456 |
if( cmSystemTools::IsOn( const_cast<cmTarget&>(target).GetProperty( "SYMBOLIC", cmProperty::TARGET )) )continue; |
|---|
| 2457 |
|
|---|
| 2458 |
const std::string path = sources[i]->GetFullPath(); |
|---|
| 2459 |
std::string rel_path = cmSystemTools::RelativePath( codeblocks_binary_directory.c_str(), path.c_str() ); |
|---|
| 2460 |
project << advance << less << "Unit filename=" << quote << rel_path << quote << greater << endl; |
|---|
| 2461 |
writeUnitCompilerVar( mf, target, sources[i] ); |
|---|
| 2462 |
writeUnitBuildCommand( mf, target, sources[i] ); |
|---|
| 2463 |
writeUnitCompiler( mf, target, sources[i] ); |
|---|
| 2464 |
writeUnitLink( mf, target, sources[i] ); |
|---|
| 2465 |
writeUnitWeight( mf, target, sources[i] ); |
|---|
| 2466 |
writeUnitVirtualFolder( mf, target, sources[i] ); |
|---|
| 2467 |
writeUnitTarget( mf, target, sources[i] ); |
|---|
| 2468 |
project << less << '/' << "Unit" << greater << endl << retreat; |
|---|
| 2469 |
} |
|---|
| 2470 |
|
|---|
| 2471 |
//Scripts |
|---|
| 2472 |
writeResourceSources( mf, target ); |
|---|
| 2473 |
|
|---|
| 2474 |
//Scripts |
|---|
| 2475 |
writeScriptSources( mf, target ); |
|---|
| 2476 |
|
|---|
| 2477 |
//Configure files |
|---|
| 2478 |
writeConfigurationSources( mf, target ); |
|---|
| 2479 |
|
|---|
| 2480 |
//Generated files not in this project |
|---|
| 2481 |
writeGeneratedSources( mf, target ); |
|---|
| 2482 |
|
|---|
| 2483 |
|
|---|
| 2484 |
} |
|---|
| 2485 |
|
|---|
| 2486 |
//------------------------------------ Project Virtual Folders ------------------------------------------------ |
|---|
| 2487 |
|
|---|
| 2488 |
/// \note Global/Director/Target property CODEBLOCKS_VIRTUAL_FOLDERS = default or a list(name |
|---|
| 2489 |
/// followed by file extensions). The extensions must have a leading asterisk. |
|---|
| 2490 |
/// For example: Sources *.cpp *.cxx Headers *.h *.hpp Sources/Assembly *.s |
|---|
| 2491 |
/// "default" will enable virtual folders with: |
|---|
| 2492 |
/// "Sources;*.cpp;*.cxx;*.c;Headers*.h;*.hxx;*.hpp;Generated;Resources;*xrc;Scripts;*.sh;*.bat;*.cmd;*" |
|---|
| 2493 |
/// Any file that has a Generated property will go under Generated, any codeblocks script file will go under |
|---|
| 2494 |
/// Scripts along with the current CMakeList.txt file. A lone asterisk means any file without an extension. |
|---|
| 2495 |
/// default followed by a list will add that list to the default list above. DIRECTORY property will |
|---|
| 2496 |
/// override the GLOBAL property, TARGET property will override DIRECTORY and a |
|---|
| 2497 |
/// SOURCE property of CODEBLOCKS_VIRTUAL_FOLDER (Folder name only) |
|---|
| 2498 |
/// will override all. |
|---|
| 2499 |
|
|---|
| 2500 |
/// Write Virtual folder section of project |
|---|
| 2501 |
void writeVirtualFolders( cmMakefile* mf, const cmTarget& target ) |
|---|
| 2502 |
{ |
|---|
| 2503 |
virtual_folder_extension.clear(); |
|---|
| 2504 |
const char* p = getProperty( mf, target, "CODEBLOCKS_VIRTUAL_FOLDERS" ); |
|---|
| 2505 |
|
|---|
| 2506 |
if( p ) |
|---|
| 2507 |
{ |
|---|
| 2508 |
std::vector< std::string > folders; |
|---|
| 2509 |
std::vector< std::string > arg; |
|---|
| 2510 |
|
|---|
| 2511 |
list2vector( p, arg ); |
|---|
| 2512 |
|
|---|
| 2513 |
if( arg[0] == "default" ) |
|---|
| 2514 |
{ |
|---|
| 2515 |
std::vector< std::string > it; |
|---|
| 2516 |
list2vector( "Sources;*.cpp;*.cxx;*.c;Headers;*.h;*.hxx;*.hpp;Generated;Resources;*.xrc;*.rc;*.rc2;Scripts;Configure;*.in", it ); |
|---|
| 2517 |
//std::back_insert_iterator< std::vector< std::string > > bi(it); |
|---|
| 2518 |
//std::copy( arg.begin(), arg.end(), bi ); |
|---|
| 2519 |
it.insert( it.end(), arg.begin()+1, arg.end() ); |
|---|
| 2520 |
arg.swap( it ); |
|---|
| 2521 |
} |
|---|
| 2522 |
|
|---|
| 2523 |
std::string last_folder; |
|---|
| 2524 |
|
|---|
| 2525 |
for( size_t i = 0; i<arg.size(); i++ ) |
|---|
| 2526 |
{ |
|---|
| 2527 |
if( arg[i].empty() ) continue; |
|---|
| 2528 |
|
|---|
| 2529 |
if( arg[i].at(0) == '*' ) |
|---|
| 2530 |
{ |
|---|
| 2531 |
if( last_folder.empty() ) |
|---|
| 2532 |
{ |
|---|
| 2533 |
/// \todo warning file extention but no folder |
|---|
| 2534 |
continue; |
|---|
| 2535 |
} |
|---|
| 2536 |
|
|---|
| 2537 |
if( arg[i].length() == 1 )virtual_folder_extension["*"] = last_folder; |
|---|
| 2538 |
else |
|---|
| 2539 |
{ |
|---|
| 2540 |
size_t start = 1; |
|---|
| 2541 |
if( arg[i].at(start) == '.' )start++; |
|---|
| 2542 |
if( arg[i].length() > start ) |
|---|
| 2543 |
{ |
|---|
| 2544 |
std::string key = arg[i].substr( start, std::string::npos ); // cmSource GetExtension - return no dot. |
|---|
| 2545 |
virtual_folder_extension[key] = last_folder; |
|---|
| 2546 |
} |
|---|
| 2547 |
else |
|---|
| 2548 |
{ |
|---|
| 2549 |
/// \todo warning file extention is a dot? |
|---|
| 2550 |
continue; |
|---|
| 2551 |
} |
|---|
| 2552 |
} |
|---|
| 2553 |
} |
|---|
| 2554 |
else |
|---|
| 2555 |
{ |
|---|
| 2556 |
last_folder = arg[i]; |
|---|
| 2557 |
if( std::count( folders.begin(), folders.end(), last_folder ) == 0 ) //keep user order |
|---|
| 2558 |
{ |
|---|
| 2559 |
folders.push_back( last_folder ); |
|---|
| 2560 |
} |
|---|
| 2561 |
} |
|---|
| 2562 |
|
|---|
| 2563 |
} |
|---|
| 2564 |
|
|---|
| 2565 |
// Get source folders ad to list |
|---|
| 2566 |
bool found_generated_source = false; |
|---|
| 2567 |
std::vector<cmSourceFile*> const sources = const_cast<cmTarget&>(target).GetSourceFiles(); |
|---|
| 2568 |
for( size_t i=0; i<sources.size(); i++ ) |
|---|
| 2569 |
{ |
|---|
| 2570 |
const char* p = sources[i]->GetProperty( "CODEBLOCKS_VIRTUAL_FOLDER" ); |
|---|
| 2571 |
if( p )folders.push_back( std::string( p ) ); |
|---|
| 2572 |
} |
|---|
| 2573 |
|
|---|
| 2574 |
/// \note Global/Director/Target property CODEBLOCKS_RESOURCE_FILES = is a list |
|---|
| 2575 |
/// of files that are the source for a generated resources - Files are cumulative |
|---|
| 2576 |
/// from global to target. |
|---|
| 2577 |
|
|---|
| 2578 |
last_folder = "Resources"; |
|---|
| 2579 |
if( std::count( folders.begin(), folders.end(), last_folder ) == 0 ) |
|---|
| 2580 |
{ |
|---|
| 2581 |
const char* p = getProperty( mf, target, "CODEBLOCKS_RESOURCE_FILES" ); |
|---|
| 2582 |
if( p ) |
|---|
| 2583 |
{ |
|---|
| 2584 |
folders.push_back( last_folder ); // A lest one configure file was found |
|---|
| 2585 |
} |
|---|
| 2586 |
} |
|---|
| 2587 |
|
|---|
| 2588 |
last_folder = "Scripts"; |
|---|
| 2589 |
if( std::count( folders.begin(), folders.end(), last_folder ) == 0 ) |
|---|
| 2590 |
{ |
|---|
| 2591 |
folders.push_back( last_folder ); // A lest one script CMakeLists.txt |
|---|
| 2592 |
} |
|---|
| 2593 |
|
|---|
| 2594 |
last_folder = "Generated"; |
|---|
| 2595 |
if( found_generated_source && std::count( folders.begin(), folders.end(), last_folder ) == 0 ) |
|---|
| 2596 |
{ |
|---|
| 2597 |
folders.push_back( last_folder ); // A lest one generated source |
|---|
| 2598 |
} |
|---|
| 2599 |
|
|---|
| 2600 |
/// \note Global/Director/Target property CODEBLOCKS_CONFIGURED_FILES = is list |
|---|
| 2601 |
/// of files that are the source for a generated source file or script - this is a clue |
|---|
| 2602 |
/// to programmer not to edit a generated file but edit it's source and re-configure. |
|---|
| 2603 |
/// Files are cumulative from global to target. |
|---|
| 2604 |
|
|---|
| 2605 |
last_folder = "Configure"; |
|---|
| 2606 |
if( std::count( folders.begin(), folders.end(), last_folder ) == 0 ) |
|---|
| 2607 |
{ |
|---|
| 2608 |
const char* p = getProperty( mf, target, "CODEBLOCKS_CONFIGURED_FILES" ); |
|---|
| 2609 |
if( p ) |
|---|
| 2610 |
{ |
|---|
| 2611 |
folders.push_back( last_folder ); // A lest one configure file was found |
|---|
| 2612 |
} |
|---|
| 2613 |
} |
|---|
| 2614 |
|
|---|
| 2615 |
/// \note Purge CodeBlocks default folders Sources Headers Scripts and Resources, |
|---|
| 2616 |
/// it may be that Unit virtualFolder are folders not virtual folders |
|---|
| 2617 |
/// If a folder is in the Unit section but not in the virtualFolders Option |
|---|
| 2618 |
/// it will show in the codeblocks ide, but the complete path will be include in the folder. |
|---|
| 2619 |
std::string default_codeblocks_folders = "SourcesHeadersScriptsResources"; |
|---|
| 2620 |
std::vector< std::string > tz; |
|---|
| 2621 |
for( size_t i=0; i<folders.size(); i++ ) |
|---|
| 2622 |
{ |
|---|
| 2623 |
if( default_codeblocks_folders.find( folders[i] ) == std::string::npos ) tz.push_back( folders[i] ); |
|---|
| 2624 |
} |
|---|
| 2625 |
|
|---|
| 2626 |
folders.swap( tz ); |
|---|
| 2627 |
|
|---|
| 2628 |
std::string result; |
|---|
| 2629 |
vector2list( folders, result ); |
|---|
| 2630 |
|
|---|
| 2631 |
project << advance << less << "Option virtualFolders=" << quote << result << quote << endelement << endl << retreat; |
|---|
| 2632 |
} |
|---|
| 2633 |
} |
|---|
| 2634 |
|
|---|
| 2635 |
|
|---|
| 2636 |
//------------------------------------ Target Section ------------------------------------------------ |
|---|
| 2637 |
/// Write Target section of project |
|---|
| 2638 |
void writeBuildTarget( cmMakefile* mf, const cmTarget& target ) |
|---|
| 2639 |
{ |
|---|
| 2640 |
project << advance << less << "Target title=" << quote << current_build_type_name << quote << greater << endl; |
|---|
| 2641 |
writePlatformsOption( mf ); |
|---|
| 2642 |
writeOutput( mf, target ); |
|---|
| 2643 |
writeWorkingDirectory( mf, target ); |
|---|
| 2644 |
writeObjectOutput( mf, target ); |
|---|
| 2645 |
writeExternalDependencies( mf, target ); |
|---|
| 2646 |
writeAdditionalOutputs( mf, target ); |
|---|
| 2647 |
writeOutputType( mf, target ); |
|---|
| 2648 |
writeCompilerId( mf, target ); |
|---|
| 2649 |
writeConsoleRunner( mf, target ); |
|---|
| 2650 |
writeExecutionParameters( mf, target ); |
|---|
| 2651 |
writeHostApplication( mf, target ); |
|---|
| 2652 |
writeCreateDEFFile( mf, target ); |
|---|
| 2653 |
writeCreateImportLibrary( mf, target ); |
|---|
| 2654 |
writeCompilerRelation( mf, target ); |
|---|
| 2655 |
writeLinkerOptionRelation( mf, target ); |
|---|
| 2656 |
writeIncludeDirectoryRelation( mf, target ); |
|---|
| 2657 |
writeResourceIncludeDirectoryRelation( mf, target ); |
|---|
| 2658 |
writeLibraryDirectoryRelation( mf, target ); |
|---|
| 2659 |
writeTargetScripts( mf, target ); |
|---|
| 2660 |
writeTargetCompilerSettings( mf, target ); |
|---|
| 2661 |
writeTargetLinkerSettings( mf, target ); |
|---|
| 2662 |
writeTargetResourceCompilerSettings( mf, target ); |
|---|
| 2663 |
writeTargetExtraCommands( mf, target ); |
|---|
| 2664 |
|
|---|
| 2665 |
|
|---|
| 2666 |
project << less << '/' << "Target" << greater << endl << retreat; |
|---|
| 2667 |
} |
|---|
| 2668 |
|
|---|
| 2669 |
//------------------------------------ Build Section Scripts ------------------------------------------------ |
|---|
| 2670 |
|
|---|
| 2671 |
/// \note Directory property CODEBLOCKS_SCRIPT - run a directory (CMakeLists) level codeblocks script |
|---|
| 2672 |
|
|---|
| 2673 |
/// Write Build scripts of Build section. |
|---|
| 2674 |
void writeBuildScripts( cmMakefile* mf, const cmTarget& target ) |
|---|
| 2675 |
{ |
|---|
| 2676 |
const char* p = const_cast<cmTarget&>(target).GetProperty( "CODEBLOCKS_SCRIPT", cmProperty::DIRECTORY ); |
|---|
| 2677 |
|
|---|
| 2678 |
if( p ) |
|---|
| 2679 |
{ |
|---|
| 2680 |
std::string script = p; |
|---|
| 2681 |
codeblocks_scripts.push_back( script ); |
|---|
| 2682 |
project << advance << less << "Script file=" << quote << script << quote << endelement << endl << retreat; |
|---|
| 2683 |
} |
|---|
| 2684 |
} |
|---|
| 2685 |
|
|---|
| 2686 |
//------------------------------------ Build Section ------------------------------------------------ |
|---|
| 2687 |
/// Write Build sectin of project |
|---|
| 2688 |
void writeBuild( cmMakefile* mf, const cmTarget& target ) |
|---|
| 2689 |
{ |
|---|
| 2690 |
project << advance << less << "Build" << greater << endl; |
|---|
| 2691 |
writeBuildScripts( mf, target ); |
|---|
| 2692 |
|
|---|
| 2693 |
//for each build type |
|---|
| 2694 |
std::vector< std::string > build; |
|---|
| 2695 |
|
|---|
| 2696 |
getBuilds( mf, build ); |
|---|
| 2697 |
|
|---|
| 2698 |
for( size_t i=0; i<build.size(); i++ ) |
|---|
| 2699 |
{ |
|---|
| 2700 |
current_build_type_name = build[i]; |
|---|
| 2701 |
writeBuildTarget( mf, target ); |
|---|
| 2702 |
} |
|---|
| 2703 |
project << less << '/' << "Build" << greater << endl << retreat; |
|---|
| 2704 |
|
|---|
| 2705 |
} |
|---|
| 2706 |
|
|---|
| 2707 |
//------------------------------------ Project ------------------------------------------------ |
|---|
| 2708 |
/// Write the project |
|---|
| 2709 |
void writeProject( cmMakefile* mf, const cmTarget& target, const std::string& workspace_directory, |
|---|
| 2710 |
const std::string& project_file, std::set<const cmTarget*>& depends ) |
|---|
| 2711 |
{ |
|---|
| 2712 |
search_first_object_directory.clear(); //pch mode 1 - search first |
|---|
| 2713 |
virtual_folder_extension.clear(); |
|---|
| 2714 |
codeblocks_scripts.clear(); |
|---|
| 2715 |
current_build_type_name.clear(); |
|---|
| 2716 |
rpath.clear(); //executable target rpath flags |
|---|
| 2717 |
|
|---|
| 2718 |
workspace_depends.clear(); |
|---|
| 2719 |
std::set<const cmTarget*>::iterator it = depends.begin(); |
|---|
| 2720 |
while( it != depends.end() )workspace_depends.push_back( *it++ ); |
|---|
| 2721 |
|
|---|
| 2722 |
codeblocks_binary_directory = workspace_directory; |
|---|
| 2723 |
project_binary_directory = project_file; |
|---|
| 2724 |
size_t ix = project_binary_directory.rfind( target.GetName() ); //assume cbp file name after target |
|---|
| 2725 |
if( ix != std::string::npos )project_binary_directory.resize( ix ); |
|---|
| 2726 |
|
|---|
| 2727 |
std::string current_list_file = mf->GetCurrentListFile(); //There are other reasons then cmake |
|---|
| 2728 |
codeblocks_scripts.push_back( current_list_file ); |
|---|
| 2729 |
|
|---|
| 2730 |
|
|---|
| 2731 |
project.clear(); |
|---|
| 2732 |
project << less << "?xml version=" << quote << "1.0" << quote << " encoding=" |
|---|
| 2733 |
<< quote << "UTF-8" << quote << " standalone=" << quote << "yes" << quote << '?' << greater << endl; |
|---|
| 2734 |
project << less << "CodeBlocks_project_file" << greater << endl; |
|---|
| 2735 |
project << advance << less << "FileVersion major=" << quote << '1' << quote |
|---|
| 2736 |
<< " minor=" << quote << '6' << quote << endelement << endl << retreat; |
|---|
| 2737 |
|
|---|
| 2738 |
|
|---|
| 2739 |
project << advance << less << "Project" << greater << endl; |
|---|
| 2740 |
writeProjectTitleOption( target ); |
|---|
| 2741 |
writePlatformsOption( mf ); |
|---|
| 2742 |
// makefile |
|---|
| 2743 |
writePCH( mf, target ); |
|---|
| 2744 |
writeDefaultTarget( mf, target ); |
|---|
| 2745 |
writeCompilerId( mf, target ); |
|---|
| 2746 |
writeVirtualFolders( mf, target ); |
|---|
| 2747 |
writeExtendedObjectNames( mf, target ); |
|---|
| 2748 |
writeNotes( mf, target ); |
|---|
| 2749 |
writeBuild( mf, target ); |
|---|
| 2750 |
writeVirtualTargets( mf, target ); |
|---|
| 2751 |
writeCompiler( mf, target ); |
|---|
| 2752 |
writeResourceCompiler( mf, target ); |
|---|
| 2753 |
writeLinker( mf, target ); |
|---|
| 2754 |
writeExtraCommands( mf, target ); |
|---|
| 2755 |
writeUnits( mf, target ); |
|---|
| 2756 |
project << less << "/Project" << greater << endl << retreat; |
|---|
| 2757 |
|
|---|
| 2758 |
project << less << '/' << "CodeBlocks_project_file" << greater << endl; |
|---|
| 2759 |
|
|---|
| 2760 |
|
|---|
| 2761 |
project.writeBuffer( project_file ); |
|---|
| 2762 |
} |
|---|
| 2763 |
|
|---|
| 2764 |
} //namespace codeblocksgenerator |
|---|
| 2765 |
|
|---|
| 2766 |
void cmLocalCodeBlocksGenerator::writeProject( cmMakefile* mf, const cmTarget& target, const std::string& workspace_directory, |
|---|
| 2767 |
const std::string& project_file, std::set<const cmTarget*>& depends ) |
|---|
| 2768 |
{ |
|---|
| 2769 |
codeblocksgenerator::writeProject( mf, target, workspace_directory, project_file, depends ); |
|---|
| 2770 |
} |
|---|
| 2771 |
|
|---|
| 2772 |
|
|---|
| 2773 |
void cmLocalCodeBlocksGenerator::writeUtilityProject( cmMakefile* mf, const cmTarget& target, const std::string& workspace_directory, |
|---|
| 2774 |
const std::string& project_file ) |
|---|
| 2775 |
{ |
|---|
| 2776 |
codeblocksgenerator::writeUtilityProject( mf, target, workspace_directory, project_file ); |
|---|
| 2777 |
} |
|---|
| 2778 |
|
|---|
| 2779 |
|
|---|
| 2780 |
void cmLocalCodeBlocksGenerator::writeCommandProject( cmMakefile* mf, |
|---|
| 2781 |
const std::string& command, |
|---|
| 2782 |
const std::string& title, |
|---|
| 2783 |
const std::string& project_file ) |
|---|
| 2784 |
{ |
|---|
| 2785 |
codeblocksgenerator::writeCommandProject( mf, command, title, project_file ); |
|---|
| 2786 |
} |
|---|
| 2787 |
|
|---|
| 2788 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|---|