Skip to content

Commit

Permalink
Merge pull request #6 from Gold856/wpical
Browse files Browse the repository at this point in the history
Fix build
  • Loading branch information
ElliotScher authored Dec 14, 2024
2 parents bfb1153 + 865c01f commit a3f3575
Show file tree
Hide file tree
Showing 25 changed files with 802 additions and 790 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pregenerate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
with:
name: pregenerated-files-fixes
path: pregenerated-files-fixes.patch
if: ${{ failure() }}
if: ${{ failure() }}
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ cmake_dependent_option(
)
option(WITH_CSCORE "Build cscore (needs OpenCV)" ON)
option(WITH_NTCORE "Build ntcore" ON)
option(WITH_WPICAL "Build wpical" OFF)
option(WITH_WPIMATH "Build wpimath" ON)
cmake_dependent_option(
WITH_WPIUNITS
Expand Down Expand Up @@ -142,6 +143,7 @@ if(WITH_DOCS)
include(AddDoxygenDocs)
add_doxygen_docs()
endif()
find_package(Ceres CONFIG)
find_package(LIBSSH CONFIG 0.7.1)

set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
Expand Down Expand Up @@ -314,7 +316,9 @@ if(WITH_GUI)
add_subdirectory(glass)
add_subdirectory(outlineviewer)
add_subdirectory(sysid)
add_subdirectory(wpical)
if(Ceres_FOUND AND WITH_WPICAL)
add_subdirectory(wpical)
endif()
if(LIBSSH_FOUND)
add_subdirectory(roborioteamnumbersetter)
add_subdirectory(datalogtool)
Expand Down Expand Up @@ -354,6 +358,6 @@ endif()
if(WITH_SIMULATION_MODULES)
add_subdirectory(simulation)
endif()

configure_file(wpilib-config.cmake.in ${WPILIB_BINARY_DIR}/wpilib-config.cmake)
install(FILES ${WPILIB_BINARY_DIR}/wpilib-config.cmake DESTINATION share/wpilib)
2 changes: 1 addition & 1 deletion shared/java/javastyle.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ spotless {
target fileTree('.') {
include '**/*.json'
exclude '**/build/**', '**/build-*/**', '**/bin/**'
exclude '**/simgui-ds.json', '**/simgui-window.json', '**/simgui.json', '**/networktables.json', '**/*test.json', '**/canera calibration.json'
exclude '**/simgui-ds.json', '**/simgui-window.json', '**/simgui.json', '**/networktables.json', '**/*test.json', '**/camera calibration.json'
}
gson()
.indentWithSpaces(2)
Expand Down
52 changes: 34 additions & 18 deletions upstream_utils/mrcal_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@

from upstream_utils import Lib, walk_cwd_and_copy_if


def delete_lines_by_range(file_path, start_line, end_line):
# Read all lines from the file
with open(file_path, 'r') as file:
with open(file_path, "r") as file:
lines = file.readlines()

# Filter out lines that are within the specified range
filtered_lines = [line for i, line in enumerate(lines, start=1) if not (start_line <= i <= end_line)]

filtered_lines = [
line
for i, line in enumerate(lines, start=1)
if not (start_line <= i <= end_line)
]

# Write the remaining lines back to the file
with open(file_path, 'w') as file:
with open(file_path, "w") as file:
file.writelines(filtered_lines)


def copy_upstream_src(wpilib_root):
wpical = os.path.join(wpilib_root, "wpical")

Expand All @@ -33,28 +39,38 @@ def copy_upstream_src(wpilib_root):
os.path.join(wpical, "src/main/native/thirdparty/mrcal_java/include"),
)

for f in files:
delete_lines_by_range(f, 24, 29)

files = walk_cwd_and_copy_if(
lambda dp, f: f.endswith("mrcal_wrapper.cpp"),
os.path.join(wpical, "src/main/native/thirdparty/mrcal_java/src"),
)

for f in files:
delete_lines_by_range(f, 30, 41)

for f in files:
with open(f) as file:
content = file.read()
content = content.replace("#include <malloc.h>", "")
content = content.replace("// mrcal_point3_t *c_observations_point_pool = observations_point;", "mrcal_point3_t *c_observations_point_pool = observations_point;")
content = content.replace("// mrcal_observation_point_triangulated_t *observations_point_triangulated =", "mrcal_observation_point_triangulated_t *observations_point_triangulated = NULL;")
content = content.replace("// observations_point_triangulated,", "observations_point_triangulated,")
content = content.replace("// 0, // hard-coded to 0", "0, // hard-coded to 0")
content = content.replace("// observations_point_triangulated, -1,", "observations_point_triangulated, -1,")
content = content.replace("c_observations_board_pool, &mrcal_lensmodel, c_imagersizes,", "c_observations_board_pool, c_observations_point_pool, &mrcal_lensmodel, c_imagersizes,")
content = content.replace("calobject_warp, stats.Noutliers);", "calobject_warp, stats.Noutliers_board);")
content = content.replace(
"// mrcal_point3_t *c_observations_point_pool = observations_point;",
"mrcal_point3_t *c_observations_point_pool = observations_point;",
)
content = content.replace(
"// mrcal_observation_point_triangulated_t *observations_point_triangulated =",
"mrcal_observation_point_triangulated_t *observations_point_triangulated = NULL;",
)
content = content.replace(
"// observations_point_triangulated,",
"observations_point_triangulated,",
)
content = content.replace(
"// 0, // hard-coded to 0", "0, // hard-coded to 0"
)
content = content.replace(
"// observations_point_triangulated, -1,",
"observations_point_triangulated, -1,",
)
content = content.replace(
"c_observations_board_pool, &mrcal_lensmodel, c_imagersizes,",
"c_observations_board_pool, c_observations_point_pool, &mrcal_lensmodel, c_imagersizes,",
)
with open(f, "w") as file:
file.write(content)

Expand Down
98 changes: 91 additions & 7 deletions wpical/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ configure_file(src/main/generate/WPILibVersion.cpp.in WPILibVersion.cpp)
generate_resources(src/main/native/resources generated/main/cpp WPIcal wpical wpical_resources_src)

file(GLOB wpical_src src/main/native/cpp/*.cpp ${CMAKE_CURRENT_BINARY_DIR}/WPILibVersion.cpp)
file(
GLOB_RECURSE wpical_thirdparty_src
src/main/native/thirdparty/libdogleg/src/*.cpp
src/main/native/thirdparty/mrcal/src/*.c
src/main/native/thirdparty/mrcal/src/*.cpp
src/main/native/thirdparty/mrcal_java/src/*.cpp
)

if(WIN32)
set(wpical_rc src/main/native/win/wpical.rc)
Expand All @@ -18,13 +25,72 @@ elseif(APPLE)
set_source_files_properties(${APP_ICON_MACOSX} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
endif()

add_executable(wpical ${wpical_src} ${wpical_resources_src} ${wpical_rc} ${APP_ICON_MACOSX})
add_executable(
wpical
${wpical_src}
${wpical_thirdparty_src}
${wpical_resources_src}
${wpical_rc}
${APP_ICON_MACOSX}
)
wpilib_link_macos_gui(wpical)
wpilib_target_warnings(wpical)
target_include_directories(wpical PRIVATE src/main/native/include)
target_include_directories(
wpical
PRIVATE
src/main/native/include
src/main/native/thirdparty/libdogleg/include
src/main/native/thirdparty/mrcal/include
src/main/native/thirdparty/mrcal_java/include
)

if(MSVC)
set(compile_flags
/wd4047
/wd4098
/wd4267
/wd4068
/wd4101
/wd4200
/wd4576
/wd4715
)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(compile_flags
-Wno-format-nonliteral
-Wno-unused-variable
-Wno-missing-field-initializers
-Wno-gnu-anonymous-struct
-Wno-c99-extensions
-Wno-zero-length-array
-Wno-nested-anon-types
-Wno-sign-compare
-Wno-unused-function
-Wno-missing-braces
-Wno-null-conversion
-Wno-unused-but-set-variable
)
else()
set(compile_flags
-Wno-format-nonliteral
-Wno-unused-variable
-Wno-unused-function
-Wno-sign-compare
-Wno-missing-field-initializers
)
endif()
target_compile_options(wpical PRIVATE ${compile_flags})

find_package(OpenCV REQUIRED)
target_link_libraries(wpical apriltaglib ${OpenCV_LIBS} wpiutil wpimath)
find_package(Ceres CONFIG REQUIRED)
target_link_libraries(
wpical
apriltag
${OpenCV_LIBS}
wpigui
wpiutil
Ceres::ceres
)

if(WIN32)
set_target_properties(wpical PROPERTIES WIN32_EXECUTABLE YES)
Expand All @@ -35,11 +101,29 @@ endif()
if(WITH_TESTS)
wpilib_add_test(wpical src/test/native/cpp)
wpilib_link_macos_gui(wpical_test)
target_sources(wpical_test PRIVATE ${sysid_src})
target_compile_definitions(wpical_test PRIVATE RUNNING_WPICAL_TEST)
target_sources(wpical_test PRIVATE ${wpical_src} ${wpical_thirdparty_src})
target_compile_definitions(wpical_test PRIVATE RUNNING_WPICAL_TESTS)

if(MSVC)
target_compile_options(wpical_test PRIVATE /utf-8)
endif()
target_include_directories(wpical_test PRIVATE src/main/native/cpp src/main/native/include)
target_link_libraries(wpical_test googletest)

target_compile_options(wpical_test PRIVATE ${compile_flags})
target_include_directories(
wpical_test
PRIVATE
src/main/native/include
src/main/native/thirdparty/libdogleg/include
src/main/native/thirdparty/mrcal/include
src/main/native/thirdparty/mrcal_java/include
)
target_link_libraries(
wpical_test
googletest
apriltag
${OpenCV_LIBS}
wpigui
wpiutil
Ceres::ceres
)
endif()
20 changes: 9 additions & 11 deletions wpical/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,9 @@ nativeUtils.platformConfigs.each {
it.cppCompiler.args.remove("-pedantic")
it.cppCompiler.args.add("-Wno-unused-variable")
it.cppCompiler.args.add("-Wno-unused-function")
it.cppCompiler.args.add("-Wno-deprecated-enum-enum-conversion")
it.cppCompiler.args.add("-Wno-sign-compare")
it.cppCompiler.args.remove("-permissive")
it.cppCompiler.args.add("-fpermissive")
it.cppCompiler.args.add("-Wno-uninitialized")
it.cppCompiler.args.add("-Wno-missing-braces")
it.cppCompiler.args.add("-Wno-null-conversion")
it.cppCompiler.args.add("-Wno-unused-but-set-variable")
Expand All @@ -111,17 +109,15 @@ nativeUtils.platformConfigs.each {
it.cCompiler.args.add("-Wno-unused-variable")
it.cCompiler.args.add("-Wno-unused-function")
it.cCompiler.args.add("-Wno-sign-compare")
it.cCompiler.args.add("-Wno-deprecated-declarations")
it.cppCompiler.args.add("-Wno-missing-field-initializers")
it.cppCompiler.args.remove("-pedantic")
it.cppCompiler.args.add("-Wno-unused-variable")
it.cppCompiler.args.add("-Wno-unused-function")
it.cppCompiler.args.add("-Wno-deprecated-enum-enum-conversion")
it.cppCompiler.args.add("-Wno-sign-compare")
it.cppCompiler.args.add("-Wno-deprecated-declarations")
it.cppCompiler.args.add("-Wno-deprecated-enum-enum-conversion")
it.cppCompiler.args.remove("-permissive")
it.cppCompiler.args.add("-fpermissive")
it.cppCompiler.args.add("-Wno-maybe-uninitialized")
}
}
def testResources = "\"$rootDir/wpical/src/main/native/resources\"".replace("\\", "/")
Expand Down Expand Up @@ -172,16 +168,12 @@ model {
} else {
it.cppCompiler.define('GLOG_DEPRECATED', '[[deprecated]]')
}
if (it.targetPlatform.name == nativeUtils.wpi.platforms.windowsarm64) {
it.linker.args << '/alternatename:__imp___std_init_once_complete=__imp_InitOnceComplete'
it.linker.args << '/alternatename:__imp___std_init_once_begin_initialize=__imp_InitOnceBeginInitialize'
}
if (it.targetPlatform.operatingSystem.isWindows()) {
// Comdlg32.lib is needed for GetSaveFileNameA
// dbghelp.lib is needed for glog functions
it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib' << 'Comdlg32.lib' << 'dbghelp.lib'
} else if (it.targetPlatform.operatingSystem.isMacOsX()) {
it.linker.args << '-framework' << 'Metal' << '-framework' << 'MetalKit' << '-framework' << 'Cocoa' << '-framework' << 'IOKit' << '-framework' << 'CoreFoundation' << '-framework' << 'CoreVideo' << '-framework' << 'QuartzCore'
it.linker.args << '-framework' << 'Metal' << '-framework' << 'MetalKit' << '-framework' << 'Cocoa' << '-framework' << 'IOKit' << '-framework' << 'CoreFoundation' << '-framework' << 'CoreVideo' << '-framework' << 'QuartzCore' << '-framework' << 'Accelerate'
} else {
it.linker.args << '-lX11' << "-lgfortran"
if (it.targetPlatform.name.startsWith('linuxarm')) {
Expand Down Expand Up @@ -223,6 +215,11 @@ model {
nativeUtils.useRequiredLibrary(it, 'opencv_static')
it.cppCompiler.define('PROJECT_ROOT_PATH', testResources)
it.cppCompiler.define 'GLOG_USE_GLOG_EXPORT'
if (it.targetPlatform.name == nativeUtils.wpi.platforms.windowsarm64) {
// https://developercommunity.visualstudio.com/t/-imp-std-init-once-complete-unresolved-external-sy/1684365#T-N10041864
it.linker.args << '/alternatename:__imp___std_init_once_complete=__imp_InitOnceComplete'
it.linker.args << '/alternatename:__imp___std_init_once_begin_initialize=__imp_InitOnceBeginInitialize'
}
if (it.targetPlatform.operatingSystem.isWindows()) {
it.cppCompiler.define('GLOG_DEPRECATED', '__declspec(deprecated)')
} else {
Expand All @@ -234,9 +231,10 @@ model {
it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib'
// Comdlg32.lib is needed for GetSaveFileNameA
// dbghelp.lib is needed for glog functions
// advapi32.lib is needed for __imp_RegDeleteKeyA and other __imp_Reg functions for icvLoadWindowPos and the save variant
it.linker.args << 'advapi32.lib' << 'Comdlg32.lib' << 'dbghelp.lib'
} else if (it.targetPlatform.operatingSystem.isMacOsX()) {
it.linker.args << '-framework' << 'Metal' << '-framework' << 'MetalKit' << '-framework' << 'Cocoa' << '-framework' << 'IOKit' << '-framework' << 'CoreFoundation' << '-framework' << 'CoreVideo' << '-framework' << 'QuartzCore'
it.linker.args << '-framework' << 'Metal' << '-framework' << 'MetalKit' << '-framework' << 'Cocoa' << '-framework' << 'IOKit' << '-framework' << 'CoreFoundation' << '-framework' << 'CoreVideo' << '-framework' << 'QuartzCore' << '-framework' << 'Accelerate'
} else {
it.linker.args << '-lX11' << '-lgfortran'
if (it.targetPlatform.name.startsWith('linuxarm')) {
Expand Down
Loading

0 comments on commit a3f3575

Please sign in to comment.