diff options
Diffstat (limited to 'vcpkg/scripts/detect_compiler')
| -rw-r--r-- | vcpkg/scripts/detect_compiler/CMakeLists.txt | 63 | ||||
| -rw-r--r-- | vcpkg/scripts/detect_compiler/portfile.cmake | 31 | ||||
| -rw-r--r-- | vcpkg/scripts/detect_compiler/vcpkg.json | 5 |
3 files changed, 99 insertions, 0 deletions
diff --git a/vcpkg/scripts/detect_compiler/CMakeLists.txt b/vcpkg/scripts/detect_compiler/CMakeLists.txt new file mode 100644 index 0000000..d695a9e --- /dev/null +++ b/vcpkg/scripts/detect_compiler/CMakeLists.txt @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 3.20)
+project(detect_compiler NONE)
+
+if(CMAKE_GENERATOR STREQUAL "Ninja" AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ set(CMAKE_C_COMPILER_WORKS 1)
+ set(CMAKE_C_COMPILER_FORCED 1)
+ set(CMAKE_CXX_COMPILER_WORKS 1)
+ set(CMAKE_CXX_COMPILER_FORCED 1)
+endif()
+
+enable_language(C)
+enable_language(CXX)
+
+if(VCPKG_COMPILER_CACHE_FILE)
+ if(EXISTS "${VCPKG_COMPILER_CACHE_FILE}")
+ file(READ "${VCPKG_COMPILER_CACHE_FILE}" JSON_CONTENT)
+ else()
+ set(JSON_CONTENT "{}")
+ endif()
+
+ function(get_hash compiler_path out_var)
+ file(TO_CMAKE_PATH "${compiler_path}" "compiler_path")
+ file(SIZE "${compiler_path}" SIZE)
+ file(TIMESTAMP "${compiler_path}" TIMESTAMP "%s" UTC)
+
+ string(JSON COMPILER_EXISTS ERROR_VARIABLE JSON_ERROR GET "${JSON_CONTENT}" "${compiler_path}")
+ if(NOT JSON_ERROR)
+ # Get compiler attributes using JSON API
+ string(JSON SIZE_JSON GET "${JSON_CONTENT}" "${compiler_path}" "size")
+ string(JSON TIMESTAMP_JSON GET "${JSON_CONTENT}" "${compiler_path}" "timestamp")
+ string(JSON HASH_JSON GET "${JSON_CONTENT}" "${compiler_path}" "hash")
+ if ((SIZE_JSON EQUAL SIZE) AND (TIMESTAMP_JSON EQUAL TIMESTAMP))
+ set("${out_var}" "${HASH_JSON}" PARENT_SCOPE)
+ return()
+ endif()
+ endif()
+ file(SHA1 "${compiler_path}" HASH)
+ # Add new entry to JSON
+ string(JSON JSON_CONTENT SET "${JSON_CONTENT}" "${compiler_path}" "{\"size\": ${SIZE}, \"timestamp\": ${TIMESTAMP}, \"hash\": \"${HASH}\"}")
+ set("${out_var}" "${HASH}" PARENT_SCOPE)
+ set(JSON_CONTENT "${JSON_CONTENT}" PARENT_SCOPE)
+ endfunction()
+
+ get_hash("${CMAKE_C_COMPILER}" C_HASH)
+ get_hash("${CMAKE_CXX_COMPILER}" CXX_HASH)
+
+ # Write updated JSON back to file
+ file(WRITE "${VCPKG_COMPILER_CACHE_FILE}" "${JSON_CONTENT}")
+else()
+ file(SHA1 "${CMAKE_CXX_COMPILER}" CXX_HASH)
+ file(SHA1 "${CMAKE_C_COMPILER}" C_HASH)
+endif()
+string(SHA1 COMPILER_HASH "${C_HASH}${CXX_HASH}")
+
+message("#COMPILER_HASH#${COMPILER_HASH}")
+message("#COMPILER_C_HASH#${C_HASH}")
+message("#COMPILER_C_VERSION#${CMAKE_C_COMPILER_VERSION}")
+message("#COMPILER_C_ID#${CMAKE_C_COMPILER_ID}")
+message("#COMPILER_C_PATH#${CMAKE_C_COMPILER}")
+message("#COMPILER_CXX_HASH#${CXX_HASH}")
+message("#COMPILER_CXX_VERSION#${CMAKE_CXX_COMPILER_VERSION}")
+message("#COMPILER_CXX_ID#${CMAKE_CXX_COMPILER_ID}")
+message("#COMPILER_CXX_PATH#${CMAKE_CXX_COMPILER}")
diff --git a/vcpkg/scripts/detect_compiler/portfile.cmake b/vcpkg/scripts/detect_compiler/portfile.cmake new file mode 100644 index 0000000..f4d6d9c --- /dev/null +++ b/vcpkg/scripts/detect_compiler/portfile.cmake @@ -0,0 +1,31 @@ +set(LOGS
+ ${CURRENT_BUILDTREES_DIR}/config-${TARGET_TRIPLET}-out.log
+ ${CURRENT_BUILDTREES_DIR}/config-${TARGET_TRIPLET}-rel-out.log
+ ${CURRENT_BUILDTREES_DIR}/config-${TARGET_TRIPLET}-dbg-out.log
+ ${CURRENT_BUILDTREES_DIR}/config-${TARGET_TRIPLET}-rel-err.log
+ ${CURRENT_BUILDTREES_DIR}/config-${TARGET_TRIPLET}-dbg-err.log
+)
+
+foreach(LOG IN LISTS LOGS)
+ file(REMOVE ${LOG})
+ if(EXISTS ${LOG})
+ message(FATAL_ERROR "Could not remove ${LOG}")
+ endif()
+endforeach()
+
+set(VCPKG_BUILD_TYPE release)
+
+vcpkg_configure_cmake(
+ SOURCE_PATH "${CMAKE_CURRENT_LIST_DIR}"
+ PREFER_NINJA
+ OPTIONS
+ "-DVCPKG_COMPILER_CACHE_FILE=${VCPKG_COMPILER_CACHE_FILE}"
+
+)
+
+foreach(LOG IN LISTS LOGS)
+ if(EXISTS ${LOG})
+ file(READ "${LOG}" _contents)
+ message("${_contents}")
+ endif()
+endforeach()
diff --git a/vcpkg/scripts/detect_compiler/vcpkg.json b/vcpkg/scripts/detect_compiler/vcpkg.json new file mode 100644 index 0000000..64979df --- /dev/null +++ b/vcpkg/scripts/detect_compiler/vcpkg.json @@ -0,0 +1,5 @@ +{ + "name": "detect-compiler", + "version": "0", + "description": "None" +} |