[CMake] several questions about cmake

Michael Wild themiwi at gmail.com
Thu Aug 26 02:17:17 EDT 2010


On 26. Aug, 2010, at 1:34 , Mark Roden 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.
> 

Cool!

> 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.

I hope you will create an installer using CPack, and most users will then use that instead of compiling from sources, so IMHO that is no real problem.

> 
> 2) I'm trying to check to see if a certain C++ code chunk will
> compile.  The line is:
> 
> CHECK_CXX_SOURCE_COMPILES("
> #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:
> 
> AC_TRY_LINK([
> # 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.

Just put \ in front of the quotation marks, and the hello world code will work.


> 
> 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:
> 
> AC_CHECK_HEADER(_G_config.h, AC_DEFINE(_S_LIBGXX))
> 
> 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.

In that case I just find a sufficiently unique function in libg++ (using e.g. the nm tool on Unix systems or dumpbin on Windows). But what above code actually does corresponds to

find_file(G_CONFIG_H_PATH _G_config.h)
if(G_CONFIG_H_PATH)
  set(_S_LIBGXX 1)
else()
  set(_S_LIBGXX 0)
endif()

Actually, it does a bit more (see the docs of AC_DEFINE), but I don't think it is relevant to you.

> 
> 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, [
> AC_TRY_LINK([
> # 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 :)
> 

Those are definitely unixy, they contain operating system signal and error descriptions and are usually accessed through the psginal, strsignal, perror and strerror family of functions. Normally they should not be accessed directly. I think the above code assumes it's running on Unix and just determines whether the C library implementor prefixed the variables with a _ (to mark them for internal use only).

> There are other problems with converting this file, but I want to
> start with this one and still hack away at the others.
> 
> Thanks!
> Mark

HTH

Michael



More information about the CMake mailing list