forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
116 lines (102 loc) · 4.65 KB
/
CMakeLists.txt
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
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)
if(MATERIALX_BUILD_GEN_GLSL)
add_subdirectory(MaterialXGenGlsl)
target_link_libraries(MaterialXTest MaterialXGenGlsl)
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()
endif()
if(MATERIALX_BUILD_RENDER)
add_subdirectory(MaterialXRender)
target_link_libraries(MaterialXTest MaterialXRender)
if (MATERIALX_BUILD_OIIO)
target_link_libraries(MaterialXTest ${OPENIMAGEIO_LIBRARIES})
endif()
if(MATERIALX_BUILD_GEN_GLSL)
add_subdirectory(MaterialXRenderGlsl)
target_link_libraries(MaterialXTest MaterialXRenderGlsl)
endif()
if(MATERIALX_BUILD_GEN_OSL)
add_subdirectory(MaterialXRenderOsl)
target_link_libraries(MaterialXTest MaterialXRenderOsl)
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()
# TODO: Only do this stuff when it's relevant
add_custom_command(TARGET MaterialXTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/../../libraries ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libraries)
if(MATERIALX_OSL_LEGACY_CLOSURES)
add_custom_command(TARGET MaterialXTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rename
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libraries/pbrlib/genosl/pbrlib_genosl_impl.legacy ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libraries/pbrlib/genosl/pbrlib_genosl_impl.mtlx)
endif()
if(MATERIALX_BUILD_GEN_MDL)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../source/MaterialXGenMdl/mdl/"
DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${MATERIALX_INSTALL_MDL_MODULE_PATH}/mdl)
endif()
add_custom_command(TARGET MaterialXTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/../../resources ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources)
add_custom_command(TARGET MaterialXTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/MaterialXRenderOsl/Utilities ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources/Utilities)
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}")
target_link_libraries(
MaterialXTest
${CMAKE_DL_LIBS})