• Alex Wang's avatar
    Fix some `CMAKE_REQUIRED_FLAGS` stuff (#811) · 38589135
    Alex Wang authored
    Summary:
    This fixes two issues related to CMAKE_REQUIRED_FLAGS
    
    ----
    
    CMAKE_REQUIRED_FLAGS, unlike the other CMAKE_REQUIRED_* variables, is a
    string, not a list. A list with more than one item in
    CMAKE_REQUIRED_FLAGS results in a semicolon showing up in the middle of
    the command line for at least check_symbol_exists and check_type_size
    calls, prematurely terminating the compilation command and resulting in
    potentially incorrect CMake test failures.
    
    For example, CMake fails to determine the size of __int128 on macOS
    10.13.3, with Apple Clang 9 (clang-900.0.39.2), even though __int128 is
    supported for this platform, as the following C program
    
        int main() {
            __int128 i;
        }
    
    compiles successfully with the command "clang test.c". CMake fails to
    compile a program with __int128 for an entirely different reason:
    
        Building CXX object CMakeFiles/cmTC_d7e3f.dir/INT128_SIZE.cpp.o
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++  -DGFLAGS_IS_A_DLL=0 -isystem /usr/local/include -I/usr/local/opt/openssl@1.1/include  -fsanitize=address,undefined -std=gnu++14;-Werror=unknown-warning-option   -o CMakeFiles/cmTC_d7e3f.dir/INT128_SIZE.cpp.o -c /Users/awang/code/CRES/scc-analysis/build-debug/CMakeFiles/CheckTypeSize/INT128_SIZE.cpp
        clang: error: no input files
        /bin/sh: -Werror=unknown-warning-option: command not found
        make[1]: *** [CMakeFiles/cmTC_d7e3f.dir/INT128_SIZE.cpp.o] Error 127
        make: *** [cmTC_d7e3f/fast] Error 2
    
    Using set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} <new_flag>")
    avoids this problem.
    
    ----
    
    CMAKE_REQUIRED_FLAGS is given to both C and C++ compiler invocations.
    The C++-specific flag -std=gnu++14 causes compilation to fail on Apple
    LLVM 9.1.0 (clang-902.0.39.2) with errors along the lines of:
    
        Building C object CMakeFiles/cmTC_af532.dir/CheckSymbolExists.c.o
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -DGFLAGS_IS_A_DLL=0 -isystem /usr/local/include -I/usr/local/opt/openssl@1.1/include  -std=gnu++14   -o CMakeFiles/cmTC_af532.dir/CheckSymbolExists.c.o   -c /Users/awang/code/CRES/scc-analysis/build-debug/CMakeFiles/CMakeTmp/CheckSymbolExists.c
        error: invalid argument '-std=gnu++14' not allowed with 'C/ObjC'
        make[1]: *** [CMakeFiles/cmTC_af532.dir/CheckSymbolExists.c.o] Error 1
        make: *** [cmTC_af532/fast] Error 2
    
    The affected functions are:
    
      - pthread_atfork
      - memrchr
      - preadv
      - pwritev
      - clock_gettime
      - cplus_demangle_v3_callback
      - malloc_usable_size
    
    Of these, only pthread_atfork and clock_gettime were detected as being
    absent when they were actually present.
    
    The failure to correctly identify the presence of pthread_atfork, at
    least, can cause Folly to fail to build on macOS because Folly requires
    pthread_atfork for macOS but thinks it is absent due to the failed test.
    Closes https://github.com/facebook/folly/pull/811
    
    Reviewed By: simpkins
    
    Differential Revision: D7502576
    
    Pulled By: yfeldblum
    
    fbshipit-source-id: a508e432e460cf5492e5c74da7c8b1190ec923a3
    38589135
FollyConfigChecks.cmake 6.74 KB