microsoft / omi

Open Management Infrastructure
Other
360 stars 114 forks source link

Change macos macro to avoid conflict with system defined macro #669

Closed jborean93 closed 3 years ago

jborean93 commented 4 years ago

It seems like on recent builds of macOS (I think since 10.12) some of the system headers have defined the macos macro which conflicts with the -Dmacos macro we define when calling clang. This PR changes the macos macro used by omi to is_macos to avoid this conflict.

Before the PR running ./configure would fail with

*** UNABLE TO LOCATE FILE omi.version; USING VERSION 1.0.8.6 ***
*** Update build process to include omi.version from superproject! ***
checking whether pkg-config command is on the path... yes
created /Users/jborean/dev/omi/Unix/output
checking whether C compiler is on the path... yes
checking whether C compiler compiles... yes
checking whether C program executes... yes
checking for __FUNCTION__ macro or reserved word... yes
checking for __builtin_ctz... no
checking for __builtin_prefetch... yes
checking for sched_getcpu... no
checking for wcstoll... no
checking for wcsdup... no
checking for wcscasecmp, wcsncasecmp... no
checking for vswscanf... no
checking for va_copy... no
checking for backtrace... no
checking for __sync_synchronize... yes
checking for Atomic Intrinsic Functions... no
checking for sem_timedwait... no
checking for strerror_r... yes
checking for pthread_rwlock_t... no

That's because it's trying to compile and run the following code

cat > /tmp/pthread_rwlock_t_func.c <<EOF
#include <pthread.h>
int main()
{
    pthread_rwlock_t lock = PTHREAD_RWLOCK_INITIALIZER;
    (void)lock;
    return 0;
}
EOF

clang -g -O2 -Wall -I/usr/local/include -Dmacos -fvisibility=hidden -fstack-protector-all -DGSS_USE_IOV=1 -o /tmp/pthread_rwlock_t_func /tmp/pthread_rwlock_t_func.c

This fails with multiple errors of the following

In file included from /tmp/pthread_rwlock_t_func.c:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pthread.h:73:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pthread/qos.h:34:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/qos.h:132:31: error: expected ','
                        __QOS_CLASS_AVAILABLE(macos(10.10), ios(8.0)) = 0x21,
                                                   ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/qos.h:126:31: note: expanded from macro
      '__QOS_CLASS_AVAILABLE'
#define __QOS_CLASS_AVAILABLE __API_AVAILABLE

After this change I am able to compile and build OMI on my macOS host. I'm mostly doing this so I have a libmi.dylib that is linked to OpenSSL 1.1 and not 1.0 that comes with PowerShell. If you wish to change the macro to another name, happy to change it to whatever you suggest.

JumpingYang001 commented 3 years ago

thanks for PR! but omi has dropped powershell and mac support on 2018, and it is only used by SCOM and OMS/LAD now.