[CMake] Checking function or symbol in namespace

Mateusz Loskot mateusz at loskot.net
Thu Jan 21 10:59:55 EST 2010


Michael Wild wrote:
> On 21. Jan, 2010, at 16:44 , Mateusz Loskot wrote:
> 
>> Michael Wild wrote:
>>> On 21. Jan, 2010, at 24:55 , Mateusz Loskot wrote:
>>>> Hi, I'm trying to perform the following checks: 
>>>> check_function_exists(std::pow HAVE_POW) or 
>>>> check_symbol_exists(std::pow cmath HAVE_POW) but it looks that
>>>> both macros have troubles with resolving std:: namespace. The
>>>> documentation is not very clear about that. Or I should stick
>>>> to try_compile based tests? Best regards,
>>> AFAIK check_symbol_exists is used for preprocessor symbols.
>>> check_function_exists looks for C functions, not C++.
>> OK, makes sense: symbol -> preprocessor function -> real function
>> 
>> Although, for clarity, perhaps check_symbol_exists should be called
>> check_macro_exists.
> 
> No, as Marcel and I noticed, check_symbol_exists really checks
> whether that symbol exists, be it preprocessor symbol, function or
> global variable. Really, the docs should be updated to clarify this.

Gotcha. I haven't completed reading the thread yet.

>> The fact check_function_exists checks C function but not C++ free 
>> function is a bit confusing. AFAIU, CMake is dedicated to build C++
>>  source code, so I suppose many users may expect it works well for
>> both C and C++ free functions.
>> 
>> Why it can not work, actually?
> 
> Because the module writes a .c file and then compiles it with the
> C-compiler... What one needs is CheckCXXFunctionExists and
> CheckCXXSymbolExists. Or, alternatively, the modules could check the
> enabled languages and if C++ is enabled, write a C++ file (that
> should also work for C functions/symbols), otherwise fall back to
> plain C.

Both options would work well of course.
However, the latter seems to be easier to integrate seamlessly with
current set of standard macros avaialble in CMake - implementations
changes only, not interface.

For the time being, it looks like I will need to maintain private
versions of CheckCXXFunctioExists in a project.

Thanks!

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net


More information about the CMake mailing list