Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to determine what macros are defined by clang and cmake

I am currently trying to convert CGAL to Javascript, by use of an amazing LLVM->Javascript project called Emscripten. I'm just doing this with the core component only (not the ImageIO or the Qt stuff)

I've managed to do that with two of its dependencies (GMP and MPFR). Much to my surprise I was able to compile C test classes to Javascript for both of those (against the generated LLVM libs in bitcode form), the output of which running in nodejs matches the native result precisely.

All the other dependencies are header-only (Eigen, Boost), except one - libboost-thread. Now, obviously JS is single threaded, so hoping to be able to drop this from the CGAL code. There is fortunately a CGAL_HAS_NO_THREADS macro, which I've define thus:

add_definitions( -DCGAL_HAS_NO_THREADS=1 )

And that does seem to be passed to the command line as a -D option

However, when I try to compile with clang (setup by running cmake via an Emscripten tool that sets up clang etc), I get a whole bunch of errors that I don't get when compiling with gcc, that seem to be twofold:

1) First is things like:

    #if defined (__GLIBC__)
#  include <endian.h>
#  if (__BYTE_ORDER == __LITTLE_ENDIAN)
#    define CGAL_LITTLE_ENDIAN
#  elif (__BYTE_ORDER == __BIG_ENDIAN)
#    define CGAL_BIG_ENDIAN
#  else
#    error Unknown endianness
#  endif
#elif defined(__sparc) || defined(__sparc__) \
   || defined(_POWER) || defined(__powerpc__) \
   || defined(__ppc__) || defined(__hppa) \
   || defined(_MIPSEB) || defined(_POWER) \
   || defined(__s390__)
#  define CGAL_BIG_ENDIAN
#elif defined(__i386__) || defined(__alpha__) \
   || defined(__x86_64) || defined(__x86_64__) \
   || defined(__ia64) || defined(__ia64__) \
   || defined(_M_IX86) || defined(_M_IA64) \
   || defined(_M_ALPHA) || defined(_WIN64)
#  define CGAL_LITTLE_ENDIAN
#else
#  error Unknown endianness
#endif

Which gives me an 'Unknown Endianness' error. I assume is due to the clang compiler not defining GLIBC macro?

The other is things like:

In file included from /home/marcosscriven/sources/openscadjs/build/CGAL-4.1/src/CGAL/all_files.cpp:1:
In file included from /home/marcosscriven/sources/openscadjs/build/CGAL-4.1/src/CGAL/Random.cpp:25:
In file included from /home/marcosscriven/sources/openscadjs/build/CGAL-4.1/include/CGAL/Random.h:30:
In file included from /home/marcosscriven/sources/openscadjs/build/CGAL-4.1/include/CGAL/basic.h:44:
In file included from /home/marcosscriven/sources/openscadjs/build/CGAL-4.1/include/CGAL/number_type_basic.h:77:
In file included from /home/marcosscriven/sources/openscadjs/build/CGAL-4.1/include/CGAL/FPU.h:60:
In file included from /usr/lib/gcc/i686-linux-gnu/4.7/../../../../include/c++/4.7/fenv.h:33:
In file included from /usr/lib/gcc/i686-linux-gnu/4.7/../../../../include/c++/4.7/i686-linux-gnu/bits/c++config.h:414:
In file included from /usr/lib/gcc/i686-linux-gnu/4.7/../../../../include/c++/4.7/i686-linux-gnu/bits/os_defines.h:40:
/home/marcosscriven/sources/includes/features.h:324:10: fatal error: 'bits/predefs.h' file not found
#include <bits/predefs.h>

Which appears to be down to clang using a different patch (or set of paths, or order of paths) to find the libs.

Now both things obviously I can hack bit by bit - but I'm guessing that's not the 'right' way.

The trouble I'm having is knowing quite what macros are defined when running clang (or even gcc)? Neither am I sure quite what all the includes in the root of the /usr/include/ are?

I know that some of them are GNUC, and that this is distinct in some way to the std libc, and libcxx libs? But not all of them?

Any help - greatly appreciated.

Marcos

like image 876
Marcos Scriven Avatar asked Oct 04 '22 21:10

Marcos Scriven


1 Answers

Putting this on the command line will output a list of defined macros:

-E -dM
like image 112
Howard Hinnant Avatar answered Oct 10 '22 03:10

Howard Hinnant