Is there a way to know at compile time which target format was selected ?
I'm doing a console and windowed application.
I have a single source to create both the exe, with some conditional compilation of course.
I defined a constant to select the exe I want to create, but it would be a lot easier if I could simply change the target in the compiler options and hit the compile button without trying to remember every time I have to change the defined constant too.
Something like
CompilerIf #PB_Compiler_Target = 0 ; console
; console code here
CompilerEndIf
CompilerIf #PB_Compiler_Target = 1 ; windows
; windows code here
CompilerEndIf
Since a compiler constant like the above seems not supported, is there some other way to know the value of that setting ?
Thank you.
console, windows, dll - is there a way to tell which one ?
-
- Addict
- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact:
In the PB IDE, not by default. (I think jaPBe might have this option)
So out of curiosity, I created a tool to do it. (I have not extensively tested it, so beware)
It creates a constant called #PB_Compiler_Type that is set to either "Windows", "Console" or "DLL" (this is quite easy to modify however; the name is on the 2nd line.)
Set it up as a tool (you will need two entries - one for compile/run, and another for create exe).
Set the parameters to "%COMPILEFILE" (with the Double Quotes) No other options should be needed.
This should work cross platform too, although the "Windows" value may be a bit confusing on mac and linux... (plus the values looked for in the compiler options may need to be changed.)
So out of curiosity, I created a tool to do it. (I have not extensively tested it, so beware)
It creates a constant called #PB_Compiler_Type that is set to either "Windows", "Console" or "DLL" (this is quite easy to modify however; the name is on the 2nd line.)
Set it up as a tool (you will need two entries - one for compile/run, and another for create exe).
Set the parameters to "%COMPILEFILE" (with the Double Quotes) No other options should be needed.
Code: Select all
tempfile.s = ProgramParameter()
constant.s = "#PB_Compiler_Type = "+#DQUOTE$
CopyFile(tempfile, tempfile+".orig")
If ReadFile(0, tempfile+".orig")
filelen = Lof(0)
*origbuffer = AllocateMemory(filelen+2)
fileencoding = ReadStringFormat(0)
ReadData(0, *origbuffer, filelen-Loc(0))
*fileptr = *origbuffer+filelen-20
While *fileptr >= *origbuffer;so we dont reverse beyond it.
readoptions.s = PeekS(*fileptr, -1, fileencoding)
;Debug readoptions
If FindString(readoptions, "; IDE Options", 1)
If FindString(readoptions, "; ExecutableFormat = ", 1)
exeformat.s = LTrim(Mid(readoptions, FindString(readoptions, "; ExecutableFormat = ", 1)+Len("; ExecutableFormat = ")))
If Left(exeformat, 10) = "Shared Dll"
constant+"DLL"
ElseIf Left(exeformat, 7) = "Console"
constant+"Console"
Else
constant+"Windows"
EndIf
Else
constant+"Windows"
EndIf
Break
EndIf
*fileptr - 1
Wend
CloseFile(0)
If CreateFile(0, tempfile)
WriteStringFormat(0, fileencoding);set the BOM correctly
WriteStringN(0, constant+#DQUOTE$)
WriteData(0, *origbuffer, filelen-Loc(0))
CloseFile(0)
EndIf
DeleteFile(tempfile+".orig")
EndIf
Demonio Ardente
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
If you use jaPBe :luis wrote:Is there a way to know at compile time which target format was selected ?
Constants available at runtime :
#jaPBe_ExecuteBuild : Build number
#jaPBe_CompilerVersion : PB compiler version
#jaPBe_OnError : If #True, OnError is enabled in Project Options
#jaPBe_IsDebuggerRunning : If #True, project is compiled with debugger
#jaPBe_IsExecute : If #True, compiled with "Create Executable" (else "Compile / Run")
#jaPBe_ExecuteType : Executable type (0 : Windows, 1 : DLL, 2 : Console)
#jaPBe_Compiler_File : Compiled source path + filename (like #PB_Compiler_File)
#jaPBe_SourcePath : Compiled source path
#jaPBe_SourceFile : Compiled source filename
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).