-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
95 lines (84 loc) · 3.46 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
# Copyright 2013-present Barefoot Networks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
# GTests
################################################################################
# Flags needed for GTest tests.
set (GTEST_ROOT ${P4C_SOURCE_DIR}/test/frameworks/gtest/googletest)
include_directories(${GTEST_ROOT} ${GTEST_ROOT}/include
${P4C_SOURCE_DIR}/control-plane/PI/include)
# For files generated by the protobuf compiler
include_directories(${P4C_BINARY_DIR}/control-plane)
# Configure GTest to disable support for SEH (which is irrelevant for p4c since
# we don't currently support Windows) and pthreads (which prevents GTest from
# using its internal TLS implementation, which interacts badly with libgc).
add_definitions(-DGTEST_HAS_SEH=0)
add_definitions(-DGTEST_HAS_PTHREAD=0)
# Build the GTest library itself.
add_library(gtest ${GTEST_ROOT}/src/gtest-all.cc)
set (GTEST_UNITTEST_SOURCES
gtest/arch_test.cpp
gtest/bitvec_test.cpp
gtest/call_graph_test.cpp
gtest/complex_bitwise.cpp
gtest/constant_expr_test.cpp
gtest/cstring.cpp
gtest/diagnostics.cpp
gtest/dumpjson.cpp
gtest/enumerator_test.cpp
gtest/equiv_test.cpp
gtest/exception_test.cpp
gtest/expr_uses_test.cpp
gtest/format_test.cpp
gtest/helpers.cpp
gtest/json_test.cpp
gtest/midend_test.cpp
gtest/opeq_test.cpp
gtest/ordered_map.cpp
gtest/ordered_set.cpp
gtest/path_test.cpp
gtest/p4runtime.cpp
gtest/source_file_test.cpp
gtest/transforms.cpp
gtest/stringify.cpp
)
set (GTEST_UNITTEST_HEADERS
gtest/helpers.h
)
# Add the non-backend-specific unit tests to cpplint.
add_cpplint_files (${CMAKE_CURRENT_SOURCE_DIR} "${GTEST_UNITTEST_SOURCES};${GTEST_UNITTEST_HEADERS}")
# Combine the executable and the non-backend-specific unit tests into a single
# unified compilation group.
set (GTEST_BASE_SOURCES
gtest/gtestp4c.cpp
${GTEST_UNITTEST_SOURCES}
)
build_unified(GTEST_BASE_SOURCES)
# Merge the base sources with the tests added to GTEST_SOURCES by specific
# backends or by extensions. We can't assume that one extension's GTests can be
# unified with another's, so we can't handle unified compilation transparently
# for all GTests.
# XXX(seth): The current approach is an awkward fit for cmake anyway. We should
# restructure backend-specific GTests to live in their own libraries, and just
# link the libraries in.
set (GTESTP4C_SOURCES ${GTEST_SOURCES} ${GTEST_BASE_SOURCES})
# Build `gtestp4c`, which will contain all of our tests. Backends and extensions
# can add GTests to `GTEST_SOURCES` to include them in the test executable. They
# can also link in additional libraries, if needed, by adding them to
# `GTEST_LDADD`.
add_executable (gtestp4c ${GTESTP4C_SOURCES})
target_link_libraries (gtestp4c ${GTEST_LDADD} ${P4C_LIBRARIES} gtest ${P4C_LIB_DEPS})
# Tests
add_test (NAME gtestp4c COMMAND gtestp4c WORKING_DIRECTORY ${P4C_BINARY_DIR})
set_tests_properties (gtestp4c PROPERTIES LABELS "gtest")