build: clean up Windows-specific PATH handling for tests

Closes #365
This commit is contained in:
Roman Dubtsov
2018-12-27 02:33:58 -08:00
committed by Roma Dubtsov
parent 6bc2e5eea0
commit 1687299a98
6 changed files with 40 additions and 22 deletions

View File

@ -177,7 +177,7 @@ function(detect_mkl LIBNAME)
if(WIN32)
# Add paths to DLL to %PATH% on Windows
get_filename_component(MKLDLLPATH "${MKLDLL}" PATH)
set(CTESTCONFIG_PATH "${CTESTCONFIG_PATH}\;${MKLDLLPATH}")
append_to_windows_path_list(CTESTCONFIG_PATH "${MKLDLLPATH}")
set(CTESTCONFIG_PATH "${CTESTCONFIG_PATH}" PARENT_SCOPE)
endif()

View File

@ -130,11 +130,6 @@ elseif(UNIX OR MINGW)
endif()
endif()
if(WIN32)
string(REPLACE ";" "\;" ENV_PATH "$ENV{PATH}")
set(CTESTCONFIG_PATH "${CTESTCONFIG_PATH}\;${MKLDLLPATH}\;${ENV_PATH}")
endif()
if(UNIX OR MINGW)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
# Link Intel libraries statically (except for iomp5)

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='@CMAKE_BUILD_TYPE@|@USERCONFIG_PLATFORM@'">
<LocalDebuggerEnvironment>PATH=@CTESTCONFIG_PATH@;%PATH%</LocalDebuggerEnvironment>
<PropertyGroup>
<LocalDebuggerEnvironment>PATH=@CTESTCONFIG_PATH@;$(PATH)</LocalDebuggerEnvironment>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

View File

@ -24,6 +24,16 @@ set(utils_cmake_included true)
include("cmake/options.cmake")
# Common configuration for tests / test cases on Windows
function(maybe_configure_windows_test name kind)
if(WIN32 OR MINGW)
string(REPLACE ";" "\;" PATH "${CTESTCONFIG_PATH};$ENV{PATH}")
set_property(${kind} ${name} PROPERTY ENVIRONMENT "PATH=${PATH}")
configure_file(${PROJECT_SOURCE_DIR}/cmake/template.vcxproj.user
${name}.vcxproj.user @ONLY)
endif()
endfunction()
# Register new executable/test
# name -- name of the executable
# srcs -- list of source, if many must be enclosed with ""
@ -34,10 +44,7 @@ function(register_exe name srcs test)
target_link_libraries(${name} ${LIB_NAME} ${EXTRA_LIBS} ${ARGV3})
if("${test}" STREQUAL "test")
add_test(${name} ${name})
if(WIN32 OR MINGW)
set_property(TEST ${name} PROPERTY ENVIRONMENT "PATH=${CTESTCONFIG_PATH};$ENV{PATH}")
configure_file(${PROJECT_SOURCE_DIR}/config_template.vcxproj.user ${name}.vcxproj.user @ONLY)
endif()
maybe_configure_windows_test(${name} TEST)
endif()
endfunction()
@ -86,3 +93,15 @@ macro(append_if condition var value)
append(${var} "${value}")
endif()
endmacro()
# Append a path to path_list variable (Windows-only version)
macro(append_to_windows_path_list path_list path)
file(TO_NATIVE_PATH "${path}" append_to_windows_path_list_tmp__)
if(${path_list})
set(${path_list}
"${${path_list}};${append_to_windows_path_list_tmp__}")
else()
set(${path_list}
"${append_to_windows_path_list_tmp__}")
endif()
endmacro()

View File

@ -108,13 +108,20 @@ endif()
add_library(${TARGET_NAME} ${MKLDNN_LIBRARY_TYPE} ${HEADERS} ${SOURCES})
#Add mkldnn.dll to execution PATH
if(NOT(MINGW))
set(CTESTCONFIG_PATH "${CTESTCONFIG_PATH}\;${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}" PARENT_SCOPE)
else()
# CMake with "MSYS Makefiles" generator seems to build libmkldnn.dll in a directory without build type.
set(CTESTCONFIG_PATH "${CTESTCONFIG_PATH}\;${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE)
if(WIN32)
# Add mkldnn.dll to execution PATH
if(NOT(MINGW))
foreach(BUILD_TYPE Release Debug RelWithDebInfo MinSizeRel)
append_to_windows_path_list(CTESTCONFIG_PATH
"${CMAKE_CURRENT_BINARY_DIR}/${BUILD_TYPE}")
endforeach()
else()
append_to_windows_path_list(CTESTCONFIG_PATH
"${CMAKE_CURRENT_BINARY_DIR}")
endif()
set(CTESTCONFIG_PATH "${CTESTCONFIG_PATH}" PARENT_SCOPE)
endif()
target_link_libraries(${TARGET_NAME} ${${TARGET_NAME}_LINKER_LIBS} ${EXTRA_LIBS})
set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 11)
set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)

View File

@ -55,10 +55,7 @@ function(register_benchdnn_test name cmd)
DEPENDS benchdnn
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
if(WIN32)
set_property(TARGET ${name} PROPERTY ENVIRONMENT "PATH=${CTESTCONFIG_PATH}")
configure_file(${PROJECT_SOURCE_DIR}/config_template.vcxproj.user ${name}.vcxproj.user @ONLY)
endif()
maybe_configure_windows_test(${name} TARGET)
endfunction()
register_benchdnn_test(test_conv "benchdnn -v1 --conv --batch=inputs/test_conv_all")