-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathFindOcean.cmake
More file actions
134 lines (124 loc) · 4.11 KB
/
Copy pathFindOcean.cmake
File metadata and controls
134 lines (124 loc) · 4.11 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# 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.
# FindOcean.cmake — fetch, build, and install Facebook Ocean as static libraries
# Place this in a folder on CMAKE_MODULE_PATH (e.g. cmake/modules)
# Prevent multiple inclusion
if(Ocean_FOUND)
return()
endif()
# Reuse the Ocean targets installed alongside VRS when this module is loaded
# from vrslibConfig.cmake. This avoids fetching and rebuilding Ocean in every
# downstream project.
set(_Ocean_INSTALLED_TARGETS "${CMAKE_CURRENT_LIST_DIR}/../../Ocean/FindOceanTargets.cmake")
if(EXISTS "${_Ocean_INSTALLED_TARGETS}")
include("${_Ocean_INSTALLED_TARGETS}")
if(TARGET Ocean::Ocean)
set(Ocean_LIBRARIES Ocean::Ocean)
set(Ocean_FOUND TRUE)
unset(_Ocean_INSTALLED_TARGETS)
return()
endif()
endif()
unset(_Ocean_INSTALLED_TARGETS)
# --------------------------
# 0) Standard install dirs
include(GNUInstallDirs)
# Try to find Ocean in fbsource tree first
set(OCEAN_FBSOURCE_PATHS
"${VRS_SOURCE_DIR}/../../../xplat/ocean"
"${CMAKE_CURRENT_SOURCE_DIR}/../../../xplat/ocean"
"${CMAKE_SOURCE_DIR}/../../../xplat/ocean"
)
foreach(ocean_path IN LISTS OCEAN_FBSOURCE_PATHS)
if(EXISTS "${ocean_path}/CMakeLists.txt")
set(OCEAN_SOURCE_DIR "${ocean_path}")
break()
endif()
endforeach()
if(OCEAN_SOURCE_DIR)
message(STATUS "Found Ocean in fbsource at ${OCEAN_SOURCE_DIR}")
set(OCEAN_BUILD_MINIMAL ON CACHE BOOL "" FORCE)
set(OCEAN_BUILD_TEST OFF CACHE BOOL "" FORCE)
# Ocean requires CMake 3.26, VRS requires 3.16 - allow higher version
add_subdirectory("${OCEAN_SOURCE_DIR}" "${CMAKE_BINARY_DIR}/ocean")
set(ocean_SOURCE_DIR "${OCEAN_SOURCE_DIR}")
else()
# --------------------------
# 1) Fetch & build Ocean
include(FetchContent)
FetchContent_Declare(
ocean
GIT_REPOSITORY https://github.com/facebookresearch/ocean.git
GIT_TAG 5fca1d27a9f37e868738b6db09a6b1e00723d80f # master branch, 2025.11.07
)
set(OCEAN_BUILD_MINIMAL ON)
set(OCEAN_BUILD_TEST OFF)
message(STATUS "⤷ FetchContent: pulling and building Facebook Ocean…")
FetchContent_MakeAvailable(ocean)
endif()
# --------------------------
# 2) Normalize component include dirs to avoid build-tree paths
foreach(_lib IN ITEMS ocean_base ocean_cv ocean_math)
# Clear any pre-existing include dirs
set_target_properties(${_lib} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ""
)
# Add proper GENERATOR_EXPR-based includes
target_include_directories(${_lib} INTERFACE
$<BUILD_INTERFACE:${ocean_SOURCE_DIR}/impl>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
endforeach()
# --------------------------
# 3) Bundle into a single INTERFACE target
add_library(ocean INTERFACE)
target_link_libraries(ocean INTERFACE
ocean_base
ocean_cv
ocean_math
)
add_library(Ocean::Ocean ALIAS ocean)
set_target_properties(ocean PROPERTIES EXPORT_NAME Ocean)
# --------------------------
# 4) Installation
install(
TARGETS
ocean_base
ocean_cv
ocean_math
ocean
EXPORT OceanTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
DIRECTORY ${ocean_SOURCE_DIR}/impl/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)
install(
EXPORT OceanTargets
FILE FindOceanTargets.cmake
NAMESPACE Ocean::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Ocean
)
# --------------------------
# 5) In-tree find_package support
set(Ocean_FOUND TRUE)
set(Ocean_LIBRARIES Ocean::Ocean)
set(Ocean_INCLUDE_DIRS "${ocean_SOURCE_DIR}/impl")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Ocean
REQUIRED_VARS Ocean_LIBRARIES
)