How can i define DEBUG when the build type is debug? - meson-build

I want to pass "-DDEBUG" to the C++ compiler when the build type starts with "debug", something like this:
if meson.build_type().starts_with('debug')
add_global_arguments('-DDEBUG', language : 'cpp')
endif
However there is no meson.build_type(), so I get this error message from meson:
Meson encountered an error in file meson.build, line 5, column 23:
Unknown method "build_type" in object.
How can I get the build type? Or is there a different way to define DEBUG in debug builds?

if get_option('buildtype').startswith('debug')
add_project_arguments('-DDEBUG', language : 'cpp')
endif

The accepted answer didn't work on meson 0.63.0, instead I did this, per the FAQ:
if get_option('buildtype') == 'debug'
add_global_arguments('-DDEBUG', language : 'cpp')
endif

Related

I am learning gradle kotlin DSL. Why is this code example failing to compile with Gradle 6.7.1?

the following lines do not compile in my build.gradle.kts, but I do not understand why:
tasks.getting(JavaExec::class) {
standardInput=System.in
}
* What went wrong:
Script compilation error:
Line 21: standardInput = System.in
^ Expecting an element
What is the correct way to write this?
In Kotlin, in is a hard keyword, which cannot be used as an identifier. To access or declare members named in, you have to surround it with backticks (`):
standardInput = System.`in`

Successful build of Kicad 4.0.6 in Linux Mageia 5 via fixing a wx-3.0 symbol

I have managed to build the Kicad 4.0.6 in Linux Mageia 5.1 with gcc version 4.9.2. I first manually fixed two wxWidgets 3.0.2 header files in the /usr/include/wx-3.0/wx/ directory: regex.h and features.h. Kicad then compiled successfully. With the native wx-3.0 headers, the compiler generated the error in pcbnew/netlist_reader.cpp due to the undefined variable wxRE_ADVANCED.
The features.h header checks if the macro WX_NO_REGEX_ADVANCED is defined. If yes, features.h UNdefines wxHAS_REGEX_ADVANCED macro, and defines it, if no. The macro wxHAS_REGEX_ADVANCED, in turn, is used in regex.h to determine if among the enum constants wxRE_ADVANCED = 1 is present. The standard prebuilt Mageia 5 packages wxgtku3.0_0 and lib64wxgtku3.0-devel that I installed with the use of Mageia's software manager urpmi from Mageia repository WX_NO_REGEX_ADVANCED is defined, therefore wxHAS_REGEX_ADVANCED is undefined, and, hence, wxRE_ADVANCED is undefined either. Kicad 4.0.6 source package assumes wxRE_ADVANCED = 1, therefore the build process stops with the error.
Then I reverted /usr/include/wx-3.0/wx/regex.h and features.h to their original state and learned how to add the definition of wxRE_ADVANCED to CMakeLists.txt. However, I still have a question.
The recommended format of adding the definition to CMakeLists.txt I found at CMake command line for C++ #define is this:
if (NOT DEFINED wxRE_ADVANCED)
set(wxRE_ADVANCED 1)
endif()
add_definitions(-DwxRE_ADVANCED=$(wxRE_ADVANCED))
However, it did not work! The macro expansion for wxRE_ADVANCED in pcbnew/netlist_reader.cpp was empty. I printed it at compile time inserting the following lines into the netlist_reader.cpp file (this was hard to find, most of the recommended formats did not work. The correct one is in C preprocessor: expand macro in a #warning):
#define __STRINGIFY(TEXT) #TEXT
#define __WARNING(TEXT) __STRINGIFY(GCC warning TEXT)
#define WARNING(VALUE) __WARNING(__STRINGIFY(wxRE_ADVANCED = VALUE))
Pragma (WARNING(wxRE_ADVANCED))
Finally, I simplified the CMakeLists.txt definition down to this, and it was a success:
if (NOT DEFINED wxRE_ADVANCED)
set(wxRE_ADVANCED 1)
endif()
add_definitions(-DwxRE_ADVANCED=1)
My question: what is the meaning of "-DwxRE_ADVANCED=$(wxRE_ADVANCED)" if it does not work? Is it possible not to use set(wxRE_ADVANCED 1), and simply write add_definitions(-DwxRE_ADVANCED=1)? Thank you.
P.S. Yes, the Kicad 4.0.6 build process successfully finished with only one line added to the top level CMakeLists.txt file:
add_definitions(-DwxRE_ADVANCED=1)
A variable is called via $variable or ${variable}. Note the curly brackets, not parentheses.
Also, it is recommended to use:
target_compile_definitions(mytarget PUBLIC wxRE_ADVANCED=1)
on a target directly, rather than the general add_definitions() command.

Invalid preprocessing directive for #elseifdef in Xcode

Why:
#ifdef SOME_TARGET_FLAG
<some code here>
#elseifdef SOME_ANOTHER_TARGET_FLAG
<some another code here>
#endif
produces "Invalid preprocessing directive" preprocess compilation error?
SOME_TARGET_FLAG and SOME_ANOTHER_TARGET_FLAG are just some "Other C-flags" defined in target build settings (-D<FLAG_NAME> pattern).
Is #elseifdef directive not supported by Xcode?
Is #elseifdef directive not supported by Xcode?
It is not. Use this instead:
#elif defined(SOME_ANOTHER_TARGET_FLAG)
Its not supported as indicated by the error message. See 'the C preprocessor' - https://developer.apple.com/library/mac/#documentation/DeveloperTools/gcc-4.2.1/cpp/index.html#//apple_ref/doc/uid/TP40007092 (conditional compilation).

cmake parse error that repeats

I have the following line in a CMakeLists.txt file...
else
message(FATAL_ERROR "Could not locate Lua 5.1.\n"
"Please download from Lua website.")
endif
When I run cmake, I get the following error...
Parse error. Expected "(", got newline with text "
".
Okay, I figure. That isn't valid syntax, so I'll just edit the cmake file to put it all on a line like so...
message(FATAL_ERROR "Could not locate Lua 5.1.\nPlease download from Lua website.")
Go to the directory where I ran cmake, delete all the cache stuff, re-run it, and I get the same error as before. I've even deleted that whole line and I keep getting the same error. I'm obviously missing something crucial that defines how cmake operates, but I'm not sure what.
Any help is appreciated.
The if, else, elseif, and endif all need () after them.

objc_startCollectorThread() implicit declaration warning

I'm trying to work through Apple's CoreData Utility Tutorial. It asks me to create a 'Foundation Tool' project in the 'Command Line Utility' section. In XCode 3.2, I only found a 'Command Line Tool' section with a 'Foundation' type in the 'New Project' wizard.
So I created the 'Command Line Tool' 'Foundation' type project, and added the following line to enable garbage collection:
objc_startCollectorThread();
I also changed the 'Objective-C Garbage Collection' setting in my 'Target Info' 'Build' tab to 'Required [-fobjc-gc-only]'. When I run my build, I get the following error:
warning: implicit declaration of function 'objc_startCollectorThread'
The target runs fine so far. All it does is print 'Hello World' to the console. I'm just concerned about this warning. I must be doing something wrong if I'm getting warnings for something as basic as garbage collection on a command line tool.
You should #include <objc/objc-auto.h>, which is where this function is defined.