diff --git a/src/Clang.cmake b/src/Clang.cmake new file mode 100644 index 00000000..7bdab283 --- /dev/null +++ b/src/Clang.cmake @@ -0,0 +1,50 @@ +include_guard() + +set(ProjectOptions_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}") + +# detect clang +function(is_clang value) + if(clang + OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") + OR ("${DETECTED_CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${DETECTED_CMAKE_C_COMPILER_ID}" + STREQUAL "Clang") + ) + set(${value} ON PARENT_SCOPE) + return() + endif() + + # if the compiler is unknown by CMake + if(NOT CMAKE_CXX_COMPILER + AND NOT CMAKE_C_COMPILER + AND NOT CMAKE_CXX_COMPILER_ID + AND NOT CMAKE_C_COMPILER_ID + ) + + # if clang is inferred by cmake later + include("${ProjectOptions_SRC_DIR}/DetectCompiler.cmake") + detect_compiler() + + if((DETECTED_CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND DETECTED_CMAKE_C_COMPILER_ID STREQUAL + "Clang") + ) + set(${value} ON PARENT_SCOPE) + return() + endif() + + endif() + + set(${value} OFF PARENT_SCOPE) +endfunction() + +# configure clang toolchain for vcpkg +macro(configure_clang_vcpkg) + if(WIN32) + is_clang(_is_clang) + if(${_is_clang}) + # Disable /utf-8 flag in the vcpkg toolchain file + # https://github.com/microsoft/vcpkg/blob/e590c2b30c08caf1dd8d612ec602a003f9784b7d/scripts/toolchains/windows.cmake#L68 + message(STATUS "Disabling /utf-8 flag in the vcpkg toolchain file for Clang") + set(VCPKG_SET_CHARSET_FLAG "OFF" CACHE STRING "Vcpkg set charset flag" FORCE) + endif() + endif() +endmacro() diff --git a/src/DetectCompiler.cmake b/src/DetectCompiler.cmake index 144c327b..7f23cdc5 100644 --- a/src/DetectCompiler.cmake +++ b/src/DetectCompiler.cmake @@ -5,30 +5,41 @@ set(ProjectOptions_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}") # includes a separate CMakeLists.txt file to detect the CXX/C compilers before project is called # Using a separate file ensures that the current scope is not contaminated by the variable macro(detect_compiler) - find_program(CMAKE_EXECUTABLE cmake) - execute_process( - COMMAND - "${CMAKE_EXECUTABLE}" -S "${ProjectOptions_SRC_DIR}/detect_compiler" -B - "${CMAKE_CURRENT_BINARY_DIR}/detect_compiler" -G "${CMAKE_GENERATOR}" "--log-level=ERROR" - "-Wno-dev" - OUTPUT_QUIET + if(NOT + (DETECTED_CMAKE_CXX_COMPILER + AND DETECTED_CMAKE_C_COMPILER + AND DETECTED_CMAKE_CXX_COMPILER_ID + AND DETECTED_CMAKE_C_COMPILER_ID + AND DETECTED_CMAKE_SYSTEM_PROCESSOR + AND DETECTED_CMAKE_HOST_SYSTEM_PROCESSOR) ) - # parse the detected compilers from the cache - set(cache_variables - CMAKE_CXX_COMPILER - CMAKE_CXX_COMPILER_ID - CMAKE_C_COMPILER - CMAKE_C_COMPILER_ID - CMAKE_SYSTEM_PROCESSOR - CMAKE_HOST_SYSTEM_PROCESSOR - ) - foreach(cache_var ${cache_variables}) - file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/detect_compiler/CMakeCache.txt" - "DETECTED_${cache_var}" REGEX "^${cache_var}:STRING=(.*)$" + find_program(CMAKE_EXECUTABLE cmake) + execute_process( + COMMAND + "${CMAKE_EXECUTABLE}" -S "${ProjectOptions_SRC_DIR}/detect_compiler" -B + "${CMAKE_CURRENT_BINARY_DIR}/detect_compiler" -G "${CMAKE_GENERATOR}" "--log-level=ERROR" + "-Wno-dev" + OUTPUT_QUIET ) - string(REGEX REPLACE "^${cache_var}:STRING=(.*)$" "\\1" "DETECTED_${cache_var}" - "${DETECTED_${cache_var}}" + + # parse the detected compilers from the cache + set(cache_variables + CMAKE_CXX_COMPILER + CMAKE_CXX_COMPILER_ID + CMAKE_C_COMPILER + CMAKE_C_COMPILER_ID + CMAKE_SYSTEM_PROCESSOR + CMAKE_HOST_SYSTEM_PROCESSOR ) - endforeach() + foreach(cache_var ${cache_variables}) + file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/detect_compiler/CMakeCache.txt" + "DETECTED_${cache_var}" REGEX "^${cache_var}:STRING=(.*)$" + ) + string(REGEX REPLACE "^${cache_var}:STRING=(.*)$" "\\1" "DETECTED_${cache_var}" + "${DETECTED_${cache_var}}" + ) + endforeach() + + endif() endmacro() diff --git a/src/Git.cmake b/src/Git.cmake index 66884bc6..dcf56adf 100644 --- a/src/Git.cmake +++ b/src/Git.cmake @@ -499,7 +499,7 @@ Wait for the git lock file to be released Input variables: - ``REPOSITORY_PATH``: The path to the repository -- ``TIMEOUT_COUNTER``: The number of times to wait before timing out +- ``TIMEOUT_COUNTER``: The number of times to wait before timing out, each time 1 seconds (defaults to 120) ]] function(git_wait) @@ -511,7 +511,7 @@ function(git_wait) endif() if("${_fun_TIMEOUT_COUNTER}" STREQUAL "") - set(_fun_TIMEOUT_COUNTER 20) + set(_fun_TIMEOUT_COUNTER 120) endif() set(counter 0) @@ -520,8 +520,11 @@ function(git_wait) while(NOT EXISTS "${_fun_REPOSITORY_PATH}/.git/index" OR EXISTS "${_fun_REPOSITORY_PATH}/.git/index.lock" ) - message(STATUS "Waiting for git lock file...[${counter}/${_fun_TIMEOUT_COUNTER}]") - execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 0.5 COMMAND_ERROR_IS_FATAL LAST) + if(${counter} EQUAL 0) + message(STATUS "Waiting for git lock file\n") + endif() + + execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1 COMMAND_ERROR_IS_FATAL LAST) math(EXPR counter "${counter} + 1") if(${counter} GREATER ${_fun_TIMEOUT_COUNTER}) diff --git a/src/Index.cmake b/src/Index.cmake index 72f57d09..d66df40f 100644 --- a/src/Index.cmake +++ b/src/Index.cmake @@ -38,6 +38,7 @@ include("${ProjectOptions_SRC_DIR}/Doxygen.cmake") include("${ProjectOptions_SRC_DIR}/StaticAnalyzers.cmake") include("${ProjectOptions_SRC_DIR}/VCEnvironment.cmake") include("${ProjectOptions_SRC_DIR}/MinGW.cmake") +include("${ProjectOptions_SRC_DIR}/Clang.cmake") include("${ProjectOptions_SRC_DIR}/DetectCompiler.cmake") include("${ProjectOptions_SRC_DIR}/CrossCompiler.cmake") include("${ProjectOptions_SRC_DIR}/DynamicProjectOptions.cmake") diff --git a/src/VCEnvironment.cmake b/src/VCEnvironment.cmake index 07e22464..8c487cb7 100644 --- a/src/VCEnvironment.cmake +++ b/src/VCEnvironment.cmake @@ -60,7 +60,7 @@ macro(msvc_toolchain) include(FetchContent) FetchContent_Declare( _msvc_toolchain GIT_REPOSITORY "https://github.com/MarkSchofield/WindowsToolchain.git" - GIT_TAG "v0.9.0" + GIT_TAG "v0.10.0" ) FetchContent_MakeAvailable(_msvc_toolchain) include("${_msvc_toolchain_SOURCE_DIR}/Windows.MSVC.toolchain.cmake") diff --git a/src/Vcpkg.cmake b/src/Vcpkg.cmake index c91b90f9..be18dfca 100644 --- a/src/Vcpkg.cmake +++ b/src/Vcpkg.cmake @@ -232,6 +232,7 @@ macro(run_vcpkg) _checkout_vcpkg_repository() configure_mingw_vcpkg() + # configure_clang_vcpkg() # add the vcpkg toolchain _add_vcpkg_toolchain()