vcpkg/ports/wpilib/0001-Update-cmake-find-to-support-vcpkg-libuv.patch
2019-04-16 08:03:18 -07:00

416 lines
15 KiB
Diff

From 1cc701c3620b24440fdd7ad95683dca09e575008 Mon Sep 17 00:00:00 2001
From: Thad House <thadhouse1@gmail.com>
Date: Sat, 13 Apr 2019 22:04:31 -0700
Subject: [PATCH] Update cmake find to support vcpkg libuv
Fix install on MSVC
---
CMakeLists.txt | 34 +++++++++++++++++++----
cameraserver/CMakeLists.txt | 5 ++--
cameraserver/cameraserver-config.cmake | 8 ------
cameraserver/cameraserver-config.cmake.in | 9 ++++++
cscore/CMakeLists.txt | 5 ++--
cscore/cscore-config.cmake | 6 ----
cscore/cscore-config.cmake.in | 6 ++++
hal/CMakeLists.txt | 5 ++--
hal/hal-config.cmake | 5 ----
hal/hal-config.cmake.in | 5 ++++
ntcore/CMakeLists.txt | 5 ++--
ntcore/ntcore-config.cmake | 5 ----
ntcore/ntcore-config.cmake.in | 5 ++++
wpilib-config.cmake.in | 6 ++--
wpilibc/CMakeLists.txt | 5 ++--
wpilibc/wpilibc-config.cmake | 10 -------
wpilibc/wpilibc-config.cmake.in | 9 ++++++
wpilibj/CMakeLists.txt | 2 +-
wpiutil/CMakeLists.txt | 5 ++--
wpiutil/wpiutil-config.cmake | 2 --
wpiutil/wpiutil-config.cmake.in | 7 +++++
21 files changed, 93 insertions(+), 56 deletions(-)
delete mode 100644 cameraserver/cameraserver-config.cmake
create mode 100644 cameraserver/cameraserver-config.cmake.in
delete mode 100644 cscore/cscore-config.cmake
create mode 100644 cscore/cscore-config.cmake.in
delete mode 100644 hal/hal-config.cmake
create mode 100644 hal/hal-config.cmake.in
delete mode 100644 ntcore/ntcore-config.cmake
create mode 100644 ntcore/ntcore-config.cmake.in
delete mode 100644 wpilibc/wpilibc-config.cmake
create mode 100644 wpilibc/wpilibc-config.cmake.in
delete mode 100644 wpiutil/wpiutil-config.cmake
create mode 100644 wpiutil/wpiutil-config.cmake.in
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a5b89d9ac..20557d78e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -51,6 +51,7 @@ option(WITHOUT_ALLWPILIB "Don't build allwpilib (removes OpenCV requirement)" ON
option(USE_EXTERNAL_HAL "Use a separately built HAL" OFF)
set(EXTERNAL_HAL_FILE "" CACHE FILEPATH "Location to look for an external HAL CMake File")
option(USE_VCPKG_LIBUV "Use vcpkg libuv" OFF)
+option(FLAT_INSTALL_WPILIB "Use a flat install directory" OFF)
if (NOT WITHOUT_JAVA AND NOT BUILD_SHARED_LIBS)
message(FATAL_ERROR "
@@ -66,26 +67,49 @@ set( main_lib_dest wpilib/lib )
set( java_lib_dest wpilib/java )
set( jni_lib_dest wpilib/jni )
-if (MSVC)
+if (MSVC OR FLAT_INSTALL_WPILIB)
set (wpilib_config_dir ${wpilib_dest})
else()
set (wpilib_config_dir share/wpilib)
endif()
+if (USE_VCPKG_LIBUV)
+set (LIBUV_VCPKG_REPLACE "find_package(unofficial-libuv CONFIG)")
+endif()
+
+if (MSVC OR FLAT_INSTALL_WPILIB)
+set(WPIUTIL_DEP_REPLACE "include($\{SELF_DIR\}/wpiutil-config.cmake)")
+set(NTCORE_DEP_REPLACE "include($\{SELF_DIR\}/ntcore-config.cmake)")
+set(CSCORE_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cscore-config.cmake)")
+set(CAMERASERVER_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cameraserver-config.cmake)")
+set(HAL_DEP_REPLACE_IMPL "include(\${SELF_DIR}/hal-config.cmake)")
+set(WPILIBC_DEP_REPLACE_IMPL "include(\${SELF_DIR}/wpilibc-config.cmake)")
+else()
+set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)")
+set(NTCORE_DEP_REPLACE "find_dependency(ntcore)")
+set(CSCORE_DEP_REPLACE_IMPL "find_dependency(cscore)")
+set(CAMERASERVER_DEP_REPLACE_IMPL "find_dependency(cameraserver)")
+set(HAL_DEP_REPLACE_IMPL "find_dependency(hal)")
+set(WPILIBC_DEP_REPLACE_IMPL "find_dependency(wpilibc)")
+endif()
+
+set(FILENAME_DEP_REPLACE "get_filename_component(SELF_DIR \"$\{CMAKE_CURRENT_LIST_FILE\}\" PATH)")
+set(SELF_DIR "$\{SELF_DIR\}")
+
add_subdirectory(wpiutil)
add_subdirectory(ntcore)
if (NOT WITHOUT_CSCORE)
+ set(CSCORE_DEP_REPLACE ${CSCORE_DEP_REPLACE_IMPL})
+ set(CAMERASERVER_DEP_REPLACE ${CAMERASERVER_DEP_REPLACE_IMPL})
add_subdirectory(cscore)
add_subdirectory(cameraserver)
- set (CSCORE_DEP_REPLACE "find_dependency(cscore)")
- set (CAMERASERVER_DEP_REPLACE "find_dependency(cameraserver)")
if (NOT WITHOUT_ALLWPILIB)
+ set(HAL_DEP_REPLACE ${HAL_DEP_REPLACE_IMPL})
+ set(WPILIBC_DEP_REPLACE ${WPILIBC_DEP_REPLACE_IMPL})
add_subdirectory(hal)
add_subdirectory(wpilibj)
add_subdirectory(wpilibc)
- set (HAL_DEP_REPLACE "find_dependency(hal)")
- set (WPILIBC_DEP_REPLACE "find_dependency(wpilibc)")
endif()
endif()
diff --git a/cameraserver/CMakeLists.txt b/cameraserver/CMakeLists.txt
index a3a74607a..1a75ae48d 100644
--- a/cameraserver/CMakeLists.txt
+++ b/cameraserver/CMakeLists.txt
@@ -43,13 +43,14 @@ if (NOT WITHOUT_JAVA AND MSVC)
install(TARGETS cameraserver RUNTIME DESTINATION "${jni_lib_dest}" COMPONENT Runtime)
endif()
-if (MSVC)
+if (MSVC OR FLAT_INSTALL_WPILIB)
set (cameraserver_config_dir ${wpilib_dest})
else()
set (cameraserver_config_dir share/cameraserver)
endif()
-install(FILES cameraserver-config.cmake DESTINATION ${cameraserver_config_dir})
+configure_file(cameraserver-config.cmake.in ${CMAKE_BINARY_DIR}/cameraserver-config.cmake )
+install(FILES ${CMAKE_BINARY_DIR}/cameraserver-config.cmake DESTINATION ${cameraserver_config_dir})
install(EXPORT cameraserver DESTINATION ${cameraserver_config_dir})
file(GLOB multiCameraServer_src multiCameraServer/src/main/native/cpp/*.cpp)
diff --git a/cameraserver/cameraserver-config.cmake b/cameraserver/cameraserver-config.cmake
deleted file mode 100644
index 2c2b1cc33..000000000
--- a/cameraserver/cameraserver-config.cmake
+++ /dev/null
@@ -1,8 +0,0 @@
-include(CMakeFindDependencyMacro)
-find_dependency(wpiutil)
-find_dependency(ntcore)
-find_dependency(cscore)
-find_dependency(OpenCV)
-
-get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
-include(${SELF_DIR}/cameraserver.cmake)
diff --git a/cameraserver/cameraserver-config.cmake.in b/cameraserver/cameraserver-config.cmake.in
new file mode 100644
index 000000000..0c71fc58c
--- /dev/null
+++ b/cameraserver/cameraserver-config.cmake.in
@@ -0,0 +1,9 @@
+include(CMakeFindDependencyMacro)
+@FILENAME_DEP_REPLACE@
+@WPIUTIL_DEP_REPLACE@
+@NTCORE_DEP_REPLACE@
+@CSCORE_DEP_REPLACE@
+find_dependency(OpenCV)
+
+include(${SELF_DIR}/cameraserver.cmake)
+
diff --git a/cscore/CMakeLists.txt b/cscore/CMakeLists.txt
index 52bcb54a2..805b3a583 100644
--- a/cscore/CMakeLists.txt
+++ b/cscore/CMakeLists.txt
@@ -36,13 +36,14 @@ set_property(TARGET cscore PROPERTY FOLDER "libraries")
install(TARGETS cscore EXPORT cscore DESTINATION "${main_lib_dest}")
install(DIRECTORY src/main/native/include/ DESTINATION "${include_dest}/cscore")
-if (MSVC)
+if (MSVC OR FLAT_INSTALL_WPILIB)
set (cscore_config_dir ${wpilib_dest})
else()
set (cscore_config_dir share/cscore)
endif()
-install(FILES cscore-config.cmake DESTINATION ${cscore_config_dir})
+configure_file(cscore-config.cmake.in ${CMAKE_BINARY_DIR}/cscore-config.cmake )
+install(FILES ${CMAKE_BINARY_DIR}/cscore-config.cmake DESTINATION ${cscore_config_dir})
install(EXPORT cscore DESTINATION ${cscore_config_dir})
SUBDIR_LIST(cscore_examples "${CMAKE_CURRENT_SOURCE_DIR}/examples")
diff --git a/cscore/cscore-config.cmake b/cscore/cscore-config.cmake
deleted file mode 100644
index 790633b87..000000000
--- a/cscore/cscore-config.cmake
+++ /dev/null
@@ -1,6 +0,0 @@
-include(CMakeFindDependencyMacro)
-find_dependency(wpiutil)
-find_dependency(OpenCV)
-
-get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
-include(${SELF_DIR}/cscore.cmake)
diff --git a/cscore/cscore-config.cmake.in b/cscore/cscore-config.cmake.in
new file mode 100644
index 000000000..7894fbaec
--- /dev/null
+++ b/cscore/cscore-config.cmake.in
@@ -0,0 +1,6 @@
+include(CMakeFindDependencyMacro)
+@FILENAME_DEP_REPLACE@
+@WPIUTIL_DEP_REPLACE@
+find_dependency(OpenCV)
+
+include(${SELF_DIR}/cscore.cmake)
diff --git a/hal/CMakeLists.txt b/hal/CMakeLists.txt
index e52d90ff0..7394495db 100644
--- a/hal/CMakeLists.txt
+++ b/hal/CMakeLists.txt
@@ -55,13 +55,14 @@ install(TARGETS hal EXPORT hal DESTINATION "${main_lib_dest}")
install(DIRECTORY src/main/native/include/ DESTINATION "${include_dest}/hal")
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/gen DESTINATION "${include_dest}/hal")
-if (MSVC)
+if (MSVC OR FLAT_INSTALL_WPILIB)
set (hal_config_dir ${wpilib_dest})
else()
set (hal_config_dir share/hal)
endif()
-install(FILES hal-config.cmake DESTINATION ${hal_config_dir})
+configure_file(hal-config.cmake.in ${CMAKE_BINARY_DIR}/hal-config.cmake )
+install(FILES ${CMAKE_BINARY_DIR}/hal-config.cmake DESTINATION ${hal_config_dir})
install(EXPORT hal DESTINATION ${hal_config_dir})
# Java bindings
diff --git a/hal/hal-config.cmake b/hal/hal-config.cmake
deleted file mode 100644
index 97a574ebf..000000000
--- a/hal/hal-config.cmake
+++ /dev/null
@@ -1,5 +0,0 @@
-include(CMakeFindDependencyMacro)
-find_dependency(wpiutil)
-
-get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
-include(${SELF_DIR}/hal.cmake)
diff --git a/hal/hal-config.cmake.in b/hal/hal-config.cmake.in
new file mode 100644
index 000000000..ae5533c27
--- /dev/null
+++ b/hal/hal-config.cmake.in
@@ -0,0 +1,5 @@
+include(CMakeFindDependencyMacro)
+@FILENAME_DEP_REPLACE@
+@WPIUTIL_DEP_REPLACE@
+
+include(${SELF_DIR}/hal.cmake)
diff --git a/ntcore/CMakeLists.txt b/ntcore/CMakeLists.txt
index 47e226401..1c00da138 100644
--- a/ntcore/CMakeLists.txt
+++ b/ntcore/CMakeLists.txt
@@ -16,13 +16,14 @@ set_property(TARGET ntcore PROPERTY FOLDER "libraries")
install(TARGETS ntcore EXPORT ntcore DESTINATION "${main_lib_dest}")
install(DIRECTORY src/main/native/include/ DESTINATION "${include_dest}/ntcore")
-if (MSVC)
+if (MSVC OR FLAT_INSTALL_WPILIB)
set (ntcore_config_dir ${wpilib_dest})
else()
set (ntcore_config_dir share/ntcore)
endif()
-install(FILES ntcore-config.cmake DESTINATION ${ntcore_config_dir})
+configure_file(ntcore-config.cmake.in ${CMAKE_BINARY_DIR}/ntcore-config.cmake )
+install(FILES ${CMAKE_BINARY_DIR}/ntcore-config.cmake DESTINATION ${ntcore_config_dir})
install(EXPORT ntcore DESTINATION ${ntcore_config_dir})
# Java bindings
diff --git a/ntcore/ntcore-config.cmake b/ntcore/ntcore-config.cmake
deleted file mode 100644
index 6be1dda4a..000000000
--- a/ntcore/ntcore-config.cmake
+++ /dev/null
@@ -1,5 +0,0 @@
-include(CMakeFindDependencyMacro)
-find_dependency(wpiutil)
-
-get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
-include(${SELF_DIR}/ntcore.cmake)
diff --git a/ntcore/ntcore-config.cmake.in b/ntcore/ntcore-config.cmake.in
new file mode 100644
index 000000000..1e950e90c
--- /dev/null
+++ b/ntcore/ntcore-config.cmake.in
@@ -0,0 +1,5 @@
+include(CMakeFindDependencyMacro)
+@FILENAME_DEP_REPLACE@
+@WPIUTIL_DEP_REPLACE@
+
+include(${SELF_DIR}/ntcore.cmake)
diff --git a/wpilib-config.cmake.in b/wpilib-config.cmake.in
index 445db82d7..2c15dfe09 100644
--- a/wpilib-config.cmake.in
+++ b/wpilib-config.cmake.in
@@ -1,8 +1,10 @@
include(CMakeFindDependencyMacro)
+@FILENAME_DEP_REPLACE@
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_dependency(Threads)
-find_dependency(wpiutil)
-find_dependency(ntcore)
+@LIBUV_VCPKG_REPLACE@
+@WPIUTIL_DEP_REPLACE@
+@NTCORE_DEP_REPLACE@
@CSCORE_DEP_REPLACE@
@CAMERASERVER_DEP_REPLACE@
@HAL_DEP_REPLACE@
diff --git a/wpilibc/CMakeLists.txt b/wpilibc/CMakeLists.txt
index da3587188..7b131838b 100644
--- a/wpilibc/CMakeLists.txt
+++ b/wpilibc/CMakeLists.txt
@@ -20,11 +20,12 @@ set_property(TARGET wpilibc PROPERTY FOLDER "libraries")
install(TARGETS wpilibc EXPORT wpilibc DESTINATION "${main_lib_dest}")
install(DIRECTORY src/main/native/include/ DESTINATION "${include_dest}/wpilibc")
-if (MSVC)
+if (MSVC OR FLAT_INSTALL_WPILIB)
set (wpilibc_config_dir ${wpilib_dest})
else()
set (wpilibc_config_dir share/wpilibc)
endif()
-install(FILES wpilibc-config.cmake DESTINATION ${wpilibc_config_dir})
+configure_file(wpilibc-config.cmake.in ${CMAKE_BINARY_DIR}/wpilibc-config.cmake )
+install(FILES ${CMAKE_BINARY_DIR}/wpilibc-config.cmake DESTINATION ${wpilibc_config_dir})
install(EXPORT wpilibc DESTINATION ${wpilibc_config_dir})
diff --git a/wpilibc/wpilibc-config.cmake b/wpilibc/wpilibc-config.cmake
deleted file mode 100644
index 86f077c71..000000000
--- a/wpilibc/wpilibc-config.cmake
+++ /dev/null
@@ -1,10 +0,0 @@
-include(CMakeFindDependencyMacro)
-find_dependency(wpiutil)
-find_dependency(ntcore)
-find_dependency(cscore)
-find_dependency(cameraserver)
-find_dependency(hal)
-find_dependency(OpenCV)
-
-get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
-include(${SELF_DIR}/wpilibc.cmake)
diff --git a/wpilibc/wpilibc-config.cmake.in b/wpilibc/wpilibc-config.cmake.in
new file mode 100644
index 000000000..4332c550e
--- /dev/null
+++ b/wpilibc/wpilibc-config.cmake.in
@@ -0,0 +1,9 @@
+include(CMakeFindDependencyMacro)
+@FILENAME_DEP_REPLACE@
+@WPIUTIL_DEP_REPLACE@
+@NTCORE_DEP_REPLACE@
+@CSCORE_DEP_REPLACE@
+@CAMERASERVER_DEP_REPLACE@
+@HAL_DEP_REPLACE@
+
+include(${SELF_DIR}/wpilibc.cmake)
diff --git a/wpilibj/CMakeLists.txt b/wpilibj/CMakeLists.txt
index 61fb558fa..964fa0cc1 100644
--- a/wpilibj/CMakeLists.txt
+++ b/wpilibj/CMakeLists.txt
@@ -23,7 +23,7 @@ if (NOT WITHOUT_JAVA)
set_property(TARGET wpilibj_jar PROPERTY FOLDER "java")
- if (MSVC)
+ if (MSVC OR FLAT_INSTALL_WPILIB)
set (wpilibj_config_dir ${wpilib_dest})
else()
set (wpilibj_config_dir share/wpilibj)
diff --git a/wpiutil/CMakeLists.txt b/wpiutil/CMakeLists.txt
index bcc0bcf5b..de66a9671 100644
--- a/wpiutil/CMakeLists.txt
+++ b/wpiutil/CMakeLists.txt
@@ -124,13 +124,14 @@ if (NOT WITHOUT_JAVA AND MSVC)
install(TARGETS wpiutil RUNTIME DESTINATION "${jni_lib_dest}" COMPONENT Runtime)
endif()
-if (MSVC)
+if (MSVC OR FLAT_INSTALL_WPILIB)
set (wpiutil_config_dir ${wpilib_dest})
else()
set (wpiutil_config_dir share/wpiutil)
endif()
-install(FILES wpiutil-config.cmake DESTINATION ${wpiutil_config_dir})
+configure_file(wpiutil-config.cmake.in ${CMAKE_BINARY_DIR}/wpiutil-config.cmake )
+install(FILES ${CMAKE_BINARY_DIR}/wpiutil-config.cmake DESTINATION ${wpiutil_config_dir})
install(EXPORT wpiutil DESTINATION ${wpiutil_config_dir})
SUBDIR_LIST(wpiutil_examples "${CMAKE_CURRENT_SOURCE_DIR}/examples")
diff --git a/wpiutil/wpiutil-config.cmake b/wpiutil/wpiutil-config.cmake
deleted file mode 100644
index 91d01a77c..000000000
--- a/wpiutil/wpiutil-config.cmake
+++ /dev/null
@@ -1,2 +0,0 @@
-get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
-include(${SELF_DIR}/wpiutil.cmake)
diff --git a/wpiutil/wpiutil-config.cmake.in b/wpiutil/wpiutil-config.cmake.in
new file mode 100644
index 000000000..5d71bc192
--- /dev/null
+++ b/wpiutil/wpiutil-config.cmake.in
@@ -0,0 +1,7 @@
+include(CMakeFindDependencyMacro)
+@FILENAME_DEP_REPLACE@
+set(THREADS_PREFER_PTHREAD_FLAG ON)
+find_dependency(Threads)
+@LIBUV_VCPKG_REPLACE@
+
+include(${SELF_DIR}/wpiutil.cmake)
--
2.18.0.windows.1