[CMake] Testing for time.h on various platforms
Hendrik Sattler
post at hendrik-sattler.de
Sat Apr 5 04:52:09 EDT 2008
Am Freitag 04 April 2008 schrieb Mike Jackson:
> I am looking for a game plan (or code..) to test for a header file and
> where the "correct" location of that header might be. Seems on some
> systems, time.h should be <sys/time.h> were on others it is just
> <time.h>. Should I create some cmake code to test each one
> individually? or is there a more common/scalable approach for this
> type of thing?
Explicitely testing this is kinda the way of autoconf. There is another way,
though: add a compatibility include file layer that you include depending on
the system, e.g. include/compat/some_system/time.h:
#include <sys/time.h>
and add include/compat/some_system to the system include path. Now, you code
contains _much_ less ifdefs (good). And knowing the some_system type you
kinda get for free. I did this e.g. for inttypes.h + stdint.h on
VisualStudio. This actually means that some_system may be one of system or
compiler, e.g. platform/win32 vs. compiler/msvc, and both cases have to be
handled.
HS
More information about the CMake
mailing list