[CMake] several questions about cmake

Mike McQuaid mike at mikemcquaid.com
Thu Aug 26 02:12:27 EDT 2010

On 26 August 2010 01:34, Mark Roden <mmroden at gmail.com> wrote:
> I'm starting to get deep into CMake, and I have a few questions as I
> try to convert the socket++ library such that it can be compiled by
> CMake on Windows.
> 1) The default install directory on Windows is C:\Program Files, or
> C:\Program Files (x86) on 64 bit.  This default will not work on
> Windows 7 (and perhaps Vista), because the user isn't running as
> administrator anymore, and only administrators can modify that
> directory.  There should probably be a warning to that effect on
> windows systems; otherwise, there are painful ways to run install, but
> they are painful.

Most developers run as administrator so I don't think there should be a warning.

> 2) I'm trying to check to see if a certain C++ code chunk will
> compile.  The line is:
> #include <string.h>
> #include <stdio.h>
>  void main(){
>  char buf[100];
>  char buf2[100];
>  strncpy(buf2, buf, 5);
>  buf2[5] = '\0';
>  puts(buf2);
>  }" EXTERN_C)
> The EXTERN_C test is failing here.  The problem is, I can cut and
> paste that code into a blank project in vs2008 and it compiles just
> fine.  Is there a way to see the compiler error, or to determine why
> that would fail?
> The code in the configure.in file is:
> # include <string.h>
> # include <stdio.h>
> ], [
>  char buf[100];
>  strcpy(buf, "Hello world\n");
> ],
>  bz_cv_cplusplus_needexternCwrapper=no,
>  bz_cv_cplusplus_needexternCwrapper=yes)
> ])
> I can't use that directly (or can I?) because the quotation marks in
> "Hello World" prematurely cut off the code in the SOURCE section of
> CHECK_CXX_SOURCE_COMPILES, and I get an error that the variable World"
> makes no sense.

You can use quotes by doing \" rather than ".

> 3) There is a check for the presence of the Libg++ library, but no
> specific mention of which function is needed.  According to what I can
> find on CheckLibraryExists, I need to provide a specific function to
> determine if that library is present.  The code in configure.in is:
> In that case, should I be looking for a particular function in
> _G_config.h (which I don't have, since I'm on Windows) and just using
> it arbitrarily?  I'm not even close to the point where this code can
> fail in compilation and therefore determine the error directly.

I don't think you need to check for that library, certainly not on Windows.

> 4) There are two checks for potentially predefined variables, namely
> sys_siglist and sys_errlist.  The code to check for these looks like:
> AC_CACHE_VAL(socketxx_cv_siglist, [
> # include <unistd.h>
> # include <sys/signal.h>
> ], [
> #ifndef _sys_siglist
>  extern char* _sys_siglist[];
> #endif
>  puts(*_sys_siglist);
> ],
> socketxx_cv_siglist=_sys_siglist,
> socketxx_cv_siglist=sys_siglist) ])
> AC_DEFINE_UNQUOTED(SYS_SIGLIST, $socketxx_cv_siglist)
> Windows doesn't have unistd.h or sys/signal.h, so I know that this
> will fail, regardless of the test.  I'm unfamiliar with these
> variables; does anyone have any insight into them?  It looks like if
> the code compiles, the variable _sys_siglist will be used, otherwise,
> sys_siglist, whatever that is.  I'm tempted to just say that it is
> what it is, and if other unix users have issues, we can fix the cmake
> file then.  The typical sloppiness of someone not dealing with their
> native platform, I guess :)
> There are other problems with converting this file, but I want to
> start with this one and still hack away at the others.

I'd recommend looking at the manpages for these functions and trying
to find a native equivalent you can check for and extend the check.

I wouldn't try and copy all the autoconf checks exactly, just get your
project building first and then create the ones you actually need.

Mike McQuaid

More information about the CMake mailing list