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) function (set_compiler_ver spliced_version_var)
exec_program(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE version_string) set(whole_version "${${spliced_version_var}}")
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_CXX_COMPILER_VERSION "${version_string}") set(var_prefix "${spliced_version_var}")
string(REGEX MATCHALL "[0-9]+" version_nums "${CMAKE_CXX_COMPILER_VERSION}") string(REGEX MATCHALL "[0-9]+" version_nums "${whole_version}")
list(GET version_nums 0 CMAKE_CXX_COMPILER_VERSION_MAJOR) list(GET version_nums 0 compiler_MAJOR)
list(GET version_nums 1 CMAKE_CXX_COMPILER_VERSION_MINOR) list(GET version_nums 1 compiler_MINOR)
list(GET version_nums 2 CMAKE_CXX_COMPILER_VERSION_PATCH) 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_nums)
unset(version_string) unset(whole_version)
else() unset(var_prefix)
set(CMAKE_CXX_COMPILER_VERSION "0.0.0") endfunction()
set(CMAKE_CXX_COMPILER_VERSION_MAJOR "0")
set(CMAKE_CXX_COMPILER_VERSION_MINOR "0") if (NOT CMAKE_CXX_COMPILER_VERSION)
set(CMAKE_CXX_COMPILER_VERSION_PATCH "0") 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() endif()
if (CMAKE_COMPILER_IS_GNUCC) if (NOT CMAKE_C_COMPILER_VERSION)
exec_program(${CMAKE_C_COMPILER} ARGS --version OUTPUT_VARIABLE version_string) if (CMAKE_COMPILER_IS_GNUCC)
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_C_COMPILER_VERSION "${version_string}") exec_program(${CMAKE_C_COMPILER} ARGS --version OUTPUT_VARIABLE version_string)
string(REGEX MATCHALL "[0-9]+" version_nums "${CMAKE_C_COMPILER_VERSION}") string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_C_COMPILER_VERSION "${version_string}")
list(GET version_nums 0 CMAKE_C_COMPILER_VERSION_MAJOR) unset(version_string)
list(GET version_nums 1 CMAKE_C_COMPILER_VERSION_MINOR) else()
list(GET version_nums 2 CMAKE_C_COMPILER_VERSION_PATCH) set(CMAKE_C_COMPILER_VERSION "0.0.0")
unset(version_nums) endif()
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")
endif() endif()
set_compiler_ver(CMAKE_CXX_COMPILER_VERSION)
set_compiler_ver(CMAKE_C_COMPILER_VERSION)