1# Copyright 2018 The Amber Authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15
16# Include this file to find Dawn and and set up compilation and linking.
17
18## Example usage:
19##
20## include(find_dawn.cmake)
21## # Set HAVE_DAWN to 1 if we have Dawn, and 0 otherwise.
22## add_definitions(-DHAVE_DAWN=$<BOOL:${Dawn_FOUND}>)
23## # Set up link dependencies.
24## if (${Dawn_FOUND})
25##   target_link_libraries(mylib Dawn::dawn_native)
26## endif()
27##
28
29# Exports these settings to the includer:
30#    Boolean Dawn_FOUND indicates whether we found Dawn.
31#    If Dawn was found, then library dependencies for Dawn::dawn and Dawn::dawn_native
32#    will be set up.
33set(Dawn_FOUND FALSE)
34
35# Setup via CMake setting variables:
36#
37#   Separately specify the directory locations of the Dawn headers and
38#   the dawn_native library.
39#
40#     -DDawn_INCLUDE_DIR=<directory containing dawn/dawn_export.h>
41#     -DDawn_GEN_INCLUDE_DIR=<directory containing dawn/dawn.h>
42#     -DDawn_LIBRARY_DIR=<directory containing dawn_native library
43#                         e.g., libdawn_native.a>
44
45
46find_path(Dawn_INCLUDE_DIR
47  NAMES dawn/dawn_export.h
48  PATHS
49    "${Dawn_INCLUDE_DIR}"
50  )
51find_path(Dawn_GEN_INCLUDE_DIR
52  NAMES dawn/dawn.h dawn/dawncpp.h
53  PATHS
54    "${Dawn_GEN_INCLUDE_DIR}"
55  )
56find_library(Dawn_LIBRARY
57  NAMES dawn
58  PATHS
59    "${Dawn_LIBRARY_DIR}"
60  )
61find_library(Dawn_native_LIBRARY
62  NAMES dawn_native
63  PATHS
64    "${Dawn_LIBRARY_DIR}"
65  )
66
67include(FindPackageHandleStandardArgs)
68find_package_handle_standard_args(Dawn
69  DEFAULT_MSG
70  Dawn_INCLUDE_DIR Dawn_GEN_INCLUDE_DIR
71  Dawn_LIBRARY Dawn_native_LIBRARY
72  )
73
74if(${Dawn_FOUND} AND NOT TARGET Dawn::dawn)
75  add_library(Dawn::dawn UNKNOWN IMPORTED)
76  set_target_properties(Dawn::dawn PROPERTIES
77    IMPORTED_LOCATION "${Dawn_LIBRARY}"
78    INTERFACE_INCLUDE_DIRECTORIES "${Dawn_INCLUDE_DIR};${Dawn_GEN_INCLUDE_DIR}")
79endif()
80if(${Dawn_FOUND} AND NOT TARGET Dawn::dawn_native)
81  add_library(Dawn::dawn_native UNKNOWN IMPORTED)
82  set_target_properties(Dawn::dawn_native PROPERTIES
83    IMPORTED_LOCATION "${Dawn_native_LIBRARY}"
84    INTERFACE_INCLUDE_DIRECTORIES "${Dawn_INCLUDE_DIR};${Dawn_GEN_INCLUDE_DIR}")
85endif()
86
87if (${Dawn_FOUND})
88  message(STATUS "Amber: Using Dawn headers at ${Dawn_INCLUDE_DIR}")
89  message(STATUS "Amber: Using Dawn generated headers at ${Dawn_GEN_INCLUDE_DIR}")
90  message(STATUS "Amber: Using Dawn library ${Dawn_LIBRARY}")
91  message(STATUS "Amber: Using Dawn native library ${Dawn_native_LIBRARY}")
92else()
93  message(STATUS "Amber: Did not find Dawn")
94endif()
95