forked from PhotonVision/mrcal-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
104 lines (83 loc) · 3.16 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.18)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(mrcal LANGUAGES C CXX VERSION 1.0.0)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
# C++
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set (WITH_ASAN OFF)
if (WITH_ASAN)
add_compile_options(-fsanitize=address -g -Wall -fsanitize=undefined)
endif ()
find_package(JNI)
if (JNI_FOUND)
# Fixes odd AWT dependency
set (JNI_INCLUDE_DIRS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
endif()
set(OPENCV_YEAR "frc2024")
set(OPENCV_VERSION "4.8.0-2")
# also valid: windowsx86-64
# type can be "", "debug", "static", or "staticdebug"
set(OPENCV_TYPE "")
set(OPENCV_ARCH "windowsx86-64")
# Download opencv, and save the path
include(FetchContent)
FetchContent_Declare(
opencv_lib
URL https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-${OPENCV_ARCH}${OPENCV_TYPE}.zip
)
FetchContent_MakeAvailable(opencv_lib)
# download OpenCV headers
FetchContent_Declare(
opencv_header
URL https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-headers.zip
)
FetchContent_MakeAvailable(opencv_header)
# This probably doesn't work great with shared libraries, but I don't care about those right now
file(GLOB_RECURSE OPENCV_LIB_PATH
"${opencv_lib_SOURCE_DIR}/**/*.lib"
"${opencv_lib_SOURCE_DIR}/**/*.so*"
)
SET(OPENCV_INCLUDE_PATH ${opencv_header_SOURCE_DIR})
message("Depending on opencv ${OPENCV_LIB_PATH}")
set(
SRC
src/mrcal_wrapper.h
src/mrcal_wrapper.cpp
libdogleg/dogleg.c
mrcal/mrcal.c
mrcal/cahvore.cc
mrcal/poseutils-opencv.c
mrcal/poseutils-uses-autodiff.cc
mrcal/poseutils.c
mrcal/poseutils-opencv.c
mrcal/mrcal-opencv.c
mrcal/triangulation.cc
)
#ignore opencv spam
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-deprecated-enum-enum-conversion")
find_package(OpenCV REQUIRED)
# Gennerate minimath
find_package( Perl REQUIRED )
add_custom_target(
generate_minimath ALL
COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generate.pl > ${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generated.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generated.h
COMMENT "Generating minimath"
)
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
# Create shared library
add_library(mrcal STATIC ${SRC})
target_include_directories(mrcal SYSTEM PUBLIC ${JNI_INCLUDE_DIRS} ${OPENCV_INCLUDE_PATH} src mrcal libdogleg)
add_dependencies(mrcal generate_minimath)
IF (WIN32)
find_package(SuiteSparse CONFIG REQUIRED)
target_link_libraries(mrcal ${OpenCV_LIBS} SuiteSparse::amd SuiteSparse::cholmod)
ELSE()
target_link_libraries(mrcal ${OpenCV_LIBS} suitesparseconfig cholmod)
target_include_directories(mrcal PUBLIC "/usr/include/suitesparse")
ENDIF()
unset(OPENCV_ARCH CACHE) # Set by Actions usually