forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
144 lines (128 loc) · 5.8 KB
/
CMakeLists.txt
File metadata and controls
144 lines (128 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
file(GLOB materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")
list(APPEND materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/External/Catch/catch.hpp")
assign_source_group("Source Files" ${materialx_source})
assign_source_group("Header Files" ${materialx_headers})
# Discover all tests and allow them to be run in parallel (ctest -j20):
function(add_tests _sources)
foreach(src_file ${_sources})
file(STRINGS ${src_file} matched_lines REGEX "TEST_CASE")
foreach(matched_line ${matched_lines})
string(REGEX REPLACE "(TEST_CASE[( \"]+)" "" test_name ${matched_line})
string(REGEX REPLACE "(\".*)" "" test_name ${test_name})
string(REGEX REPLACE "[^A-Za-z0-9_]+" "_" test_safe_name ${test_name})
add_test(NAME "MaterialXTest_${test_safe_name}"
COMMAND MaterialXTest ${test_name}
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
if(MATERIALX_BUILD_OIIO AND MSVC)
# Add path to OIIO library so it can be found for the test.
# On windows we have to escape the semicolons, otherwise only
# the first path entry will be passed to the test executable
STRING(REPLACE ";" "\\;" TESTPATH "$ENV{PATH}")
STRING(APPEND TESTPATH "\\;${OPENIMAGEIO_ROOT_DIR}/bin")
STRING(REPLACE "/" "\\" TESTPATH "${TESTPATH}")
set_tests_properties("MaterialXTest_${test_safe_name}" PROPERTIES
ENVIRONMENT "PATH=${TESTPATH}")
endif()
endforeach()
endforeach()
endfunction()
add_executable(MaterialXTest ${materialx_source} ${materialx_headers})
target_include_directories( MaterialXTest PUBLIC
${EXTERNAL_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/../)
add_subdirectory(MaterialXCore)
target_link_libraries(MaterialXTest MaterialXCore)
add_subdirectory(MaterialXFormat)
target_link_libraries(MaterialXTest MaterialXFormat)
add_subdirectory(MaterialXGenShader)
target_link_libraries(MaterialXTest MaterialXGenShader)
if(MATERIALX_BUILD_GEN_GLSL OR MATERIALX_BUILD_GEN_OSL OR MATERIALX_BUILD_GEN_MDL OR MATERIALX_BUILD_GEN_MSL OR MATERIALX_BUILD_GEN_SLANG)
if(MATERIALX_BUILD_GEN_GLSL)
add_subdirectory(MaterialXGenGlsl)
target_link_libraries(MaterialXTest MaterialXGenGlsl)
endif()
if(MATERIALX_BUILD_GEN_SLANG)
add_subdirectory(MaterialXGenSlang)
target_link_libraries(MaterialXTest MaterialXGenSlang)
endif()
if(MATERIALX_BUILD_GEN_OSL)
add_subdirectory(MaterialXGenOsl)
target_link_libraries(MaterialXTest MaterialXGenOsl)
endif()
if(MATERIALX_BUILD_GEN_MDL)
add_subdirectory(MaterialXGenMdl)
target_link_libraries(MaterialXTest MaterialXGenMdl)
endif()
if(MATERIALX_BUILD_GEN_MSL)
add_subdirectory(MaterialXGenMsl)
target_link_libraries(MaterialXTest MaterialXGenMsl)
endif()
endif()
if(MATERIALX_BUILD_RENDER)
add_subdirectory(MaterialXRender)
target_link_libraries(MaterialXTest MaterialXRender)
if(MATERIALX_BUILD_GEN_GLSL AND NOT MATERIALX_RENDER_MSL_ONLY)
add_subdirectory(MaterialXRenderGlsl)
target_link_libraries(MaterialXTest MaterialXRenderGlsl)
endif()
if(MATERIALX_BUILD_GEN_SLANG AND MATERIALX_SLANG_RHI_SOURCE_DIR)
add_subdirectory(MaterialXRenderSlang)
target_link_libraries(MaterialXTest MaterialXRenderSlang)
endif()
if(MATERIALX_BUILD_GEN_OSL)
add_subdirectory(MaterialXRenderOsl)
target_link_libraries(MaterialXTest MaterialXRenderOsl)
endif()
if(APPLE AND MATERIALX_BUILD_GEN_MSL)
add_subdirectory(MaterialXRenderMsl)
target_link_libraries(MaterialXTest MaterialXRenderMsl)
endif()
if(MATERIALX_BUILD_OIIO AND OPENIMAGEIO_ROOT_DIR)
add_custom_command(TARGET MaterialXTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${OPENIMAGEIO_ROOT_DIR}/bin ${CMAKE_CURRENT_BINARY_DIR})
endif()
endif()
# Disable deprecation warnings on Clang.
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(MaterialXTest PUBLIC -Wno-deprecated-declarations)
endif()
# The MaterialX test suite maintains a synchronized copy of the data libraries.
add_custom_target(MaterialXTestData ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different
${MATERIALX_DATA_LIBRARY_DIR} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libraries)
if(MATERIALX_BUILD_DATA_LIBRARY)
add_dependencies(MaterialXTestData MaterialXBuildData)
endif()
if(MATERIALX_BUILD_GEN_MDL)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../source/MaterialXGenMdl/mdl/"
DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${MATERIALX_INSTALL_STDLIB_PATH}/mdl)
endif()
# Copy resources to build directory - always runs during build
add_custom_target(MaterialXTestResources ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different
${CMAKE_CURRENT_SOURCE_DIR}/../../resources ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources
COMMENT "Copying resources to build directory")
# Copy OSL utilities to build directory - always runs during build
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/MaterialXRenderOsl/Utilities")
add_custom_target(MaterialXTestOslUtilities ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different
${CMAKE_CURRENT_SOURCE_DIR}/MaterialXRenderOsl/Utilities ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources/Utilities
COMMENT "Copying OSL utilities to build directory")
add_dependencies(MaterialXTestResources MaterialXTestOslUtilities)
endif()
add_dependencies(MaterialXTest MaterialXTestResources)
set_target_properties(
MaterialXTest PROPERTIES
OUTPUT_NAME MaterialXTest
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
VERSION "${MATERIALX_LIBRARY_VERSION}"
SOVERSION "${MATERIALX_MAJOR_VERSION}")
if(MATERIALX_BUILD_BENCHMARK_TESTS)
target_compile_definitions(MaterialXTest PRIVATE -DCATCH_CONFIG_ENABLE_BENCHMARKING)
endif()
target_link_libraries(
MaterialXTest
${CMAKE_DL_LIBS})