Can cmake do configure tests?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Can cmake do configure tests?

Joseph Garvin
One of the cool features of autotools is configure tests -- actually invoking the compiler on a small sample program and seeing if it's successful. Does CMake do this or do you have to depend on #ifdef SOME_PLATFORM blocks to enable/disable features?

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Can cmake do configure tests?

Michael Wild

On 6. Aug, 2009, at 3:03, Joseph Garvin wrote:

> One of the cool features of autotools is configure tests -- actually
> invoking the compiler on a small sample program and seeing if it's
> successful. Does CMake do this or do you have to depend on #ifdef
> SOME_PLATFORM blocks to enable/disable features?
>

Yep, definitely possible. You can check for the availability of  
functions, structs, symbols, libraries, headers etc. If that is not  
enough, you can try to compile your own test code, and even try to run  
it (although that has its problems when cross-compiling)


Michael

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Can cmake do configure tests?

Michael Jackson
In reply to this post by Joseph Garvin
Here is some snippets from a project that I use: (hdf5)

# Include all the necessary files for macros
INCLUDE (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFileCXX.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFiles.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckLibraryExists.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckSymbolExists.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake)

CHECK_LIBRARY_EXISTS("ws2_32" printf HAVE_LIBWS2_32)
CHECK_LIBRARY_EXISTS("wsock32" printf HAVE_LIBWSOCK32)

CHECK_TYPE_SIZE(char           SIZEOF_CHAR)
CHECK_TYPE_SIZE(short          SIZEOF_SHORT)
CHECK_TYPE_SIZE(int            SIZEOF_INT)
CHECK_TYPE_SIZE(long           SIZEOF_LONG)

CHECK_FUNCTION_EXISTS(strdup            HAVE_STRDUP)
CHECK_FUNCTION_EXISTS(snprintf          HAVE_SNPRINTF)
CHECK_FUNCTION_EXISTS(system            HAVE_SYSTEM)

CHECK_SYMBOL_EXISTS(TIOCGWINSZ "sys/ioctl.h" HAVE_TIOCGWINSZ)
CHECK_SYMBOL_EXISTS(TIOCGETD   "sys/ioctl.h" HAVE_TIOCGETD)


While there are standard tests that CMake can perform if you need  
something more specialized then you can write your own test.

HTH
_________________________________________________________
Mike Jackson                  [hidden email]
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio



On Aug 5, 2009, at 9:03 PM, Joseph Garvin wrote:

> One of the cool features of autotools is configure tests -- actually  
> invoking the compiler on a small sample program and seeing if it's  
> successful. Does CMake do this or do you have to depend on #ifdef  
> SOME_PLATFORM blocks to enable/disable features?
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Can cmake do configure tests?

Alexander Neundorf-3
On Thursday 06 August 2009, Michael Jackson wrote:

> Here is some snippets from a project that I use: (hdf5)
>
> # Include all the necessary files for macros
> INCLUDE (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
> INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
> INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFileCXX.cmake)
> INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFiles.cmake)
> INCLUDE (${CMAKE_ROOT}/Modules/CheckLibraryExists.cmake)
> INCLUDE (${CMAKE_ROOT}/Modules/CheckSymbolExists.cmake)
> INCLUDE (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake)

The above can be shortened to

INCLUDE (CheckFunctionExists)
INCLUDE (CheckIncludeFile)
INCLUDE (CheckIncludeFileCXX)
INCLUDE (CheckIncludeFiles)
INCLUDE (CheckLibraryExists)
INCLUDE (CheckSymbolExists)
INCLUDE (CheckTypeSize)

> CHECK_LIBRARY_EXISTS("ws2_32" printf HAVE_LIBWS2_32)
> CHECK_LIBRARY_EXISTS("wsock32" printf HAVE_LIBWSOCK32)
>
> CHECK_TYPE_SIZE(char           SIZEOF_CHAR)
> CHECK_TYPE_SIZE(short          SIZEOF_SHORT)
> CHECK_TYPE_SIZE(int            SIZEOF_INT)
> CHECK_TYPE_SIZE(long           SIZEOF_LONG)
>
> CHECK_FUNCTION_EXISTS(strdup            HAVE_STRDUP)
> CHECK_FUNCTION_EXISTS(snprintf          HAVE_SNPRINTF)
> CHECK_FUNCTION_EXISTS(system            HAVE_SYSTEM)
>
> CHECK_SYMBOL_EXISTS(TIOCGWINSZ "sys/ioctl.h" HAVE_TIOCGWINSZ)
> CHECK_SYMBOL_EXISTS(TIOCGETD   "sys/ioctl.h" HAVE_TIOCGETD)

and usually after all that you want to use the configure_file() command to
generate your specific config.h

Alex
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake