Recent

Author Topic: [Solved]Conditional compilation depending of fpc version?  (Read 217 times)

glorfin

  • Jr. Member
  • **
  • Posts: 66
[Solved]Conditional compilation depending of fpc version?
« on: November 12, 2019, 09:48:28 pm »
Is it possible to create a file with conditional compilation depending on a compiler version, to write code which implements newest possibilities when compiled by a new fpc, but is compatible with older ones?
« Last Edit: November 13, 2019, 02:12:01 am by glorfin »

valdir.marcos

  • Hero Member
  • *****
  • Posts: 865
Re: Conditional compilation depending of fpc version?
« Reply #1 on: November 13, 2019, 01:57:28 am »
Is it possible to create a file with conditional compilation depending on a compiler version, to write code which implements newest possibilities when compiled by a new fpc, but is compatible with older ones?
Code: Pascal  [Select]
  1. const
  2.   lcl_version =  // note: 48 = Ord('0')
  3.     {$ifdef ConditionalExpressions} {$if Declared(lcl_major) and (lcl_major >= 10)}
  4.      Chr (48+(lcl_major div 10)) + {$ifend} {$endif}
  5.      Chr (48+(lcl_major mod 10)) +'.'+
  6.  
  7.     {$ifdef ConditionalExpressions} {$if Declared(lcl_minor) and (lcl_minor >= 10)}
  8.      Chr (48+(lcl_minor div 10)) + {$ifend} {$endif}
  9.      Chr (48+(lcl_minor mod 10)) +'.'+
  10.  
  11.     {$ifdef ConditionalExpressions} {$if Declared(lcl_release) and (lcl_release >= 10)}
  12.      Chr (48+(lcl_release div 10)) + {$ifend} {$endif}
  13.      Chr (48+(lcl_release mod 10)) +'.'+
  14.  
  15.     {$ifdef ConditionalExpressions} {$if Declared(lcl_patch) and (lcl_patch >= 10)}
  16.      Chr (48+(lcl_patch div 10)) + {$ifend} {$endif}
  17.      Chr (48+(lcl_patch mod 10));
https://lazarus-ccr.sourceforge.io/docs/lcl/lclversion/index.html

Directive, conditional or macro for LCL version?
https://forum.lazarus.freepascal.org/index.php/topic,22674.0.html
https://lazarus-ccr.sourceforge.io/docs/lcl/lclversion/index.html

lcl_version as constant expression
https://forum.lazarus.freepascal.org/index.php/topic,34831.0.html

Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
https://forum.lazarus.freepascal.org/index.php/topic,45144.msg321468.html#msg321468

Get LCL revision or version via ifdef
http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Get-LCL-revision-or-version-via-ifdef-td3383720.html

https://wiki.freepascal.org/Conditional_compilation
https://www.freepascal.org/docs-html/prog/progch1.html
https://www.freepascal.org/docs-html/current/prog/progch2.html
https://wiki.freepascal.org/Conditional_Compiler_Options
https://wiki.freepascal.org/Macros_and_Conditionals
https://wiki.freepascal.org/local_compiler_directives
https://wiki.freepascal.org/index.php?title=local_compiler_directives&printable=yes

glorfin

  • Jr. Member
  • **
  • Posts: 66
Re: Conditional compilation depending of fpc version?
« Reply #2 on: November 13, 2019, 01:59:52 am »
Thank you. It is better than nothing, but a library which I am supporting does not use LCL. Theoretically, it may be complied without lazarus. Are there LCL-independent solutions? If not, it would be nice to introduce them  ::)
« Last Edit: November 13, 2019, 02:03:54 am by glorfin »

Cyrax

  • Hero Member
  • *****
  • Posts: 760
Re: Conditional compilation depending of fpc version?
« Reply #3 on: November 13, 2019, 02:08:20 am »
Code: Pascal  [Select]
  1. {$IF FPC_FULLVERSION >= 33000} ... ${ENDIF}

glorfin

  • Jr. Member
  • **
  • Posts: 66
Re: Conditional compilation depending of fpc version?
« Reply #4 on: November 13, 2019, 02:11:35 am »
Oh, thank you, Cyrax! This is what I needed!