In my project's CMakeLists.txt
I have:
include(CheckIncludeFiles)
configure_file(config.h.in config.h @ONLY)
and I want to check for my platform's 64-bit integer type and printf conversion specifier for it, for use in C via config.h
. How do I do that?
Note: I know that on most systems we can just use stdint.h
's int64_t
type, but suppose I can't assume stdint.h
is available.
I would use:
include(CheckIncludeFile)
check_include_file(stdint.h HAVE_STDINT_H)
or
include(CheckIncludeFileCXX)
check_include_file_cxx(cstdint HAVE_CSTDINT)
For int64_t
I would do:
include(CheckTypeSize)
check_type_size("int64_t" SIZEOF_INT64_T)
check_type_size("long long" SIZEOF_LONG_LONG)
check_type_size("long" SIZEOF_LONG)
if(SIZEOF_INT64_T EQUAL "8")
set(INT64_T "int64_t")
elseif(SIZEOF_LONG EQUAL "8")
set(INT64_T "long")
elseif(SIZEOF_LONG_LONG EQUAL "8")
set(INT64_T "long long")
else()
message(FATAL_ERROR "Can't find suitable int64_t")
endif()
message(STATUS "Found int64_t: ${INT64_T}")
and then use a compile_definitions() or configure_file() to propagate it in your source code...
Also, you can try to look for the symbols otherwise:
set(TEST_INCLUDES "")
if(HAVE_STDINT_H)
list(APPEND TEST_INCLUDES "stdint.h")
endif()
include(CheckCXXSymbolExists)
check_cxx_symbol_exists(int64_t "${TEST_INCLUDES}" HAVE_INT64_T)
src: https://github.com/Mizux/Cbc/blob/master/cmake/CheckEnv.cmake
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments