1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-25 00:53:43 +00:00

Improve compiler version detection in cmake

This commit is contained in:
King_DuckZ 2016-04-14 20:44:14 +02:00
parent aee6c35ede
commit 69590a0267

View file

@ -1,31 +1,40 @@
if (CMAKE_COMPILER_IS_GNUCXX)
exec_program(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE version_string)
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_CXX_COMPILER_VERSION "${version_string}")
string(REGEX MATCHALL "[0-9]+" version_nums "${CMAKE_CXX_COMPILER_VERSION}")
list(GET version_nums 0 CMAKE_CXX_COMPILER_VERSION_MAJOR)
list(GET version_nums 1 CMAKE_CXX_COMPILER_VERSION_MINOR)
list(GET version_nums 2 CMAKE_CXX_COMPILER_VERSION_PATCH)
function (set_compiler_ver spliced_version_var)
set(whole_version "${${spliced_version_var}}")
set(var_prefix "${spliced_version_var}")
string(REGEX MATCHALL "[0-9]+" version_nums "${whole_version}")
list(GET version_nums 0 compiler_MAJOR)
list(GET version_nums 1 compiler_MINOR)
list(GET version_nums 2 compiler_PATCH)
set(${var_prefix}_MAJOR "${compiler_MAJOR}" PARENT_SCOPE)
set(${var_prefix}_MINOR "${compiler_MINOR}" PARENT_SCOPE)
set(${var_prefix}_PATCH "${compiler_PATCH}" PARENT_SCOPE)
unset(compiler_MAJOR)
unset(compiler_MINOR)
unset(compiler_PATCH)
unset(version_nums)
unset(version_string)
else()
set(CMAKE_CXX_COMPILER_VERSION "0.0.0")
set(CMAKE_CXX_COMPILER_VERSION_MAJOR "0")
set(CMAKE_CXX_COMPILER_VERSION_MINOR "0")
set(CMAKE_CXX_COMPILER_VERSION_PATCH "0")
unset(whole_version)
unset(var_prefix)
endfunction()
if (NOT CMAKE_CXX_COMPILER_VERSION)
if (CMAKE_COMPILER_IS_GNUCXX)
exec_program(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE version_string)
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_CXX_COMPILER_VERSION "${version_string}")
unset(version_string)
else()
set(CMAKE_CXX_COMPILER_VERSION "0.0.0")
endif()
endif()
if (CMAKE_COMPILER_IS_GNUCC)
exec_program(${CMAKE_C_COMPILER} ARGS --version OUTPUT_VARIABLE version_string)
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_C_COMPILER_VERSION "${version_string}")
string(REGEX MATCHALL "[0-9]+" version_nums "${CMAKE_C_COMPILER_VERSION}")
list(GET version_nums 0 CMAKE_C_COMPILER_VERSION_MAJOR)
list(GET version_nums 1 CMAKE_C_COMPILER_VERSION_MINOR)
list(GET version_nums 2 CMAKE_C_COMPILER_VERSION_PATCH)
unset(version_nums)
unset(version_string)
else()
set(CMAKE_C_COMPILER_VERSION "0.0.0")
set(CMAKE_C_COMPILER_VERSION_MAJOR "0")
set(CMAKE_C_COMPILER_VERSION_MINOR "0")
set(CMAKE_C_COMPILER_VERSION_PATCH "0")
if (NOT CMAKE_C_COMPILER_VERSION)
if (CMAKE_COMPILER_IS_GNUCC)
exec_program(${CMAKE_C_COMPILER} ARGS --version OUTPUT_VARIABLE version_string)
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_C_COMPILER_VERSION "${version_string}")
unset(version_string)
else()
set(CMAKE_C_COMPILER_VERSION "0.0.0")
endif()
endif()
set_compiler_ver(CMAKE_CXX_COMPILER_VERSION)
set_compiler_ver(CMAKE_C_COMPILER_VERSION)