I've been doing some tinkering with the Firefox source code, and I'd like to be able to compile it with some custom defines.
For example, the Firefox source code has some ifdef blocks like this, where EXAMPLE is one of many constants.
#ifdef EXAMPLE
// code here
#endif
What I'd like to do is enable some of these constants, presumable by configuring my .mozconfig file to set them somehow.
I haven't found any documentation on how to do this, but based on some examples, I thought maybe adding this might do the trick.
mk_add_options EXAMPLE=1
But it didn't work, and neither does this (DEFINES: command not found):
DEFINES += -DEXAMPLE
It must be possible somehow though, as presumably Firefox developers are using this feature.
How can I set some custom defines for the Firefox build scripts?
Related
I'm fiddling around with an old game and am trying to learn how it works. My current experiments include trying to proxy one of the game's DLL.
So I renamed the original DLL.dll to trueDLL.dll, dumped the DLL's exports with dumpbin and created the #pragmas (fine for now, I'll look into .def files later) to generate an "empty" proxy. This worked as expected.
Now, I'd like to redirect some of the functions to my reverse engineered implementations to test if they work. This is where I got stuck. Here's an example: the LogDebug function. The "empty", working pragma in the proxy DLL look like this:
#pragma comment(linker, "/export:?LogDebug##YAXPBDZZ=trueDLL.?LogDebug##YAXPBDZZ,#504")
I thought I could change the pragma like so to redirect the call to my implementation:
#pragma comment(linker, "/export:?LogDebug##YAXPBDZZ=LogInfo,#504")
Running the program, it fails to start because it can't find ?LogDebug##YAXPBDZZ. Some research shows that the ##YAXPBDZZ part isn't exported in my DLL. It appears to be some kind of info represented in the mangled name, but I couldn't find out what it actually means. Ghidra and this demangler aren't helping either, and the only search results are in russian.
Using VS 2019, no project settings are altered.
What is the problem here and how would I go about making this work? Or is there an easier/better way of achieving this? I'd like to avoid hooking the calls in the program exe for now but if I have to, I'll do it.
EDIT - Mangling scheme and compiler
I don't know exactly what was used to create DLL.dll, but according to Ghidra it was visualstudio:unknown. I'd interpret that as a 1998 (game file dates) version of MSVC. I'm using the current MSVC compiler (CL ver. 19).
It'd make sense for a current CL to use the C++ scheme. Looking at this page, and comparing it to the exports, DLL.dll appears to be using the C++ scheme too, but I could be wrong. How do I find this out for sure?
It turns out that the method in my DLL doesn't need the #pragma, as it actually overwrites the desired behaviour. If I define my function like undname.exe says and just add a __declspec(dllexport) in front, everything falls into place nicely.
I want to have google-style like code style checker that would automatically run within Clion.
However, what I found as solutions (predeclared code style for google and others, direct Editor settings and EditorConfig support in Clion help) are all rather primitive. For example, I want to use snake case with final underscore for class member fileds (e.g. my_class_member_) and usual snake case for function arguments (e.g. some_argument), and none of the suggested options would do the trick as far as I am concerned. Furthermore, some politics associated with endless loops and so are to be added, which is even more context-specific.
I consider creating cpplint.py-like script for this, but it is going to be very time-consuming and is likely to be run outside Clion. Are there any elegant ways to solve my problem?
Yeah, you able to do this! Look into Clion plug-in Clion-cpplint and use with cpplint.py script, provided by Google. You will get highlights on the fly when you are editing C++ source code.
You able to install add-on through Plugins tab in settings. In the end you will get something like:
Is there a way to sort my #include statements in Clion? Additionally, can I do this automatically every time I save? I didn't manage to find any such functionality or plugin.
Yes, it is possible with help of clang-format.
File->Settings...->Languages & Framework->C/C++->Clangd->Enable clangs server
clang-format should be installed in your system. Normally it is available in your favourite repository. You can specify the path to it if required
File->Settings...->Tools->clang-format
You have to put .clang-format file into your project root with coding rules. More information you can find on clang-format web site. For example, I am using Google coding rules. My content looks like this:
Language: Cpp
BasedOnStyle: Google
This includes already the include statements sorting. However, there is a choice of other ready-to-use coding styles like LLVM, Mozilla, WebKit, Chromium which you can use and if necessary modify or you can create your own format by providing set of rules you want. The rule you might be interesting in is
SortIncludes (bool)
If true, clang-format will sort #includes.
Please refer to the clang format documentation here
I was wondering about the BII_IMPLICIT_RULES_ENABLED flag which I had switched off in one of my CMakeLists.txt files, in order to get an OpenGL related block to compile on a Mac, following a suggestion from biicode. This setting is still there and everything works perfectly, but I would like to find out more about it. Could someone explain what it does exactly?
Thanks!
BII_IMPLICIT_RULES_ENABLED activates the addition of system libs to the target that has included certain headers. For example, if your code contains an:
#include "math.h"
And you are in *nix systems, then the library "m" (libm) will be added to your target via TARGET_LINK_LIBRARIES.
You can see the headers that are processed in your cmake/biicode.cmake file, in the HANDLE_SYSTEM_DEPS
My recommendation: Put it to False whenever possible, and handle the required system libs yourself, exactly what you have done. It is something that will be deprecated soon, or at least set to False by default to new projects. This option sometimes causes troubles, if something fails or there is a bug in biicode.cmake, e.g. in the past it tried to add libm to targets also in windows. It will be gradually deprecated and probably substituted by some CMake macros hosted (as in http://www.biicode.com/biicode/cmake) that could be used by users if they decide to, but not automatically as it is done now.
I'd like to compile differently based on which build configuration I'm using. Something like
#ifdef DEBUG
// debug code goes here
#endif
I know I can do this by defining preprocessor macros for each build configuration. But I'm wondering if there's already something built-in I can ues. Is there?
This is what I've always used and it's very clean. It also comes up when you search your code, which is nice, since settings, etc...may not.