Merge pull request #2826 from amdrexu/bugfix
[platform/upstream/glslang.git] / gtests / CMakeLists.txt
1 # Copyright (C) 2020 The Khronos Group Inc.
2 #
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 #
9 #    Redistributions of source code must retain the above copyright
10 #    notice, this list of conditions and the following disclaimer.
11 #
12 #    Redistributions in binary form must reproduce the above
13 #    copyright notice, this list of conditions and the following
14 #    disclaimer in the documentation and/or other materials provided
15 #    with the distribution.
16 #
17 #    Neither the name of The Khronos Group Inc. nor the names of its
18 #    contributors may be used to endorse or promote products derived
19 #    from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33
34 if(BUILD_TESTING)
35     if(TARGET gmock)
36         message(STATUS "Google Mock found - building tests")
37
38         set(TEST_SOURCES
39             # Framework related source files
40             ${CMAKE_CURRENT_SOURCE_DIR}/Initializer.h
41             ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
42             ${CMAKE_CURRENT_SOURCE_DIR}/Settings.cpp
43             ${CMAKE_CURRENT_SOURCE_DIR}/Settings.h
44             ${CMAKE_CURRENT_SOURCE_DIR}/TestFixture.cpp
45             ${CMAKE_CURRENT_SOURCE_DIR}/TestFixture.h
46
47             # Test related source files
48             ${CMAKE_CURRENT_SOURCE_DIR}/AST.FromFile.cpp
49             ${CMAKE_CURRENT_SOURCE_DIR}/BuiltInResource.FromFile.cpp
50             ${CMAKE_CURRENT_SOURCE_DIR}/Common.cpp
51             ${CMAKE_CURRENT_SOURCE_DIR}/Config.FromFile.cpp
52             ${CMAKE_CURRENT_SOURCE_DIR}/HexFloat.cpp
53             ${CMAKE_CURRENT_SOURCE_DIR}/Hlsl.FromFile.cpp
54             ${CMAKE_CURRENT_SOURCE_DIR}/Link.FromFile.cpp
55             ${CMAKE_CURRENT_SOURCE_DIR}/Link.FromFile.Vk.cpp
56             ${CMAKE_CURRENT_SOURCE_DIR}/Pp.FromFile.cpp
57             ${CMAKE_CURRENT_SOURCE_DIR}/Spv.FromFile.cpp
58             ${CMAKE_CURRENT_SOURCE_DIR}/VkRelaxed.FromFile.cpp
59             ${CMAKE_CURRENT_SOURCE_DIR}/GlslMapIO.FromFile.cpp)
60
61         if(ENABLE_SPVREMAPPER)
62             set(TEST_SOURCES ${TEST_SOURCES}
63                 ${CMAKE_CURRENT_SOURCE_DIR}/Remap.FromFile.cpp)
64         endif()
65
66
67         add_executable(glslangtests ${TEST_SOURCES})
68         glslang_pch(glslangtests ${CMAKE_CURRENT_SOURCE_DIR}/pch.h)
69         set_property(TARGET glslangtests PROPERTY FOLDER tests)
70         glslang_set_link_args(glslangtests)
71         if(ENABLE_GLSLANG_INSTALL)
72             install(TARGETS glslangtests EXPORT glslangtestsTargets
73                     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
74                         install(EXPORT glslangtestsTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
75         endif()
76
77         set(GLSLANG_TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../Test")
78         # Supply a default test root directory, so that manual testing
79         # doesn't have to specify the --test-root option in the normal
80         # case that you want to use the tests from the same source tree.
81         target_compile_definitions(glslangtests
82                                    PRIVATE GLSLANG_TEST_DIRECTORY="${GLSLANG_TEST_DIRECTORY}")
83         target_include_directories(glslangtests PRIVATE
84                                    ${CMAKE_CURRENT_SOURCE_DIR}
85                                    ${PROJECT_SOURCE_DIR}
86                                    ${gmock_SOURCE_DIR}/include
87                                    ${gtest_SOURCE_DIR}/include)
88
89         if(ENABLE_OPT)
90             target_include_directories(glslangtests
91                 PRIVATE ${spirv-tools_SOURCE_DIR}/include
92             )
93         endif()
94
95         set(LIBRARIES
96             glslang OSDependent OGLCompiler glslang
97             SPIRV glslang-default-resource-limits)
98
99         if(ENABLE_SPVREMAPPER)
100             set(LIBRARIES ${LIBRARIES} SPVRemapper)
101         endif()
102
103         if(ENABLE_HLSL)
104             set(LIBRARIES ${LIBRARIES} HLSL)
105         endif()
106         target_link_libraries(glslangtests PRIVATE ${LIBRARIES} gmock)
107
108         add_test(NAME glslang-gtests
109                  COMMAND glslangtests --test-root "${GLSLANG_TEST_DIRECTORY}")
110     endif()
111 endif()