check_cxx_source_compiles(<code> <resultVar> [FAIL_REGEX <regex1> [<regex2>...]])
check_cxx_source_compiles(<code> <resultVar> [FAIL_REGEX <regex1> [<regex2>...]])
check_cxx_source_compiles("${ATOMIC32_TEST_CODE}" atomic32_test)
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("${CODE}" "${_COMPILE_VAR}")
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("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("
#include <atomic>
std::atomic<int> x;
int main() {
return x;
}
" ${varname})
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("${code}" ${var})
check_cxx_source_compiles("${draco_cxx_main}" linker_flag_test_passed)
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("#include <ppl.h>
int main() { concurrency::parallel_for(0, 1, 1, [](int) { } ); }"
HAVE_PARALLEL_FOR)
check_cxx_source_compiles("int main(void) { return 0;}" LINKER_SUPPORTS_NO_UNDEFINED)
CHECK_CXX_SOURCE_COMPILES("int main() { return 0;}" have_gold)
check_cxx_source_compiles("
void operator\"\" _udl(long double);
int main() {}"
SUPPORTS_USER_DEFINED_LITERALS)
CHECK_CXX_SOURCE_COMPILES("
#include <lqr.h>
int main()
{
LqrImageType t = LQR_RGB_IMAGE;
return 0;
}
" HAVE_LQR_0_4)
CHECK_CXX_SOURCE_COMPILES(
"${find_standard_math_library_test_program}"
standard_math_library_linked_to_automatically
)
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 <atomic>
std::atomic<int> x;
std::atomic<short> y;
std::atomic<char> z;
int main() {
++z;
++y;
return ++x;
}
" ${varname})
check_cxx_source_compiles(
"
#include <source_location>
int main() {
std::source_location l{};
return 0;
}
"
HAVE_SOURCE_LOCATION
)
check_cxx_source_compiles("
#include <atomic>
int main(int argc, char** argv) {
std::atomic<uint8_t> a1;
std::atomic<uint16_t> a2;
std::atomic<uint32_t> a4;
std::atomic<uint64_t> a8;
struct Test { bool val; };
std::atomic<Test> s;
return a1++ + a2++ + a4++ + a8++ + unsigned(s.is_lock_free());
}"
FOLLY_CPP_ATOMIC_BUILTIN
)
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("
# include <string>
# ifndef _GLIBCXX_USE_CXX11_ABI
# error \"GlibCXX ABI is not defined\"
# endif
int main() {
return 0;
}"
OPENVINO_STDLIB_GNU)
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 <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(
"
_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("
#define G_BEGIN_DECLS
#define G_END_DECLS
#include <gst/gstversion.h>
#if GST_CHECK_VERSION(${_comma_version})
int main() { return 0; }
#else
# error \"GStreamer version incompatible\"
#endif
" GSTREAMER_VERSION_COMPATIBLE)
check_cxx_source_compiles("int main(int argc, char **argv){return 0;}" HAVE_LD_VERSION_SCRIPT)
check_cxx_source_compiles("
#include <elpa/elpa_version.h>
#if ELPA_API_VERSION < 20210430
#error ELPA version is too old.
#endif
int main(){}
"
ELPA_VERSION_SATISFIES
)
check_cxx_source_compiles(
"#include <nvjpeg.h>
int main(){
return NVJPEG_BACKEND_LOSSLESS_JPEG != 6;
}"
NVJPEG_LOSSLESS_SUPPORTED)
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
std::atomic<int> x;
int main() {
return std::atomic_is_lock_free(&x);
}
" ${varname})
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("${code}" ${var})
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 <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 <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("
#if ${HAVE_PAM_PAM_APPL_H}+0
# include <pam/pam_appl.h>
#else
# include <security/pam_appl.h>
#endif
static int PAM_conv(
int num_msg,
const struct pam_message **msg, /* this is the culprit */
struct pam_response **resp,
void *ctx)
{
return 0;
}
int main(void)
{
struct pam_conv PAM_conversation = {
&PAM_conv, /* this bombs out if the above does not match */
0
};
return 0;
}
" PAM_MESSAGE_CONST)
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("
#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("
#include <sched.h>
int main() {
cpu_set_t cpumask;
sched_setaffinity( 0, sizeof(cpumask), &cpumask );
return 0;
}" HAVE_THREE_PARAM_SCHED_SETAFFINITY)
check_cxx_source_compiles("
#ifndef __linux__
#error Not Linux
#endif
int main()
{
return 0;
}" IS_LINUX)
check_cxx_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO)
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("
#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("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(
"
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <windows.h>
#include <afunix.h>
int main(){(void)sizeof(((struct sockaddr_un *)0)->sun_path); return 0;}
"
HAVE_AF_UNIX_H)
check_cxx_source_compiles("int main() { return __builtin_bswap32(42); }" HAVE_BUILTIN_BSWAP32)
check_cxx_source_compiles("
#include <type_traits>
#if _GLIBCXX_RELEASE
int main() {}
#endif"
FBTHRIFT_COMPILER_STDLIB_LIBSTDCXX
)
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 <atomic>
#include <cstdint>
std::atomic<uint64_t> x {0};
int main() {
uint64_t i = x.load(std::memory_order_relaxed);
return 0;
}"
COMPILER_SUPPORTS_ATOMIC_WITHOUT_LIBATOMIC)
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("${lfsSource}" BOOST_NOWIDE_HAS_LFS)
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 <fmt/ranges.h>
int main() {
float grades[] = {3.14};
fmt::print(\"{}\", grades);
}"
Cxx_Compiler_BZ107852_Free
FAIL_REGEX "is out of the bounds")
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 <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("
#include <atomic>
int main() {
return std::atomic<int64_t>{};
}
" protobuf_HAVE_BUILTIN_ATOMICS)
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)