Making non-standard OS checks in cmake?
Pau Garcia i Quiles
pgquiles at elpauer.org
Fri Jan 1 19:43:10 CET 2010
On Fri, Jan 1, 2010 at 7:22 PM, Raphael Kubo da Costa <kubito at gmail.com> wrote:
> On Friday 01 January 2010 16:01:14 Alexander Neundorf wrote:
>> On Friday 01 January 2010, Raphael Kubo da Costa wrote:
>> > Hey there,
>> >
>> > As you can see on my.cdash.org, both kdeadmin and kdenetwork fail to
>> > build
>> >
>> > cleanly on FreeBSD:
>> > * kdeadmin/kuser's CMakeLists.txt's check for the need to link against -
>> >
>> > lcrypt is broken on FreeBSD, since the crypt() function is defined in
>> > unistd.h, not crypt.h, even though -lcrypt still must be passed to the
>> > compiler
>>
>> Does crypt.h also exist ?
>> You could also try check_symbol_exists() (
>> http://www.cmake.org/cmake/help/cmake2.6docs.html#module:CheckSymbolExists
>> ) to find out whether crypt() is in unistd.h or crypt.h
> No, crypt.h doesn't exist. Would check_symbol_exists() not work then? How
> about using check_library_exists()?
Something like this should work in all cases:
find_file( CRYPT_HEADER crypt.h )
find_library( CRYPT_LIBRARY crypt )
if( NOT CRYPT_HEADER )
set( CRYPT_HEADER unistd.h )
endif( NOT CRYPT_HEADER)
include(CheckFunctionExists)
include(CheckLibraryExists)
set(CMAKE_REQUIRED_INCLUDES ${CRYPT_HEADER})
check_function_exists(crypt CRYPT3_EXISTS)
if(NOT CRYPT3_EXISTS)
if(CRYPT_LIBRARY)
set(CMAKE_REQUIRED_LIBRARIES "crypt")
set(CMAKE_REQUIRED_INCLUDES ${CRYPT_HEADER})
check_function_exists(crypt CRYPT3_EXISTS_WITH_LIBRARY)
endif(CRYPT_LIBRARY)
endif(NOT CRYPT3_EXISTS)
if(CRYPT3_EXISTS OR CRYPT3_EXISTS_WITH_LIBRARY)
# add_executable, or whatever you should do if crypt(3) is available
endif(CRYPT3_EXISTS OR CRYPT3_EXISTS_WITH_LIBRARY)
if( CRYPT3_EXISTS_WITH_LIBRARY )
target_link_libraries( yourtarget ${CRYPT_LIBRARY} )
endif( CRYPT3_EXISTS_WITH_LIBRARY )
It's probably possible to simplify it but I'm not in the mood just now :-)
--
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)
More information about the Kde-buildsystem
mailing list