Skip to content

Commit 33feef4

Browse files
committed
build as sub components with defined exports
1 parent e5e2341 commit 33feef4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+600
-330
lines changed

CMakeLists.txt

Lines changed: 17 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
cmake_minimum_required(VERSION 3.1)
1+
cmake_minimum_required(VERSION 3.5)
22
project(apriltag VERSION 3.3.0 LANGUAGES C CXX)
33

4+
if (MSVC)
5+
add_compile_definitions("_CRT_SECURE_NO_WARNINGS")
6+
endif()
7+
48
if(POLICY CMP0077)
59
cmake_policy(SET CMP0077 NEW)
610
endif()
11+
712
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
13+
option(BUILD_EXAMPLES "Build example binaries" ON)
814
option(ASAN "Use AddressSanitizer for debug builds to detect memory issues" OFF)
915

1016
if (ASAN)
@@ -38,150 +44,20 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
3844
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
3945
endif()
4046

41-
aux_source_directory(common COMMON_SRC)
42-
set(APRILTAG_SRCS apriltag.c apriltag_pose.c apriltag_quad_thresh.c)
43-
44-
# Library
45-
file(GLOB TAG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tag*.c)
46-
add_library(${PROJECT_NAME} ${APRILTAG_SRCS} ${COMMON_SRC} ${TAG_FILES})
47-
48-
if (MSVC)
49-
add_compile_definitions("_CRT_SECURE_NO_WARNINGS")
50-
else()
51-
find_package(Threads REQUIRED)
52-
target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads m)
53-
endif()
54-
55-
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 3 VERSION ${PROJECT_VERSION})
56-
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "d")
57-
58-
include(GNUInstallDirs)
59-
target_include_directories(${PROJECT_NAME} PUBLIC
60-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>"
61-
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
62-
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>/apriltag")
63-
64-
65-
# install header file hierarchy
66-
file(GLOB HEADER_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h common/*.h)
67-
list(REMOVE_ITEM HEADER_FILES apriltag_detect.docstring.h apriltag_py_type.docstring.h)
68-
69-
foreach(HEADER ${HEADER_FILES})
70-
string(REGEX MATCH "(.*)[/\\]" DIR ${HEADER})
71-
install(FILES ${HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${DIR})
72-
endforeach()
73-
74-
# export library
75-
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
76-
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
77-
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
78-
set(targets_export_name "${PROJECT_NAME}Targets")
79-
set(config_install_dir "share/${PROJECT_NAME}/cmake")
80-
81-
# Include module with fuction 'write_basic_package_version_file'
82-
include(CMakePackageConfigHelpers)
83-
84-
# Configure '<PROJECT-NAME>Config.cmake'
85-
# Use variables:
86-
# * targets_export_name
87-
# * PROJECT_NAME
88-
configure_package_config_file(
89-
"CMake/apriltagConfig.cmake.in"
90-
"${project_config}"
91-
INSTALL_DESTINATION "${config_install_dir}"
92-
)
47+
# build main library
48+
add_subdirectory(libs/apriltag)
9349

94-
# Configure '<PROJECT-NAME>ConfigVersion.cmake'
95-
# Note: PROJECT_VERSION is used as a VERSION
96-
write_basic_package_version_file("${version_config}" COMPATIBILITY SameMajorVersion)
97-
98-
99-
# install library
100-
install(TARGETS ${PROJECT_NAME} EXPORT ${targets_export_name}
101-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
102-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
103-
)
104-
105-
install(EXPORT ${targets_export_name}
106-
NAMESPACE apriltag::
107-
DESTINATION ${config_install_dir})
108-
109-
install(FILES ${project_config} ${version_config} DESTINATION ${config_install_dir})
110-
111-
export(TARGETS apriltag
112-
NAMESPACE apriltag::
113-
FILE ${generated_dir}/${targets_export_name}.cmake)
114-
115-
116-
# install pkgconfig file
117-
configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
118-
install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
119-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
120-
121-
122-
# Python wrapper
50+
## Python wrapper
12351
include(CMakeDependentOption)
12452
cmake_dependent_option(BUILD_PYTHON_WRAPPER "Builds Python wrapper" ON BUILD_SHARED_LIBS OFF)
12553

12654
if(BUILD_PYTHON_WRAPPER)
127-
SET(Python_ADDITIONAL_VERSIONS 3)
128-
find_package(PythonLibs)
129-
execute_process(COMMAND which python3 OUTPUT_QUIET RESULT_VARIABLE Python3_NOT_FOUND)
130-
execute_process(COMMAND python3 -c "import numpy" RESULT_VARIABLE Numpy_NOT_FOUND)
131-
endif(BUILD_PYTHON_WRAPPER)
132-
133-
if (NOT Python3_NOT_FOUND AND NOT Numpy_NOT_FOUND AND PYTHONLIBS_FOUND AND BUILD_PYTHON_WRAPPER)
134-
# TODO deal with both python2/3
135-
execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/python_build_flags.py OUTPUT_VARIABLE PY_OUT)
136-
set(PY_VARS CFLAGS LDFLAGS LINKER EXT_SUFFIX)
137-
cmake_parse_arguments(PY "" "${PY_VARS}" "" ${PY_OUT})
138-
separate_arguments(PY_CFLAGS)
139-
list(REMOVE_ITEM PY_CFLAGS -flto)
140-
separate_arguments(PY_LDFLAGS)
141-
142-
foreach(X detect py_type)
143-
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/apriltag_${X}.docstring.h
144-
COMMAND < ${CMAKE_CURRENT_SOURCE_DIR}/apriltag_${X}.docstring sed 's/\"/\\\\\"/g\; s/^/\"/\; s/$$/\\\\n\"/\;' > apriltag_${X}.docstring.h
145-
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
146-
endforeach()
147-
148-
add_custom_command(OUTPUT apriltag_pywrap.o
149-
COMMAND ${CMAKE_C_COMPILER} ${PY_CFLAGS} -I${PROJECT_BINARY_DIR} -c -o apriltag_pywrap.o ${CMAKE_CURRENT_SOURCE_DIR}/apriltag_pywrap.c
150-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/apriltag_pywrap.c ${PROJECT_BINARY_DIR}/apriltag_detect.docstring.h ${PROJECT_BINARY_DIR}/apriltag_py_type.docstring.h)
151-
add_custom_command(OUTPUT apriltag${PY_EXT_SUFFIX}
152-
COMMAND ${PY_LINKER} ${PY_LDFLAGS} -Wl,-rpath,lib apriltag_pywrap.o $<TARGET_FILE:apriltag> -o apriltag${PY_EXT_SUFFIX}
153-
DEPENDS ${PROJECT_NAME} apriltag_pywrap.o)
154-
add_custom_target(apriltag_python ALL
155-
DEPENDS apriltag${PY_EXT_SUFFIX})
156-
157-
execute_process(COMMAND python3 -m site --user-site OUTPUT_VARIABLE PY_DEST)
158-
string(STRIP ${PY_DEST} PY_DEST)
159-
install(FILES ${PROJECT_BINARY_DIR}/apriltag${PY_EXT_SUFFIX} DESTINATION ${PY_DEST})
160-
endif (NOT Python3_NOT_FOUND AND NOT Numpy_NOT_FOUND AND PYTHONLIBS_FOUND AND BUILD_PYTHON_WRAPPER)
55+
# build python wrapper
56+
add_subdirectory(libs/apriltag_python)
57+
endif()
16158

16259
# Examples
163-
# apriltag_demo
164-
add_executable(apriltag_demo example/apriltag_demo.c)
165-
target_link_libraries(apriltag_demo ${PROJECT_NAME})
166-
167-
# opencv_demo
168-
set(_OpenCV_REQUIRED_COMPONENTS core imgproc videoio highgui)
169-
find_package(OpenCV COMPONENTS ${_OpenCV_REQUIRED_COMPONENTS} QUIET CONFIG)
170-
if(OpenCV_FOUND)
171-
# NB: contrib required for TickMeter in OpenCV 2.4. This is only required for 16.04 backwards compatibility and can be removed in the future.
172-
# If we add it to the find_package initially, the demo won't build for newer OpenCV versions
173-
if(OpenCV_VERSION VERSION_LESS "3.0.0")
174-
list(APPEND _OpenCV_REQUIRED_COMPONENTS contrib)
175-
find_package(OpenCV COMPONENTS ${_OpenCV_REQUIRED_COMPONENTS} CONFIG)
176-
endif()
177-
178-
add_executable(opencv_demo example/opencv_demo.cc)
179-
target_link_libraries(opencv_demo apriltag ${OpenCV_LIBRARIES})
180-
set_target_properties(opencv_demo PROPERTIES CXX_STANDARD 11)
181-
install(TARGETS opencv_demo RUNTIME DESTINATION bin)
182-
else()
183-
message(STATUS "OpenCV not found: Not building demo")
184-
endif(OpenCV_FOUND)
185-
186-
# install example programs
187-
install(TARGETS apriltag_demo RUNTIME DESTINATION bin)
60+
if(BUILD_EXAMPLES)
61+
# build examples
62+
add_subdirectory(example)
63+
endif()

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ AR = ar
66
CFLAGS = -std=gnu99 -fPIC -Wall -Wno-unused-parameter -Wno-unused-function
77
CFLAGS += -I. -O3 -fno-strict-overflow
88

9+
ROOT := $(shell pwd)
10+
APRILTAG_DIR := $(ROOT)/libs/apriltag
11+
APRILTAG_SRC_DIR := $(APRILTAG_DIR)/src
12+
913
#APRILTAG_SRCS := $(shell ls *.c common/*.c)
10-
APRILTAG_SRCS := apriltag.c apriltag_pose.c apriltag_quad_thresh.c common/g2d.c common/getopt.c common/homography.c common/image_u8.c common/image_u8x3.c common/image_u8x4.c common/matd.c common/pam.c common/pjpeg.c common/pjpeg-idct.c common/pnm.c common/string_util.c common/svd22.c common/time_util.c common/unionfind.c common/workerpool.c common/zarray.c common/zhash.c common/zmaxheap.c tag16h5.c tag25h9.c tag36h11.c tagCircle21h7.c tagCircle49h12.c tagCustom48h12.c tagStandard41h12.c tagStandard52h13.c
11-
APRILTAG_HEADERS := $(shell ls *.h common/*.h)
14+
APRILTAG_SRCS := $(APRILTAG_SRC_DIR)/apriltag.c $(APRILTAG_SRC_DIR)/apriltag_pose.c $(APRILTAG_SRC_DIR)/apriltag_quad_thresh.c $(APRILTAG_SRC_DIR)/common/g2d.c $(APRILTAG_SRC_DIR)/common/getopt.c $(APRILTAG_SRC_DIR)/common/homography.c $(APRILTAG_SRC_DIR)/common/image_u8.c $(APRILTAG_SRC_DIR)/common/image_u8x3.c $(APRILTAG_SRC_DIR)/common/image_u8x4.c $(APRILTAG_SRC_DIR)/common/matd.c $(APRILTAG_SRC_DIR)/common/pam.c $(APRILTAG_SRC_DIR)/common/pjpeg.c $(APRILTAG_SRC_DIR)/common/pjpeg-idct.c $(APRILTAG_SRC_DIR)/common/pnm.c $(APRILTAG_SRC_DIR)/common/string_util.c $(APRILTAG_SRC_DIR)/common/svd22.c $(APRILTAG_SRC_DIR)/common/time_util.c $(APRILTAG_SRC_DIR)/common/workerpool.c $(APRILTAG_SRC_DIR)/common/zarray.c $(APRILTAG_SRC_DIR)/common/zhash.c $(APRILTAG_SRC_DIR)/common/zmaxheap.c $(APRILTAG_SRC_DIR)/tag16h5.c $(APRILTAG_SRC_DIR)/tag25h9.c $(APRILTAG_SRC_DIR)/tag36h11.c $(APRILTAG_SRC_DIR)/tagCircle21h7.c $(APRILTAG_SRC_DIR)/tagCircle49h12.c $(APRILTAG_SRC_DIR)/tagCustom48h12.c $(APRILTAG_SRC_DIR)/tagStandard41h12.c $(APRILTAG_SRC_DIR)/tagStandard52h13.c
15+
APRILTAG_HEADERS := $(shell ls $(APRILTAG_DIR)/include/apriltag/*.h $(APRILTAG_DIR)/include/apriltag/common/*.h)
1216
APRILTAG_OBJS := $(APRILTAG_SRCS:%.c=%.o)
1317
TARGETS := libapriltag.a libapriltag.so
1418

@@ -20,7 +24,7 @@ all: $(TARGETS)
2024
install: libapriltag.so
2125
@chmod +x install.sh
2226
@./install.sh $(PREFIX)/lib libapriltag.so
23-
@./install.sh $(PREFIX)/include/apriltag $(APRILTAG_HEADERS)
27+
@./install.sh $(PREFIX)/ $(APRILTAG_HEADERS)
2428
@ldconfig
2529

2630
libapriltag.a: $(APRILTAG_OBJS)
@@ -37,5 +41,5 @@ libapriltag.so: $(APRILTAG_OBJS)
3741

3842
.PHONY: clean
3943
clean:
40-
@rm -rf *.o common/*.o $(TARGETS)
44+
@rm -rf $(APRILTAG_SRC_DIR)/*.o $(APRILTAG_SRC_DIR)/common/*.o $(TARGETS)
4145
@$(MAKE) -C example clean

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ AprilTag is the subject of the following papers.
1515
[Flexible Layouts for Fiducial Tags](https://april.eecs.umich.edu/papers/details.php?name=krogius2019iros)
1616

1717

18-
1918
Usage
2019
=====
2120
[User Guide](https://github.com/AprilRobotics/apriltag/wiki/AprilTag-User-Guide)
@@ -25,7 +24,7 @@ Install
2524

2625
Officially only Linux operating systems are supported, although users have had success installing on Windows too.
2726

28-
The default installation will place headers in /usr/local/include and shared library in /usr/local/lib. It also installs a pkg-config script into /usr/local/lib/pkgconfig and will install a python wrapper if python3 is installed.
27+
The default installation will place headers in /usr/local/include and shared libraries in /usr/local/lib. It also installs a pkg-config script into /usr/local/lib/pkgconfig and will install a python wrapper if python3 is installed.
2928

3029
## cmake
3130
If you have CMake installed, then do:

common/unionfind.c

Lines changed: 0 additions & 30 deletions
This file was deleted.

example/CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## Build Examples
2+
3+
### Note
4+
# apriltag targets are in the same build tree so can be used directly without installation
5+
# or including the build-generated apriltagsTargets.cmake file
6+
#
7+
# Typical usage would be to build and *install* the apriltag libraries and then, for your project use
8+
# find_package(apriltag REQUIRED)
9+
# target_link_libraries(my_application PRIVATE apriltag::detector apriltag::utils apriltag::tags)
10+
11+
# apriltag_demo
12+
add_executable(apriltag_demo apriltag_demo.c)
13+
target_link_libraries(apriltag_demo PRIVATE apriltag-detector apriltag-utils apriltag-tags)
14+
15+
set(_OpenCV_REQUIRED_COMPONENTS core imgproc videoio highgui)
16+
find_package(OpenCV COMPONENTS ${_OpenCV_REQUIRED_COMPONENTS} QUIET CONFIG)
17+
if(OpenCV_FOUND)
18+
# NB: contrib required for TickMeter in OpenCV 2.4. This is only required for 16.04 backwards compatibility and can be removed in the future.
19+
# If we add it to the find_package initially, the demo won't build for newer OpenCV versions
20+
if(OpenCV_VERSION VERSION_LESS "3.0.0")
21+
list(APPEND _OpenCV_REQUIRED_COMPONENTS contrib)
22+
find_package(OpenCV COMPONENTS ${_OpenCV_REQUIRED_COMPONENTS} CONFIG)
23+
endif()
24+
25+
add_executable(opencv_demo opencv_demo.cc)
26+
target_link_libraries(opencv_demo apriltag-detector apriltag-tags apriltag-utils ${OpenCV_LIBRARIES})
27+
set_target_properties(opencv_demo PROPERTIES CXX_STANDARD 11)
28+
install(TARGETS opencv_demo RUNTIME DESTINATION bin)
29+
else()
30+
message(STATUS "OpenCV not found: Not building demo")
31+
endif(OpenCV_FOUND)
32+
33+
# install example programs
34+
install(TARGETS apriltag_demo RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

example/apriltag_demo.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ either expressed or implied, of the Regents of The University of Michigan.
4141
#include <unistd.h>
4242
#endif
4343

44-
#include "apriltag.h"
45-
#include "tag36h11.h"
46-
#include "tag25h9.h"
47-
#include "tag16h5.h"
48-
#include "tagCircle21h7.h"
49-
#include "tagCircle49h12.h"
50-
#include "tagCustom48h12.h"
51-
#include "tagStandard41h12.h"
52-
#include "tagStandard52h13.h"
53-
54-
#include "common/getopt.h"
55-
#include "common/image_u8.h"
56-
#include "common/pjpeg.h"
57-
#include "common/zarray.h"
44+
#include "apriltag/apriltag.h"
45+
#include "apriltag/tag36h11.h"
46+
#include "apriltag/tag25h9.h"
47+
#include "apriltag/tag16h5.h"
48+
#include "apriltag/tagCircle21h7.h"
49+
#include "apriltag/tagCircle49h12.h"
50+
#include "apriltag/tagCustom48h12.h"
51+
#include "apriltag/tagStandard41h12.h"
52+
#include "apriltag/tagStandard52h13.h"
53+
54+
#include "apriltag/common/getopt.h"
55+
#include "apriltag/common/image_u8.h"
56+
#include "apriltag/common/pjpeg.h"
57+
#include "apriltag/common/zarray.h"
5858

5959
#define HAMM_HIST_MAX 10
6060

example/opencv_demo.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ either expressed or implied, of the Regents of The University of Michigan.
3131
#include "opencv2/opencv.hpp"
3232

3333
extern "C" {
34-
#include "apriltag.h"
35-
#include "tag36h11.h"
36-
#include "tag25h9.h"
37-
#include "tag16h5.h"
38-
#include "tagCircle21h7.h"
39-
#include "tagCircle49h12.h"
40-
#include "tagCustom48h12.h"
41-
#include "tagStandard41h12.h"
42-
#include "tagStandard52h13.h"
43-
#include "common/getopt.h"
34+
#include "apriltag/apriltag.h"
35+
#include "apriltag/tag36h11.h"
36+
#include "apriltag/tag25h9.h"
37+
#include "apriltag/tag16h5.h"
38+
#include "apriltag/tagCircle21h7.h"
39+
#include "apriltag/tagCircle49h12.h"
40+
#include "apriltag/tagCustom48h12.h"
41+
#include "apriltag/tagStandard41h12.h"
42+
#include "apriltag/tagStandard52h13.h"
43+
#include "apriltag/common/getopt.h"
4444
}
4545

4646
using namespace std;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Helper Functions
2+
function(set_apriltag_lib_property_defaults target_name)
3+
set_target_properties(${target_name} PROPERTIES SOVERSION 3 VERSION ${PROJECT_VERSION})
4+
set_target_properties(${target_name} PROPERTIES DEBUG_POSTFIX "d")
5+
set_target_properties(${target_name} PROPERTIES POSITION_INDEPENDENT_CODE ON)
6+
endfunction()
7+
8+
function(set_apriltag_named_exports_only target_name)
9+
set_target_properties(${target_name} PROPERTIES
10+
C_VISIBILITY_PRESET hidden
11+
CXX_VISIBILITY_PRESET hidden
12+
VISIBILITY_INLINES_HIDDEN ON
13+
WINDOWS_EXPORT_ALL_SYMBOLS OFF
14+
# multiple libs sharing same auto-generated header so override default to use apriltag_EXPORTS
15+
DEFINE_SYMBOL apriltag_EXPORTS
16+
)
17+
endfunction()
18+
19+
function(set_apriltag_export_all target_name)
20+
set_target_properties(${target_name} PROPERTIES
21+
C_VISIBILITY_PRESET default
22+
CXX_VISIBILITY_PRESET default
23+
VISIBILITY_INLINES_HIDDEN OFF
24+
WINDOWS_EXPORT_ALL_SYMBOLS ON
25+
# multiple libs sharing same auto-generated header so override default to use apriltag_EXPORTS
26+
DEFINE_SYMBOL apriltag_EXPORTS
27+
)
28+
endfunction()

0 commit comments

Comments
 (0)