mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
[build] Clean up CMake files (#6802)
Explicitly list required components when using FindJava and FindJNI Consolidate find_package calls for Java, JNI, and OpenCV into the root CMakeLists.txt file Remove references to main_lib_dest Install missing generated headers Flatten some if statements Use LinkMacOSGUI macro instead of hand rolling it Stop installing OpenCV libraries and an extra ntcorejni library; OpenCV JAR will still be installed to make it easy to use Only print platform version on Windows Prevent GUI modules from being built when wpimath is off, which would otherwise cause a build failure Simplify build configuration checks Clean up fieldImages JAR creation Place built JARs in the same subdir as installed JARs Remove unnecessary JAR includes Remove extra directories in target_include_directories Improve CMake docs
This commit is contained in:
@@ -5,8 +5,6 @@ include(CompileWarnings)
|
||||
include(AddTest)
|
||||
include(LinkMacOSGUI)
|
||||
|
||||
find_package(OpenCV REQUIRED)
|
||||
|
||||
file(GLOB cscore_native_src src/main/native/cpp/*.cpp)
|
||||
file(GLOB cscore_linux_src src/main/native/linux/*.cpp)
|
||||
file(GLOB cscore_osx_src src/main/native/osx/*.cpp)
|
||||
@@ -16,23 +14,21 @@ file(GLOB cscore_windows_src src/main/native/windows/*.cpp)
|
||||
add_library(cscore ${cscore_native_src})
|
||||
set_target_properties(cscore PROPERTIES DEBUG_POSTFIX "d")
|
||||
|
||||
if(NOT MSVC)
|
||||
if(APPLE)
|
||||
target_sources(cscore PRIVATE ${cscore_osx_src} ${cscore_osx_objc_src})
|
||||
target_compile_options(cscore PRIVATE "-fobjc-arc")
|
||||
set_target_properties(
|
||||
cscore
|
||||
PROPERTIES
|
||||
LINK_FLAGS
|
||||
"-framework CoreFoundation -framework AVFoundation -framework Foundation -framework CoreMedia -framework CoreVideo"
|
||||
)
|
||||
else()
|
||||
target_sources(cscore PRIVATE ${cscore_linux_src})
|
||||
endif()
|
||||
else()
|
||||
if(APPLE)
|
||||
target_sources(cscore PRIVATE ${cscore_osx_src} ${cscore_osx_objc_src})
|
||||
target_compile_options(cscore PRIVATE "-fobjc-arc")
|
||||
set_target_properties(
|
||||
cscore
|
||||
PROPERTIES
|
||||
LINK_FLAGS
|
||||
"-framework CoreFoundation -framework AVFoundation -framework Foundation -framework CoreMedia -framework CoreVideo"
|
||||
)
|
||||
elseif(MSVC)
|
||||
target_sources(cscore PRIVATE ${cscore_windows_src})
|
||||
target_compile_definitions(cscore PUBLIC -DNOMINMAX)
|
||||
target_compile_definitions(cscore PRIVATE -D_CRT_SECURE_NO_WARNINGS)
|
||||
else()
|
||||
target_sources(cscore PRIVATE ${cscore_linux_src})
|
||||
endif()
|
||||
|
||||
target_include_directories(
|
||||
@@ -81,12 +77,9 @@ endforeach()
|
||||
|
||||
# Java bindings
|
||||
if(WITH_JAVA)
|
||||
find_package(Java REQUIRED)
|
||||
find_package(JNI REQUIRED)
|
||||
include(UseJava)
|
||||
|
||||
#find java files, copy them locally
|
||||
|
||||
#find JAR file, copy it locally
|
||||
if("${OPENCV_JAVA_INSTALL_DIR}" STREQUAL "")
|
||||
set(OPENCV_JAVA_INSTALL_DIR ${OpenCV_INSTALL_PATH}/share/java/opencv4)
|
||||
endif()
|
||||
@@ -101,24 +94,6 @@ if(WITH_JAVA)
|
||||
${OpenCV_INSTALL_PATH}/share/OpenCV/java
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
find_file(
|
||||
OPENCV_JNI_FILE
|
||||
NAMES
|
||||
libopencv_java${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}.so
|
||||
libopencv_java${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}.dylib
|
||||
opencv_java${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}.dll
|
||||
PATHS
|
||||
${OPENCV_JAVA_INSTALL_DIR}
|
||||
${OpenCV_INSTALL_PATH}/bin
|
||||
${OpenCV_INSTALL_PATH}/bin/Release
|
||||
${OpenCV_INSTALL_PATH}/bin/Debug
|
||||
${OpenCV_INSTALL_PATH}/lib
|
||||
${OpenCV_INSTALL_PATH}/lib/Release
|
||||
${OpenCV_INSTALL_PATH}/lib/Debug
|
||||
${OpenCV_INSTALL_PATH}/lib/jni
|
||||
${OpenCV_INSTALL_PATH}/share/java/opencv4
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
file(GLOB cscore_jni_src src/main/native/cpp/jni/CameraServerJNI.cpp)
|
||||
|
||||
@@ -130,6 +105,7 @@ if(WITH_JAVA)
|
||||
${JAVA_SOURCES}
|
||||
INCLUDE_JARS wpiutil_jar ${OPENCV_JAR_FILE}
|
||||
OUTPUT_NAME cscore
|
||||
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
|
||||
GENERATE_NATIVE_HEADERS cscore_jni_headers
|
||||
)
|
||||
set_property(TARGET cscore_jar PROPERTY FOLDER "java")
|
||||
@@ -138,27 +114,6 @@ if(WITH_JAVA)
|
||||
install_jar_exports(TARGETS cscore_jar FILE cscore_jar.cmake DESTINATION share/cscore)
|
||||
install(FILES ${OPENCV_JAR_FILE} DESTINATION "${java_lib_dest}")
|
||||
|
||||
if(MSVC)
|
||||
install(FILES ${OPENCV_JNI_FILE} DESTINATION "${jni_lib_dest}")
|
||||
|
||||
foreach(cvFile ${OpenCV_LIBS})
|
||||
find_file(
|
||||
${cvFile}Loc
|
||||
NAMES
|
||||
${cvFile}${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}.dll
|
||||
${cvFile}${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}d.dll
|
||||
PATHS
|
||||
${OPENCV_JAVA_INSTALL_DIR}
|
||||
${OpenCV_INSTALL_PATH}/bin
|
||||
${OpenCV_INSTALL_PATH}/bin/Release
|
||||
${OpenCV_INSTALL_PATH}/bin/Debug
|
||||
${OpenCV_INSTALL_PATH}/lib
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
install(FILES ${${cvFile}Loc} DESTINATION "${jni_lib_dest}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
add_library(cscorejni ${cscore_jni_src})
|
||||
wpilib_target_warnings(cscorejni)
|
||||
target_link_libraries(cscorejni PUBLIC cscore wpiutil ${OpenCV_LIBS})
|
||||
@@ -173,7 +128,6 @@ if(WITH_JAVA)
|
||||
endif()
|
||||
|
||||
if(WITH_JAVA_SOURCE)
|
||||
find_package(Java REQUIRED)
|
||||
include(UseJava)
|
||||
file(GLOB CSCORE_SOURCES src/main/java/edu/wpi/first/cscore/*.java)
|
||||
file(GLOB CSCORE_RAW_SOURCES src/main/java/edu/wpi/first/cscore/raw/*.java)
|
||||
@@ -183,6 +137,7 @@ if(WITH_JAVA_SOURCE)
|
||||
NAMESPACE "edu/wpi/first/cscore" ${CSCORE_SOURCES}
|
||||
NAMESPACE "edu/wpi/first/cscore/raw" ${CSCORE_RAW_SOURCES}
|
||||
OUTPUT_NAME cscore-sources
|
||||
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
|
||||
)
|
||||
|
||||
get_property(CSCORE_SRC_JAR_FILE TARGET cscore_src_jar PROPERTY JAR_FILE)
|
||||
|
||||
Reference in New Issue
Block a user