• Laurent Stacul's avatar
    Don't pollute CMAKE_REQUIRED_* variable (#1463) · 648bc92b
    Laurent Stacul authored
    Summary:
    Hello,
    
    Adding data in those variables can have an impact upon feature detections.
    
    For instance, using 'check_cxx_source_compiles' to detect libatomic can fail because the link command uses -rdynamic and the list of shared objects. But as libcrypto needs zlib which is not added in CMAKE_REQUIRED_LIBRARIES, the test will fail, as we can see here (from CMakeError.log, modified for readability):
    
    ```
    $ g++  -DNDEBUG -O3 -flto -ffat-lto-objects -fuse-linker-plugin -std=gnu++20 -fno-working-directory -ggdb3 -Wno-error=maybe-uninitialized -Wno-error=shadow=compatible-local -Wno-error=array-bounds -Wno-error=stringop-overflow -DFOLLY_CPP_ATOMIC_BUILTIN  -std=gnu++20  -DNDEBUG -O3 -Wl,-flto -ffat-lto-objects -fuse-linker-plugin -fno-working-directory -ggdb3 -L /path/to/mylibs  -pthread -lgflags -lglog -levent -levent_core -ldouble-conversion   -rdynamic CMakeFiles/cmTC_4a1a2.dir/src.cxx.o  -o cmTC_4a1a2  /path/to/mylibs/libgflags.so  /path/to/mylibs/libssl.so  /path/to/mylibs/libcrypto.so  -ldl
    ld: warning: libz.so.1, needed by /path/to/mylibs/libssl.so, not found (try using -rpath or -rpath-link)
    ld: /path/to/mylibs/libcrypto.so: undefined reference to `deflateInit_'
    ld: /path/to/mylibs/libcrypto.so: undefined reference to `deflate'
    ld: /path/to/mylibs/libcrypto.so: undefined reference to `deflateEnd'
    ld: /path/to/mylibs/libcrypto.so: undefined reference to `inflate'
    ld: /path/to/mylibs/libcrypto.so: undefined reference to `inflateInit_'
    ld: /path/to/mylibs/libcrypto.so: undefined reference to `inflateEnd'
    ld: /path/to/mylibs/libcrypto.so: undefined reference to `zError'
    ```
    I only give the example of the detection of libatomic but this error prevents the probing mechanism from detecting other features like the presence of ASN1_TIME_diff function or elf.h.
    
    I propose to avoid setting things in those variables or, if it needs to be modified, clean it up after it was useful.
    
    Pull Request resolved: https://github.com/facebook/folly/pull/1463
    
    Reviewed By: yfeldblum
    
    Differential Revision: D24000700
    
    Pulled By: Orvid
    
    fbshipit-source-id: ace1b5b5dee6362c4a30ab0a986984005e7dc569
    648bc92b
FollyConfigChecks.cmake 7.58 KB