I am using some features that are provided in GCC v4+ and would like CMake to find GCC v4 compiler and if it does not find it, return an error stating GCC v4 is required.
Anyone have any modules / ideas on how to do something like this?
Thanks.
CMake supports an extensive list of compilers, including: Apple Clang, Clang, GNU GCC, MSVC, Oracle Developer Studio, and Intel C++ Compiler.
For example, specifying --program-prefix=foo- would result in ' gcc ' being installed as /usr/local/bin/foo-gcc . Appends suffix to the names of programs to install in bindir (see above). For example, specifying --program-suffix=-3.1 would result in ' gcc ' being installed as /usr/local/bin/gcc-3.1 .
As the linker is invoked by the compiler driver, CMake needs a way to determine which compiler to use to invoke the linker. This is calculated by the LANGUAGE of source files in the target, and in the case of static libraries, the language of the dependent libraries.
Use the try_compile() command and try to compile the following program
#if __GNUC__ != 4
#error
#endif
int main() { return 0; }
A wholly different (not necessarily better) way to implement a gcc version check would be something like:
if(CMAKE_COMPILER_IS_GNUCXX)
exec_program(
${CMAKE_CXX_COMPILER}
ARGS --version
OUTPUT_VARIABLE _compiler_output)
string(REGEX REPLACE ".* ([0-9]\\.[0-9]\\.[0-9]) .*" "\\1"
gcc_compiler_version ${_compiler_output})
message(STATUS "C++ compiler version: ${gcc_compiler_version} [${CMAKE_CXX_COMPILER}]")
if(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]")
message(FATAL_ERROR "foobar")
...
if(gcc_compiler_version VERSION_GREATER "4.5.99")
...
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With