Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
36 changes: 36 additions & 0 deletions cmake/check_c_compiler_uses_glibc.cmake
Original file line number Diff line number Diff line change
@@ -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 <execinfo.h>

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()
1 change: 0 additions & 1 deletion src/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ extern "C"
{
#endif

#define _GNU_SOURCE
#include <errno.h>
#include <stdlib.h>
#include <string.h>
Expand Down