diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f7429cf..a7ffe516 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,16 @@ find_package(ament_cmake_ros REQUIRED) ament_python_install_package(${PROJECT_NAME}) +if(UNIX AND NOT APPLE) + include(cmake/check_c_compiler_uses_glibc.cmake) + check_c_compiler_uses_glibc(USES_GLIBC) + if(USES_GLIBC) + # Ensure GNU extended libc API is used, as C++ test code will. + # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=2082. + add_definitions(-D_GNU_SOURCE) + endif() +endif() + if(NOT WIN32) add_compile_options(-Wall -Wextra -Wpedantic) endif() diff --git a/cmake/check_c_compiler_uses_glibc.cmake b/cmake/check_c_compiler_uses_glibc.cmake new file mode 100644 index 00000000..46755bec --- /dev/null +++ b/cmake/check_c_compiler_uses_glibc.cmake @@ -0,0 +1,36 @@ +# Copyright 2020 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# Checks if the C compiler uses glibc. +# +# @private +# +function(check_c_compiler_uses_glibc result_variable) + include(CheckCSourceCompiles) + + set(GLIBC_TEST_CODE [====[ + #include + + int main() { + void * buffer[1]; + int size = sizeof(buffer) / sizeof(void *); + backtrace(&buffer, size); + return 0; + } + ]====]) + + check_c_source_compiles("${GLIBC_TEST_CODE}" ${result_variable}) + set(${result_variable} ${result_variable} PARENT_SCOPE) +endfunction() diff --git a/src/process.c b/src/process.c index 832c3d1a..e821120d 100644 --- a/src/process.c +++ b/src/process.c @@ -17,7 +17,6 @@ extern "C" { #endif -#define _GNU_SOURCE #include #include #include