Bug 29228

Summary: cmake build fails on GNU platforms
Product: dbus Reporter: Manuel Traut <manut>
Component: coreAssignee: Simon McVittie <smcv>
Status: RESOLVED FIXED QA Contact: John (J5) Palmieri <johnp>
Severity: normal    
Priority: medium CC: hp, smcv
Version: 1.4.xKeywords: patch
Hardware: x86 (IA32)   
OS: Linux (All)   
URL: http://cgit.collabora.co.uk/git/user/smcv/dbus-smcv.git/log/?id=refs/heads/cmake-gnu-29228
Whiteboard:
i915 platform: i915 features:
Bug Depends on:    
Bug Blocks: 34976, 36074    
Attachments: fix missing include, and add sd-daemon.* to CMakeLists.txt
cmake: always enable GNU and recent-POSIX extensions, like autoconf does
replacement patch for current dbus-1.4
alternative patch: revert Lennart's change to how this works

Description Manuel Traut 2010-07-23 07:46:50 UTC
Created attachment 37336 [details]
fix missing include, and add sd-daemon.* to CMakeLists.txt

- bus/activation-helper.h should include dbus-errors.h
- ld failed, because sd_is_socket, isn't defined

The attached patch fixes this issues.
Comment 1 Simon McVittie 2011-02-08 08:18:32 UTC
(In reply to comment #0)
> - bus/activation-helper.h should include dbus-errors.h

Strictly speaking, yes (or <dbus/dbus.h> would be even better). However, this doesn't seem to be a practical problem at the moment, because everything that includes it includes either utils.h or test.h first?

> - ld failed, because sd_is_socket, isn't defined

Already fixed in git, will be in 1.4.4, 1.5.0.
Comment 2 Simon McVittie 2011-04-26 07:51:24 UTC
(In reply to comment #1)
> However, this
> doesn't seem to be a practical problem at the moment, because everything that
> includes it includes either utils.h or test.h first?

Confirmed to be not a practical problem, at least on Linux. However, the build fails for an unrelated reason. Patch on the way.
Comment 3 Simon McVittie 2011-04-26 07:51:53 UTC
Created attachment 46089 [details] [review]
cmake: always enable GNU and recent-POSIX extensions, like  autoconf does

Not doing this broke the cmake build on Linux, where SO_PEERCRED is
defined unconditionally, but struct ucred is considered to be a GNU
extension.
Comment 4 Ralf Habacker 2011-07-02 17:06:48 UTC
(In reply to comment #3)
> Created an attachment (id=46089) [details]
> cmake: always enable GNU and recent-POSIX extensions, like  autoconf does
> 
> Not doing this broke the cmake build on Linux, where SO_PEERCRED is
> defined unconditionally, but struct ucred is considered to be a GNU
> extension.

In configure.ac the following defines are only added when activating ansi as shown: 
  if test "x$enable_ansi" = "xyes"; then
    TP_ADD_COMPILER_FLAG([WARNING_CFLAGS],
      [-ansi -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE -pedantic])
  fi

would it not make sense to use the same context ? 

Additional autotools uses _BSD_SOURCE instead of _GNU_SOURCE.
Comment 5 Simon McVittie 2011-07-11 00:51:20 UTC
The flags other than -ansi -pedantic are probably redundant now, because AC_USE_SYSTEM_EXTENSIONS (further up configure.ac) defines __EXTENSIONS__, _ALL_SOURCE, _GNU_SOURCE, _POSIX_PTHREAD_SEMANTICS, _TANDEM_SOURCE (some of which are only necessary on certain platforms).

See commit 18b08180 - the changes to .c files in that commit are what broke the cmake build on Unix.
Comment 6 Will Thompson 2011-07-18 10:58:08 UTC
Review of attachment 46089 [details] [review]:

Won't this also define them when using MSVC? (I don't really speak CMake.)
Comment 7 Simon McVittie 2011-07-18 11:09:35 UTC
(In reply to comment #6)
> Won't this also define them when using MSVC? (I don't really speak CMake.)

Yes, but so does configure (via AC_USE_SYSTEM_EXTENSIONS), so...

As far as I understand it, the purpose of _GNU_SOURCE etc. is that when they're not defined, glibc hides functionality that is in a namespace reserved by the C or POSIX standard, but not specified by that standard; for instance, strfry(3) is only declared if you define _GNU_SOURCE, because strictly speaking, anything starting with str is meant to be reserved by ISO C.

Only libc headers should be testing those macros; they're not like "#define __linux__" or similar. They're an opt-in to extra GNU features, not a feature test.
Comment 8 Simon McVittie 2011-07-27 09:15:09 UTC
Created attachment 49618 [details] [review]
replacement patch for current dbus-1.4

Updated version of the patch, with a hopefully-clearer description:

    cmake: always enable GNU and recent-POSIX extensions, like autoconf does
    
    If the C library is (e)glibc, this allows use of POSIX, BSD, SVID, GNU,
    etc., extensions to ISO C, regardless of using -ansi or not.
    
    Not doing this broke the cmake build on Linux since commit 18b08180,
    which added AC_USE_SYSTEM_EXTENSIONS to configure.ac (and removed
    _GNU_SOURCE from files that use it) without also updating the cmake
    build system. SO_PEERCRED is defined unconditionally, but struct ucred
    is considered to be a GNU extension, so can't be used under _GNU_SOURCE.
Comment 9 Simon McVittie 2011-07-27 09:16:22 UTC
Created attachment 49619 [details] [review]
alternative patch: revert Lennart's change to how this works

If people would prefer it, this is the other way this could be fixed:

    Define _GNU_SOURCE in files that need it (again)
    
    This reverts commit 18b08180aa5a4417fa1d6d268a1aad894e8a4549.
Comment 10 Will Thompson 2011-08-05 04:31:01 UTC
Review of attachment 49618 [details] [review]:

I think this is fine, ship it.
Comment 11 Simon McVittie 2011-08-05 06:38:27 UTC
(In reply to comment #10)
> Review of attachment 49618 [details] [review]:
> 
> I think this is fine, ship it.

Shipped it. 1.4.16, 1.5.8.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.