blob: 694c65d188415fd1f84652f3fc7c371fe1a0ec2d [file]
include("${CMAKE_CURRENT_LIST_DIR}/check-json.cmake")
# The `import std` support targets are generated by CMake and their build
# database contents vary by toolchain (flags, depfile paths, module names,
# translation unit ordering, etc.). Ignore everything related to them so
# that the same expectations can be shared across platforms.
function (filter_import_std_sets json_in json_out)
set(json "${json_in}")
# Drop `@cmake_cxx_std@` sets.
string(JSON sets_len LENGTH "${json}" "sets")
if (sets_len GREATER 0)
math(EXPR last "${sets_len} - 1")
set(std_indices "")
foreach (idx RANGE "${last}")
string(JSON name GET "${json}" "sets" "${idx}" "name")
if (name MATCHES "^@cmake_cxx_std@")
list(APPEND std_indices "${idx}")
endif ()
endforeach ()
list(REVERSE std_indices)
foreach (idx IN LISTS std_indices)
string(JSON json REMOVE "${json}" "sets" "${idx}")
endforeach ()
endif ()
# Drop references to those sets from every `visible-sets` array.
string(JSON sets_len LENGTH "${json}" "sets")
if (sets_len GREATER 0)
math(EXPR last "${sets_len} - 1")
foreach (idx RANGE "${last}")
string(JSON vis_len LENGTH "${json}" "sets" "${idx}" "visible-sets")
if (vis_len GREATER 0)
math(EXPR vis_last "${vis_len} - 1")
set(vis_indices "")
foreach (vis_idx RANGE "${vis_last}")
string(JSON vis_name GET
"${json}" "sets" "${idx}" "visible-sets" "${vis_idx}")
if (vis_name MATCHES "^@cmake_cxx_std@")
list(APPEND vis_indices "${vis_idx}")
endif ()
endforeach ()
list(REVERSE vis_indices)
foreach (vis_idx IN LISTS vis_indices)
string(JSON json REMOVE
"${json}" "sets" "${idx}" "visible-sets" "${vis_idx}")
endforeach ()
endif ()
endforeach ()
endif ()
set("${json_out}" "${json}" PARENT_SCOPE)
endfunction ()
function (check_build_database expect_basename fname component)
if (component STREQUAL "NO_EXIST")
if (EXISTS "${RunCMake_TEST_BINARY_DIR}/${fname}")
list(APPEND RunCMake_TEST_FAILED
"Build database detected before it is expected (${fname}).")
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
endif ()
return ()
endif ()
if (NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/${fname}")
list(APPEND RunCMake_TEST_FAILED
"No build database detected (${fname}).")
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
return ()
endif ()
if (component STREQUAL "ALL")
set(CXXModules_config "Debug")
set(suffix "all")
elseif (component STREQUAL "ALL_MULTI")
set(CXXModules_config "Debug")
set(CXXModules_config_other "Release")
set(suffix "all-multi")
elseif (component STREQUAL "JUST_CXX")
set(CXXModules_config "Debug")
set(suffix "cxx")
elseif (component STREQUAL "JUST_CXX_MULTI")
set(CXXModules_config "Debug")
set(CXXModules_config_other "Release")
set(suffix "cxx-multi")
elseif (component STREQUAL "CXX_AND_DEBUG")
set(CXXModules_config "Debug")
set(suffix "cxx-config")
elseif (component STREQUAL "CXX_AND_RELEASE")
set(CXXModules_config "Release")
set(suffix "cxx-config")
elseif (component STREQUAL "JUST_DEBUG")
set(CXXModules_config "Debug")
set(suffix "config")
elseif (component STREQUAL "JUST_RELEASE")
set(CXXModules_config "Release")
set(suffix "config")
elseif (component STREQUAL "JUST_TARGET_DEBUG")
set(CXXModules_config "Debug")
set(suffix "target")
elseif (component STREQUAL "JUST_TARGET_RELEASE")
set(CXXModules_config "Release")
set(suffix "target")
elseif (component STREQUAL "JUST_TARGET")
set(CXXModules_config "Debug")
set(suffix "target")
else ()
list(APPEND RunCMake_TEST_FAILED
"Unrecognized test component for ${fname}: ${component}")
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
return ()
endif ()
set(expected_file "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/expect/${expect_basename}-${suffix}.json")
if (NOT EXISTS "${expected_file}")
list(APPEND RunCMake_TEST_FAILED
"No expected output JSON file found: ${expected_file}")
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
return ()
endif ()
file(READ "${RunCMake_TEST_BINARY_DIR}/${fname}" actual)
file(READ "${expected_file}" expect)
filter_import_std_sets("${actual}" actual)
set(RunCMake_TEST_FAILED_before "${RunCMake_TEST_FAILED}")
set(RunCMake_TEST_FAILED "")
check_json("${actual}" "${expect}")
if (RunCMake_TEST_FAILED)
string(PREPEND RunCMake_TEST_FAILED
"${RunCMake_TEST_FAILED_before}\n"
"actual file: ${RunCMake_TEST_BINARY_DIR}/${fname}\n"
"expect file: ${expected_file}\n")
else ()
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED_before}")
endif ()
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
endfunction ()