[CMake] Adding a library to link in during TRY_RUN with Windows/nmake?

Eric Noulard eric.noulard at gmail.com
Tue Oct 12 10:25:48 EDT 2010


2010/10/12 Clifford Yapp <cliffyapp at gmail.com>:
> I'm trying to compile some C code using TRY_RUN that uses gethostname,
> but in order for this code to succeed on Windows it needs "/link
> ws2_32.lib" added to the compile line.  I have tried putting this
> string into the ARGS variable of TRY_RUN and a couple of CMake
> variables, but the compile still fails and I can't see any indications
> the extra link argument is being passed... am I doing something wrong?

May be you could the higher level "CheckCSourceRuns" modules
which has explicit var for what you want:

$ cmake --help-module CheckCSourceRuns
cmake version 2.8.2
  CheckCSourceRuns
       Check if the given C source code compiles and runs.

       CHECK_C_SOURCE_RUNS(<code> <var>)

         <code>   - source code to try to compile
         <var>    - variable to store the result
                    (1 for success, empty for failure)

       The following variables may be set before calling this macro to modify
       the way the check is run:

         CMAKE_REQUIRED_FLAGS = string of compile command line flags
         CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
         CMAKE_REQUIRED_INCLUDES = list of include directories
         CMAKE_REQUIRED_LIBRARIES = list of libraries to link



       Defined in: /usr/share/cmake-2.8/Modules/CheckCSourceRuns.cmake


>  Alternately, does anybody know of a pre-existing cross-platform way
> to get the hostname from CMake?

Don't know.

I think that on many Unix "hostname" command exists.
It looks like it exists on some Windows flavor too:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/hostname.mspx

so may be an "execute_process" call with hostname command is portable?

-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list