[CMake] Compatibility between cmake-based directives and autoconf-based directives

Alexander Neundorf a.neundorf-work at gmx.net
Tue Feb 5 13:23:48 EST 2013


On Tuesday 05 February 2013, DRypl wrote:
> Is there a way how to avoid problems with different declarations of
> directives depending whether
> using autoconf (for a library) and cmake (for my application using that
> library). For example autoconf
> declares "#define HAVE_UNISTD_H 1" while cmake declares "#define
> HAVE_UNISTD_H".
> Using #cmakedefine01 instead of #cmakedefine does not solve the problem
> because statement
> "#define HAVE_UNISTD_H 0" is apparently something else than "#undef
> HAVE_UNISTD_H" (and the
> library is using preprocessing checks as "#ifdef HAVE_UNISTD_H"). I also
> did not find solution in autoconf.


Try the following CMakeLists.txt:


cmake_minimum_required(VERSION 2.8)

set(HAVE_A TRUE)
set(HAVE_B TRUE)
set(HAVE_C FALSE)
set(HAVE_D FALSE)

configure_file(config.h.in config.h)


with the following config.h.in:
#cmakedefine HAVE_A 1
#cmakedefine HAVE_B
#cmakedefine HAVE_C 1
#cmakedefine HAVE_D

#cmakedefine01 HAVE_A
#cmakedefine01 HAVE_B
#cmakedefine01 HAVE_C
#cmakedefine01 HAVE_D

and look at the resulting config.h.

I think
#cmakedefine HAVE_FOO 1
is what you want.

Alex


More information about the CMake mailing list