Debian Codegraph @

go/examples/CMakeLists.txt

raw
1 #
2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
17 # under the License.
18 #
19
20 if(BUILD_GO)
21
22 set(examples electron/broker electron/receive electron/send proton/broker)
23 file(GLOB_RECURSE example_source FOLLOW_SYMLINKS ${CMAKE_CURRENT_SOURCE_DIR}/*.go)
24
25 # Build example exes
26 foreach(example ${examples})
27 string(REPLACE / _ target ${example})
28 set(target "go_example_${target}")
29 set(output ${CMAKE_CURRENT_BINARY_DIR}/${example})
30 # Always run go_build, it will do nothing if there is nothing to do.
31 # Otherwise it's too hard to get the dependencies right.
32 add_custom_target(${target} ALL
33 COMMAND ${GO_BUILD} ${GO_EXAMPLE_FLAGS} -o ${output} ${CMAKE_CURRENT_SOURCE_DIR}/${example}.go
34 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
35 DEPENDS go-build)
36 list(APPEND example_targets ${target})
37 endforeach()
38
39 # Build test driver exe
40 set(test_exe ${CMAKE_CURRENT_BINARY_DIR}/example_test)
41 add_custom_target(go_example_test ALL
42 COMMAND ${GO_TEST} -c -o ${test_exe} ${CMAKE_CURRENT_SOURCE_DIR}/example_test.go
43 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
44
45 pn_add_test(
46 UNWRAPPED
47 NAME go-example-electron
48 PREPEND_ENVIRONMENT ${GO_ENV}
49 COMMAND ${test_exe} -dir ${CMAKE_CURRENT_BINARY_DIR}/electron -broker broker)
50
51 pn_add_test(
52 UNWRAPPED
53 NAME go-example-proton
54 PREPEND_ENVIRONMENT ${GO_ENV}
55 COMMAND ${test_exe} -dir ${CMAKE_CURRENT_BINARY_DIR}/electron -broker ../proton/broker)
56 list(APPEND ADDITIONAL_MAKE_CLEAN_FILES ${examples})
57 endif()