Skip to content

Commit

Permalink
Merge pull request #269 from aminya/vcpkg
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Aug 12, 2024
2 parents d856abd + 8505a53 commit 5caec27
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 27 deletions.
50 changes: 50 additions & 0 deletions src/Clang.cmake
Original file line number Diff line number Diff line change
@@ -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()
55 changes: 33 additions & 22 deletions src/DetectCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
11 changes: 7 additions & 4 deletions src/Git.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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})
Expand Down
1 change: 1 addition & 0 deletions src/Index.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/VCEnvironment.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions src/Vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ macro(run_vcpkg)
_checkout_vcpkg_repository()

configure_mingw_vcpkg()
# configure_clang_vcpkg()

# add the vcpkg toolchain
_add_vcpkg_toolchain()
Expand Down

0 comments on commit 5caec27

Please sign in to comment.