ifdef __linux__ / gtk issue; how to list defined symbols for cmake?
Jan Beich
jbeich at FreeBSD.org
Wed Jun 26 10:34:37 UTC 2019
Gary Aitken <freebsd at dreamchaser.org> writes:
> 1. Is there an easy way to get a list of all the __*__ symbols?
# Works for GCC, Clang and some arcane compilers
$ cc -dM -E -</dev/null
# Clang being a cross-compiler can check other targets
$ clang -target x86_64-apple-darwin18.2.0 -dM -E -</dev/null | fgrep -i -e unix -e apple
#define __APPLE_CC__ 6000
#define __APPLE__ 1
$ clang -target armv7-unknown-freebsd12.0-gnueabihf -dM -E -</dev/null | fgrep -i neon
#define __ARM_NEON 1
#define __ARM_NEON_FP 0x4
#define __ARM_NEON__ 1
> Where / how are these set up?
Predefined macros are set by the compiler. Some are architecture-specific,
some are OS-specific, some depend on flags, etc.
https://gcc.gnu.org/onlinedocs/cpp/Predefined-Macros.html
For one, __FreeBSD__ is defined in
/usr/src/contrib/llvm/tools/clang/lib/Basic/Targets/OSTargets.h
/usr/src/contrib/gcc/config/freebsd-spec.h
> Is there a way to list them at the start of compilation of each file
> to check the appropriate ones are all defined in different subdirs
> of the build tree?
Unlikely without hacking the build glue to add a separate step for -dM -E.
> If __linux__ is defined, is __unix__ also defined? If any of the
> __*BSD__ syms are defined, is __unix__ also defined?
__unix__ is defined on (m)any Unix-like system except macOS despite macOS
being on of the few certified UNIX. Go figure. ;)
https://sourceforge.net/p/predef/wiki/OperatingSystems/
> 3. What's the relationship between the _WIN32, __APPLE__, __unix__ type
> syms in code and the WIN32, APPLE, UNIX, XCODE syms that I see in
> some of the CMakeLists.txt files?
CMake predefines some variables and even more are defined by cmake-modules(7).
However, UNIX is defined on macOS unlike __unix__. What a rotten apple. ;)
https://github.com/Kitware/CMake/blob/v3.14.5/Source/cmStateSnapshot.cxx#L298-L355
https://github.com/Kitware/CMake/blob/v3.14.5/Source/cmGlobalXCodeGenerator.cxx#L297-L298
> Are any/all of these case sensitive?
Yep if the underlying programming language is case-sensitive.
> How is CMAKE_SYSTEM_NAME, which may be "Linux" (on linux), related to
> the above syms?
See /usr/local/share/cmake/Modules/CMakeDetermineSystem.cmake
>
> 4. Suggestions on how to approach this? I'm inclined to change the
> "#if defined(__linux__)" to "#if defined(__WXGTK__)" where appropriate
> instead of adding
> "|| defined(__FreeBSD__) || defined(__NetBSD__)..." etc.
Probably OK but I don't have experience porting WX-based apps. Try to
insert #error first to make sure __WXGTK__ is defined in all the places
you're trying to use it.
> Is there a "BSD" sym that encompasses the various bsd variants?
AFAIK, "BSD" defined in <sys/param.h> is a vestige from when BSD was an
actual Unix distribution developed by CSRG at UC Berkeley. As macOS and
GNU/kFreeBSD also define "BSD" it's not very useful.
https://svnweb.freebsd.org/csrg?view=revision&revision=24654
http://fxr.watson.org/fxr/source/bsd/sys/param.h?v=xnu-2050.18.24#L72
More information about the freebsd-ports
mailing list