[CMake] detecting __attribute__((weak)) support
Laurent Demailly
ldemailly at fb.com
Mon Jan 19 18:35:27 EST 2015
Pending (possible) built-in support in cmake, looks like I could use
check_cxx_source_compiles(
"extern \"C\" void cmkcheckweak() __attribute__((weak));
int main(int argc, char** argv) {
return cmkcheckweak == nullptr; // works with (void*)0;
}" HAVE_WEAK_SYMBOLS)
But that doesn't work because check_cxx_source_compiles doesn't (by
default - how do I tell it to?) use the compiler flags (like -std=gnu++11)
needed to compile this (while in this case there is an easy workaround -
how do I do this in general)
Filled the 2 issues:
http://public.kitware.com/Bug/view.php?id=15359 for weak symbol knowledge
by cmake
http://public.kitware.com/Bug/view.php?id=15361 for
check_cxx_source_compiles
Thanks!
Laurent
On 1/19/15, 1:35 PM, "Laurent Demailly" <ldemailly at fb.com> wrote:
>I searched and didn't find yet would it be reasonable to have built in
>support in cmake for knowing if the platform/compiler supports weak
>symbols ?
>
>I'm porting the following autconf fragment:
>
>AC_CACHE_CHECK(
> [for weak symbol support],
> [folly_cv_prog_cc_weak_symbols],
> [AC_LINK_IFELSE(
> [AC_LANG_SOURCE[
> extern "C" void configure_link_extern_weak_test()
>__attribute__((weak));
> int main(int argc, char** argv) {
> return configure_link_extern_weak_test == nullptr;
> }]],
> [folly_cv_prog_cc_weak_symbols="yes"],
> [folly_cv_prog_cc_weak_symbols="no"])])
>
>if test "$folly_cv_prog_cc_weak_symbols" = yes; then
> AC_DEFINE([HAVE_WEAK_SYMBOLS], [1],
> [Define to 1 if the linker supports weak symbols.])
>fi
>
>And I'm not sure what's the best way to do such recipe in Cmake ?
>(by hand for now pending possible support in 3.2+ maybe)
>
>
>Laurent
More information about the CMake
mailing list