check_cxx_source_compiles(<code> <resultVar> [FAIL_REGEX <regex1> [<regex2>...]])
check_cxx_source_compiles(<code> <resultVar> [FAIL_REGEX <regex1> [<regex2>...]])
CHECK_CXX_SOURCE_COMPILES(
"${find_standard_math_library_test_program}"
standard_math_library_linked_to_automatically
)
check_cxx_source_compiles("
#include <cstddef>
#include <dlfcn.h>
int main()
{
void *handle = dlopen (\"somelib.so\", RTLD_LAZY);
return handle == NULL || dlerror();
}
" HAVE_DLOPEN)
check_cxx_source_compiles ("#include <type_traits>\nint main() { return std::${TYPE_TRAIT}<bool>::value; }" ${UPPERCASE_${TYPE_TRAIT}})
check_cxx_source_compiles ("#include <type_traits>\nint main() { return std::${TYPE_TRAIT}<bool>::value; }" ${UPPERCASE_${TYPE_TRAIT}})
CHECK_CXX_SOURCE_COMPILES("int main() { return 0;}" ${_RESULT}
# Some compilers do not fail with a bad flag
FAIL_REGEX "error: bad value (.*) for .* switch" # GNU
FAIL_REGEX "argument unused during compilation" # clang
FAIL_REGEX "is valid for .* but not for C\\\\+\\\\+" # GNU
FAIL_REGEX "unrecognized .*option" # GNU
FAIL_REGEX "ignoring unknown option" # MSVC
FAIL_REGEX "[Uu]nknown option" # HP
FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro
FAIL_REGEX "command option .* is not recognized" # XL
FAIL_REGEX "WARNING: unknown flag:" # Open64
FAIL_REGEX " #10159: " # ICC
)
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
std::atomic<int> x;
int main() {
return x;
}
" ${varname})
check_cxx_source_compiles("#include <cstdio>\nint main(){}" CSTDIO_INCLUDE_TRY1)
CHECK_CXX_SOURCE_COMPILES(
"${find_standard_math_library_test_program}"
standard_math_library_linked_to_automatically
)
check_cxx_source_compiles("int main(int argc,char*argv[]){(void)argc;(void)argv;return 0;}" ${VAR} FAIL_REGEX "(unsupported|syntax error)")
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
std::atomic<int> x;
int main() {
return x;
}
" ${varname})
check_cxx_source_compiles("${draco_cxx_main}" linker_flag_test_passed)
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
std::atomic<int> x;
int main() {
return x;
}
" ${varname})
check_cxx_source_compiles("#include <atomic>
std::atomic<int> foo{0};
int main() { return foo.fetch_add(2); }"
HAVE_LIBATOMIC)
CHECK_CXX_SOURCE_COMPILES(
"${find_standard_math_library_test_program}"
standard_math_library_linked_to_automatically
)
check_cxx_source_compiles("int main(int argc,char*argv[]){(void)argc;(void)argv;return 0;}" ${VAR} FAIL_REGEX "(unsupported|syntax error)")
check_cxx_source_compiles("int main(int argc,char*argv[]){(void)argc;(void)argv;return 0;}" ${VAR} FAIL_REGEX "(unsupported|syntax error)")
check_cxx_source_compiles("${CXX14_TEST_SOURCE}" CXX14_FLAG_DETECTED)
check_cxx_source_compiles("${code}" ${var})
check_cxx_source_compiles("${draco_cxx_main}" linker_flag_test_passed)
CHECK_CXX_SOURCE_COMPILES("#include <ppl.h>
int main() { concurrency::parallel_for(0, 1, 1, [](int) { } ); }"
HAVE_PARALLEL_FOR)
check_cxx_source_compiles(
"#include <gflags/gflags.h>
int main(int argc, char * argv[]) {
google::ParseCommandLineFlags(&argc, &argv, true);
return 0;
}"
GFLAGS_IN_GOOGLE_NAMESPACE)
check_cxx_source_compiles("${test_source} ${DRACO_CXX_MAIN}"
CXX_TEST_COMPILED)
check_cxx_source_compiles("#include <byteswap.h>\nint main(){return bswap_32(42);}" MDCM_HAVE_BYTESWAP_H)
check_cxx_source_compiles(
"
#include <sycl/sycl.hpp>
using namespace sycl::ext::oneapi::experimental;
using namespace sycl;
SYCL_EXTERNAL device_global<int, decltype(properties(device_image_scope))> Foo;
void bar(queue q) {
q.single_task([=] {
Foo = 42;
});
}
int main(){ return 0; }
"
KOKKOS_IMPL_SYCL_DEVICE_GLOBAL_SUPPORTED
)
check_cxx_source_compiles("${ATOMIC_TEST_CODE}" ATOMIC_IS_BUILTIN)
check_cxx_source_compiles("${code}" CXX_FILESYSTEM_NO_LINK_NEEDED)
check_cxx_source_compiles("
#define PACKAGE 1
#define PACKAGE_VERSION 1
#include <bfd.h>
#include <unistd.h>
int main() {
bfd_init();
bfd *abfd = bfd_openr(\"test\", \"test\");
bfd_check_format(abfd, bfd_object);
bfd_get_file_flags(abfd);
bfd_map_over_sections(abfd, (void (*)(bfd*, asection*, void*)) 0, (void *) 0);
asymbol *syms = 0;
long symcount = bfd_read_minisymbols(abfd, false, (void**) &syms, (unsigned int *) 0);
bfd_get_section_flags(abfd, (asection*) 0);
bfd_get_section_vma(abfd, (asection*) 0);
bfd_section_size(abfd, (asection*) 0);
bfd_find_nearest_line(abfd, (asection*) 0, (asymbol **) 0, (bfd_vma) 0, (const char **) 0, (const char **) 0, (unsigned int *) 0);
return (int) symcount;
}"
${var}0
)
CHECK_CXX_SOURCE_COMPILES("int main() { return 0;}" have_gold)
CHECK_CXX_SOURCE_COMPILES(
"${find_standard_math_library_test_program}"
standard_math_library_linked_to_automatically
)
CHECK_CXX_SOURCE_COMPILES("${source}" ${variable} )
CHECK_CXX_SOURCE_COMPILES("
#include <tinyxml.h>
int main() { TiXmlNode *node; std::cin >> *node; } "
TinyXML_USE_STL_D
)
CHECK_CXX_SOURCE_COMPILES(
"${find_standard_math_library_test_program}"
standard_math_library_linked_to_automatically
)
check_cxx_source_compiles("${TBB_try_ts_source}" ${result_var})
check_cxx_source_compiles(
"
#include <source_location>
int main() {
std::source_location l{};
return 0;
}
"
HAVE_SOURCE_LOCATION
)
check_cxx_source_compiles("
#define _GNU_SOURCE 1
#include <string.h>\n
int main(){\n
char errbuf[200];\n
return strerror_r(13, errbuf, sizeof(errbuf)) == errbuf;\n
}\n"
HAVE_GLIBC)
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
std::atomic<uint64_t> x(0);
int main() {
uint64_t i = x.load(std::memory_order_relaxed);
bool b = x.is_lock_free();
return 0;
}
" BUILTIN_ATOMIC)
check_cxx_source_compiles(${full_source} ${var})
check_cxx_source_compiles("
#include <string_view>
int main()
{ std::string_view sv; }"
has_string_view
)
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
int main() {
struct Test { int val; };
std::atomic<Test> s;
s.is_lock_free();
}" ${varname})
check_cxx_source_compiles("
#include <tmmintrin.h>
int main() {
__m64 a = _mm_abs_pi8(__m64());
(void)a;
return 0;
}
" HAVE_SSSE3)
check_cxx_source_compiles("
#include <stdio.h>
#include <readline/readline.h>
#if !defined(RL_VERSION_MAJOR) || !defined(RL_VERSION_MINOR)
#error Ancient version of readline
#endif
int main() { return 0; }
"
_rl_version_check)
CHECK_CXX_SOURCE_COMPILES("${_CHECK_CXX_EXPRESSION_SOURCE_CODE}" ${_RESULT})
check_cxx_source_compiles("${CXX11_TEST_SOURCE}" CXX11_FLAG_DETECTED)
check_CXX_source_compiles("${_source}" ${_var} ${_common_patterns})
check_cxx_source_compiles("
#include <immintrin.h>
#include <stdint.h>
int main()
{
__m128i a = _mm_cvtsi64_si128((uint64_t)7);
__m128i b = _mm_clmulepi64_si128(a, a, 37);
__m128i c = _mm_srli_epi64(b, 41);
__m128i d = _mm_xor_si128(b, c);
uint64_t e = _mm_cvtsi128_si64(d);
return e == 0;
}
" HAVE_CLMUL
)
CHECK_CXX_SOURCE_COMPILES(
"
_Pragma(\"GCC diagnostic push\")
_Pragma(\"GCC diagnostic ignored \\\\\\\"-Wunknown-pragmas\\\\\\\"\")
_Pragma(\"GCC diagnostic ignored \\\\\\\"-Wpragmas\\\\\\\"\")
_Pragma(\"GCC diagnostic ignored \\\\\\\"-Wextra\\\\\\\"\")
_Pragma(\"GCC diagnostic pop\")
int main() {}
"
IBTK_HAVE_PRAGMA_KEYWORD)
check_cxx_source_compiles("int main(int argc, char **argv){return 0;}" HAVE_LD_VERSION_SCRIPT)
check_cxx_source_compiles(
"#include <nvjpeg.h>
int main(){
return NVJPEG_BACKEND_LOSSLESS_JPEG != 6;
}"
NVJPEG_LOSSLESS_SUPPORTED)
check_cxx_source_compiles("#include <memory>\nint main(int, char**) { std::unique_ptr<int> i = std::make_unique<int>(0); }" OSVR_HAS_STD_MAKE_UNIQUE)
check_cxx_source_compiles("
#include <iconv.h>
int main(){
iconv_t conv = 0;
const char* in = 0;
size_t ilen = 0;
char* out = 0;
size_t olen = 0;
iconv(conv, &in, &ilen, &out, &olen);
return 0;
}
" ICONV_SECOND_ARGUMENT_IS_CONST )
check_cxx_source_compiles("int main(void) { return 0; }" ${RESULT}
# Some compilers do not fail with a bad flag
FAIL_REGEX "command line option .* is valid for .* but not for C++" # GNU
${_CheckLinkerFlag_COMMON_PATTERNS})
check_cxx_source_compiles("int main() { char const* name = __PRETTY_FUNCTION__; }" HAS_PRETTY_FUNCTION)
check_cxx_source_compiles("#include <dcmtk/config/osconfig.h>\n#include <dcmtk/ofstd/ofstream.h>\nint main(int,char*[]){return 0;}"
DCMTK_HAVE_CONFIG_H_OPTIONAL
)
CHECK_CXX_SOURCE_COMPILES( "
#include <OpenGL/glu.h>
typedef GLvoid (*TF)();
int main() {
gluTessCallback(0,GLU_TESS_END_DATA,(TF)0);
return 1;
}" FTGL_GLU_EMPTY)
check_cxx_source_compiles(
"
#include <memory>
int main() {
std::tr1::shared_ptr<int> ptr;
return 0;
}
"
TR1_SHARED_PTR_FOUND)
check_cxx_source_compiles(
"#include <cstddef>
extern \"C\" int LLVMFuzzerTestOneInput(const void *, size_t) { return 0; }"
HAS_FUZZER)
check_cxx_source_compiles("${MPREAL_TEST_PROGRAM}" MPREAL_WORKS)
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
std::atomic<int> x;
int main() {
return x;
}
" ${varname})
check_cxx_source_compiles("
#include <string.h>
int main() { char x = *strerror_r(0, &x, sizeof(x)); return 0; }
" STRERROR_R_CHAR_P)
check_cxx_source_compiles("
#include <vector>
#include <future>
int main() { std::vector<std::future<int>> v; }" HAVE_STD_FUTURE)
check_cxx_source_compiles(
"#include <portaudio.h>\nPaDeviceIndex pa_find_device_by_name(const char *name); int main () {return 0;}"
PORTAUDIO2_FOUND)
check_cxx_source_compiles("#include <FL/Fl.H>\n#if FL_MAJOR_VERSION != 1 || FL_MINOR_VERSION != 3\n#error Wrong FLTK version\n#endif\nint main(int, char**) { return 0; }" OK_FLTK_VERSION)
check_cxx_source_compiles("#include <format>\nint main(){std::format(\"t\");}" EXV_HAVE_STD_FORMAT)
check_cxx_source_compiles(
"#include <openssl/crypto.h>
#if __has_include(<openssl/ex_data.h>)
#include <openssl/ex_data.h>
#endif
int main() {
CRYPTO_EX_dup *cb = [] (CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, void **from_d, int idx, long argl, void *argp) -> int { return 0; };
return 0;
}"
HAVE_CRYPTO_EX_DUP_TYPE1
)
check_cxx_source_compiles(
"
#include <assimp/scene.h>
int main()
{
aiScene* scene = new aiScene;
delete scene;
return 1;
}
"
ASSIMP_AISCENE_CTOR_DTOR_DEFINED)
CHECK_CXX_SOURCE_COMPILES("#include <mutex>\nint main(){std::mutex m;return 0;}" GPP_SUPPORTS_STD_MUTEX)
check_cxx_source_compiles("${MINIMAL_SRC}" CXX_SUPPORTS_CUSTOM_LINKER)
CHECK_CXX_SOURCE_COMPILES("
#include <cstdint>
#include <nmmintrin.h>
#include <wmmintrin.h>
int main() {
volatile uint32_t x = _mm_crc32_u32(0, 0);
const auto a = _mm_set_epi64x(0, 0);
const auto b = _mm_set_epi64x(0, 0);
const auto c = _mm_clmulepi64_si128(a, b, 0x00);
auto d = _mm_cvtsi128_si64(c);
}
" HAVE_SSE42)
CHECK_CXX_SOURCE_COMPILES("#include <stdexcept>
#include <iostream>
void foo() {
std::cout << 'h' << std::flush << std::endl;
throw std::exception();
}
int main() {
try { foo(); }
catch (int) { return 0; }
return 1;
}" libcxx_compiles)
check_cxx_source_compiles(
"
#include <string>
#if _GLIBCXX_USE_CXX11_ABI == 0
#error NOCXX11
#endif
int main() {}
" GLIBCXX_USE_CXX11_ABI)
check_cxx_source_compiles("
void operator\"\" _udl(long double);
int main() {}"
SUPPORTS_USER_DEFINED_LITERALS)
check_cxx_source_compiles("
#ifndef __linux__
#error Not Linux
#endif
int main()
{
return 0;
}" IS_LINUX)
check_cxx_source_compiles("int main(){return 0;}" ${_supported_var})
check_cxx_source_compiles(
[==[
#ifdef _MSC_VER
# if _MSVC_LANG < 201703L
# error "The compiler defaults or is configured for C++ < 17"
# endif
#elif __cplusplus < 201703L
# error "The compiler defaults or is configured for C++ < 17"
#endif
int main() { return 0; }
]==]
ABSL_INTERNAL_AT_LEAST_CXX17)
check_cxx_source_compiles("${ALIAS_CODE}" EL_HAVE_TEMPLATE_ALIAS)
CHECK_CXX_SOURCE_COMPILES("int main(void) { return 0; }" ${RESULT}
FAIL_REGEX "unknown argument ignored"
FAIL_REGEX "argument unused during compilation"
FAIL_REGEX "unsupported .*option"
FAIL_REGEX "unknown .*option"
FAIL_REGEX "unrecognized .*option"
FAIL_REGEX "ignoring unknown option"
FAIL_REGEX "[Ww]arning: [Oo]ption"
FAIL_REGEX "error: visibility"
FAIL_REGEX "warning: visibility"
)
check_cxx_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO)
CHECK_CXX_SOURCE_COMPILES(
"${find_standard_math_library_test_program}"
standard_math_library_linked_to_automatically
)
check_cxx_source_compiles("
#include <string_view>
int main() {
std::string_view sv = \"test\";
return 0;
}
" RESIP_HAVE_STRING_VIEW)
CHECK_CXX_SOURCE_COMPILES("int main(void) { return 0; }" ${RESULT}
FAIL_REGEX "unknown argument ignored"
FAIL_REGEX "argument unused during compilation"
FAIL_REGEX "unsupported .*option"
FAIL_REGEX "unknown .*option"
FAIL_REGEX "unrecognized .*option"
FAIL_REGEX "ignoring unknown option"
FAIL_REGEX "[Ww]arning: [Oo]ption"
FAIL_REGEX "error: visibility"
FAIL_REGEX "warning: visibility"
)
check_cxx_source_compiles(
"
#include <string.h>
int main(){char b;char *a = strerror_r(0, &b, 0); static_cast<void>(a); return(0);}
"
STRERROR_R_CHAR_P)
check_cxx_source_compiles("extern \"C\" int LLVMFuzzerTestOneInput(void *, int) { return 0; }" CLANG_HAS_LIBFUZZER)
CHECK_CXX_SOURCE_COMPILES(
"#include <nng/nng.h>
void cb(nng_pipe, nng_pipe_ev, void*) {}
int main() {
nng_socket s;
nng_pipe_notify(s, NNG_PIPE_EV_ADD_PRE, cb, NULL);
}
" NEW_NNG_PIPE_NOTIFY_CALLBACK_SIGNATURE
)
check_cxx_source_compiles("
#include <iconv.h>
int main(void) {
const char *fromPtr=0;
size_t fromLen=0;
char *toPtr=0;
size_t toLen=0;
iconv_t cv=0;
iconv(cv, &fromPtr, &fromLen, &toPtr, &toLen);
return 0;
}"
ICONV_USES_CONST_POINTER)
check_cxx_source_compiles("class Base { public: virtual void test(void) { } }; class Derived : public Base { virtual void test(void) override { } }; int main(){}" CXX_FEATURE_OVERRIDE)
CHECK_CXX_SOURCE_COMPILES("
# include <stdlib.h>
# include <sys/mman.h>
int main() { void *f = 0; return mlock(f,8); }
" MLOCK_TAKES_VOID)
CHECK_CXX_SOURCE_COMPILES ( "
int main() {
volatile int ia=0;
__sync_fetch_and_or( &ia, 1 );
return 0;
}" HAVE_SYNC_FETCH )
check_cxx_source_compiles("
#include <openssl/ssl.h>
#include <openssl/opensslconf.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
int main() { return 0; }
" OPENSSL_HEADERS_AVAILABLE)
check_cxx_source_compiles("#include <new>
int main() { void * ptr = nullptr; std::size_t size = 1; ::operator delete(ptr, size); }"
HAVE_DEALLOCATION_FUNCTIONS)
check_cxx_source_compiles("
#include <zlib.h>
#if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1200)
#error zlib 1.2.x or higher is required to use the gzip format
#endif
int main() { return 0; }" ZLIB_SUPPORTS_GZIP)
CHECK_CXX_SOURCE_COMPILES("
#include <arm_neon.h>
int main() {
float f = 1.0f;
uint16_t h = __gnu_f2h_ieee(f);
return 0;
}
" HAVE_GNU_F2H_IEEE)
check_cxx_source_compiles("int test = std::isnan(0.0)" HAVE_ISNAN)
check_cxx_source_compiles("#include <${HEADER}>\n int main() { ${TYPE} test; return 0;}" ${VAR})
check_cxx_source_compiles("${code}" CXX_FILESYSTEM_NO_LINK_NEEDED)
check_cxx_source_compiles("int main() { return 0; }" ${have_flag})
check_cxx_source_compiles("
#include <atomic>
int main() {
return std::atomic<int64_t>{};
}
" protobuf_HAVE_BUILTIN_ATOMICS)
check_cxx_source_compiles("${src}" ${res_var})
check_cxx_source_compiles("${CHECK_LTO_SRC}" LTO_WORKS)
check_cxx_source_compiles("int main() { return 0; }" ${_var}
${_common_patterns})
check_cxx_source_compiles("
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
int main() { boost::filesystem::copy_file(boost::filesystem::path(), boost::filesystem::path()); }"
boost_filesystem_copy_links_without_NO_SCOPED_ENUM)