Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build as sub components with defined exports #264

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ros_workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ jobs:
submodules: recursive

- name: Setup ROS environment
uses: ros-tooling/setup-ros@v0.3
uses: ros-tooling/setup-ros@v0.4

- name: ROS 1 CI Action
if: ${{ matrix.ros_version == 1 }}
Expand Down
158 changes: 17 additions & 141 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.5)
project(apriltag VERSION 3.3.0 LANGUAGES C CXX)

if (MSVC)
add_compile_definitions("_CRT_SECURE_NO_WARNINGS")
endif()

if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()

option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(BUILD_EXAMPLES "Build example binaries" ON)
option(ASAN "Use AddressSanitizer for debug builds to detect memory issues" OFF)

if (ASAN)
Expand Down Expand Up @@ -38,150 +44,20 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

aux_source_directory(common COMMON_SRC)
set(APRILTAG_SRCS apriltag.c apriltag_pose.c apriltag_quad_thresh.c)

# Library
file(GLOB TAG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tag*.c)
add_library(${PROJECT_NAME} ${APRILTAG_SRCS} ${COMMON_SRC} ${TAG_FILES})

if (MSVC)
add_compile_definitions("_CRT_SECURE_NO_WARNINGS")
else()
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads m)
endif()

set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 3 VERSION ${PROJECT_VERSION})
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "d")

include(GNUInstallDirs)
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>/apriltag")


# install header file hierarchy
file(GLOB HEADER_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h common/*.h)
list(REMOVE_ITEM HEADER_FILES apriltag_detect.docstring.h apriltag_py_type.docstring.h)

foreach(HEADER ${HEADER_FILES})
string(REGEX MATCH "(.*)[/\\]" DIR ${HEADER})
install(FILES ${HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${DIR})
endforeach()

# export library
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(targets_export_name "${PROJECT_NAME}Targets")
set(config_install_dir "share/${PROJECT_NAME}/cmake")

# Include module with fuction 'write_basic_package_version_file'
include(CMakePackageConfigHelpers)

# Configure '<PROJECT-NAME>Config.cmake'
# Use variables:
# * targets_export_name
# * PROJECT_NAME
configure_package_config_file(
"CMake/apriltagConfig.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
# build main library
add_subdirectory(libs/apriltag)

# Configure '<PROJECT-NAME>ConfigVersion.cmake'
# Note: PROJECT_VERSION is used as a VERSION
write_basic_package_version_file("${version_config}" COMPATIBILITY SameMajorVersion)


# install library
install(TARGETS ${PROJECT_NAME} EXPORT ${targets_export_name}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(EXPORT ${targets_export_name}
NAMESPACE apriltag::
DESTINATION ${config_install_dir})

install(FILES ${project_config} ${version_config} DESTINATION ${config_install_dir})

export(TARGETS apriltag
NAMESPACE apriltag::
FILE ${generated_dir}/${targets_export_name}.cmake)


# install pkgconfig file
configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")


# Python wrapper
## Python wrapper
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a single # just like in the other cases.

include(CMakeDependentOption)
cmake_dependent_option(BUILD_PYTHON_WRAPPER "Builds Python wrapper" ON BUILD_SHARED_LIBS OFF)

if(BUILD_PYTHON_WRAPPER)
SET(Python_ADDITIONAL_VERSIONS 3)
find_package(PythonLibs)
execute_process(COMMAND which python3 OUTPUT_QUIET RESULT_VARIABLE Python3_NOT_FOUND)
execute_process(COMMAND python3 -c "import numpy" RESULT_VARIABLE Numpy_NOT_FOUND)
endif(BUILD_PYTHON_WRAPPER)

if (NOT Python3_NOT_FOUND AND NOT Numpy_NOT_FOUND AND PYTHONLIBS_FOUND AND BUILD_PYTHON_WRAPPER)
# TODO deal with both python2/3
execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/python_build_flags.py OUTPUT_VARIABLE PY_OUT)
set(PY_VARS CFLAGS LDFLAGS LINKER EXT_SUFFIX)
cmake_parse_arguments(PY "" "${PY_VARS}" "" ${PY_OUT})
separate_arguments(PY_CFLAGS)
list(REMOVE_ITEM PY_CFLAGS -flto)
separate_arguments(PY_LDFLAGS)

foreach(X detect py_type)
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/apriltag_${X}.docstring.h
COMMAND < ${CMAKE_CURRENT_SOURCE_DIR}/apriltag_${X}.docstring sed 's/\"/\\\\\"/g\; s/^/\"/\; s/$$/\\\\n\"/\;' > apriltag_${X}.docstring.h
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
endforeach()

add_custom_command(OUTPUT apriltag_pywrap.o
COMMAND ${CMAKE_C_COMPILER} ${PY_CFLAGS} -I${PROJECT_BINARY_DIR} -c -o apriltag_pywrap.o ${CMAKE_CURRENT_SOURCE_DIR}/apriltag_pywrap.c
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/apriltag_pywrap.c ${PROJECT_BINARY_DIR}/apriltag_detect.docstring.h ${PROJECT_BINARY_DIR}/apriltag_py_type.docstring.h)
add_custom_command(OUTPUT apriltag${PY_EXT_SUFFIX}
COMMAND ${PY_LINKER} ${PY_LDFLAGS} -Wl,-rpath,lib apriltag_pywrap.o $<TARGET_FILE:apriltag> -o apriltag${PY_EXT_SUFFIX}
DEPENDS ${PROJECT_NAME} apriltag_pywrap.o)
add_custom_target(apriltag_python ALL
DEPENDS apriltag${PY_EXT_SUFFIX})

execute_process(COMMAND python3 -m site --user-site OUTPUT_VARIABLE PY_DEST)
string(STRIP ${PY_DEST} PY_DEST)
install(FILES ${PROJECT_BINARY_DIR}/apriltag${PY_EXT_SUFFIX} DESTINATION ${PY_DEST})
endif (NOT Python3_NOT_FOUND AND NOT Numpy_NOT_FOUND AND PYTHONLIBS_FOUND AND BUILD_PYTHON_WRAPPER)
# build python wrapper
add_subdirectory(libs/apriltag_python)
endif()

# Examples
# apriltag_demo
add_executable(apriltag_demo example/apriltag_demo.c)
target_link_libraries(apriltag_demo ${PROJECT_NAME})

# opencv_demo
set(_OpenCV_REQUIRED_COMPONENTS core imgproc videoio highgui)
find_package(OpenCV COMPONENTS ${_OpenCV_REQUIRED_COMPONENTS} QUIET CONFIG)
if(OpenCV_FOUND)
# 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.
# If we add it to the find_package initially, the demo won't build for newer OpenCV versions
if(OpenCV_VERSION VERSION_LESS "3.0.0")
list(APPEND _OpenCV_REQUIRED_COMPONENTS contrib)
find_package(OpenCV COMPONENTS ${_OpenCV_REQUIRED_COMPONENTS} CONFIG)
endif()

add_executable(opencv_demo example/opencv_demo.cc)
target_link_libraries(opencv_demo apriltag ${OpenCV_LIBRARIES})
set_target_properties(opencv_demo PROPERTIES CXX_STANDARD 11)
install(TARGETS opencv_demo RUNTIME DESTINATION bin)
else()
message(STATUS "OpenCV not found: Not building demo")
endif(OpenCV_FOUND)

# install example programs
install(TARGETS apriltag_demo RUNTIME DESTINATION bin)
if(BUILD_EXAMPLES)
# build examples
add_subdirectory(example)
endif()
Copy link
Collaborator

@christian-rauch christian-rauch Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a new line missing here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line missing

12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ AR = ar
CFLAGS = -std=gnu99 -fPIC -Wall -Wno-unused-parameter -Wno-unused-function
CFLAGS += -I. -O3 -fno-strict-overflow

ROOT := $(shell pwd)
APRILTAG_DIR := $(ROOT)/libs/apriltag
APRILTAG_SRC_DIR := $(APRILTAG_DIR)/src

#APRILTAG_SRCS := $(shell ls *.c common/*.c)
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
APRILTAG_HEADERS := $(shell ls *.h common/*.h)
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
APRILTAG_HEADERS := $(shell ls $(APRILTAG_DIR)/include/apriltag/*.h $(APRILTAG_DIR)/include/apriltag/common/*.h)
APRILTAG_OBJS := $(APRILTAG_SRCS:%.c=%.o)
TARGETS := libapriltag.a libapriltag.so

Expand All @@ -20,7 +24,7 @@ all: $(TARGETS)
install: libapriltag.so
@chmod +x install.sh
@./install.sh $(PREFIX)/lib libapriltag.so
@./install.sh $(PREFIX)/include/apriltag $(APRILTAG_HEADERS)
@./install.sh $(PREFIX)/ $(APRILTAG_HEADERS)
@ldconfig

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

.PHONY: clean
clean:
@rm -rf *.o common/*.o $(TARGETS)
@rm -rf $(APRILTAG_SRC_DIR)/*.o $(APRILTAG_SRC_DIR)/common/*.o $(TARGETS)
@$(MAKE) -C example clean
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ AprilTag is the subject of the following papers.
[Flexible Layouts for Fiducial Tags](https://april.eecs.umich.edu/papers/details.php?name=krogius2019iros)



Usage
=====
[User Guide](https://github.com/AprilRobotics/apriltag/wiki/AprilTag-User-Guide)
Expand All @@ -25,7 +24,7 @@ Install

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

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.
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.

## cmake
If you have CMake installed, then do:
Expand Down
30 changes: 0 additions & 30 deletions common/unionfind.c

This file was deleted.

34 changes: 34 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Build Examples

### Note
# apriltag targets are in the same build tree so can be used directly without installation
# or including the build-generated apriltagsTargets.cmake file
#
# Typical usage would be to build and *install* the apriltag libraries and then, for your project use
# find_package(apriltag REQUIRED)
# target_link_libraries(my_application PRIVATE apriltag::detector apriltag::utils apriltag::tags)

# apriltag_demo
add_executable(apriltag_demo apriltag_demo.c)
target_link_libraries(apriltag_demo PRIVATE apriltag-detector apriltag-utils apriltag-tags)

set(_OpenCV_REQUIRED_COMPONENTS core imgproc videoio highgui)
find_package(OpenCV COMPONENTS ${_OpenCV_REQUIRED_COMPONENTS} QUIET CONFIG)
if(OpenCV_FOUND)
# 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.
# If we add it to the find_package initially, the demo won't build for newer OpenCV versions
if(OpenCV_VERSION VERSION_LESS "3.0.0")
list(APPEND _OpenCV_REQUIRED_COMPONENTS contrib)
find_package(OpenCV COMPONENTS ${_OpenCV_REQUIRED_COMPONENTS} CONFIG)
endif()

add_executable(opencv_demo opencv_demo.cc)
target_link_libraries(opencv_demo apriltag-detector apriltag-tags apriltag-utils ${OpenCV_LIBRARIES})
set_target_properties(opencv_demo PROPERTIES CXX_STANDARD 11)
install(TARGETS opencv_demo RUNTIME DESTINATION bin)
else()
message(STATUS "OpenCV not found: Not building demo")
endif(OpenCV_FOUND)

# install example programs
install(TARGETS apriltag_demo RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line missing

28 changes: 14 additions & 14 deletions example/apriltag_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ either expressed or implied, of the Regents of The University of Michigan.
#include <unistd.h>
#endif

#include "apriltag.h"
#include "tag36h11.h"
#include "tag25h9.h"
#include "tag16h5.h"
#include "tagCircle21h7.h"
#include "tagCircle49h12.h"
#include "tagCustom48h12.h"
#include "tagStandard41h12.h"
#include "tagStandard52h13.h"

#include "common/getopt.h"
#include "common/image_u8.h"
#include "common/pjpeg.h"
#include "common/zarray.h"
#include "apriltag/apriltag.h"
#include "apriltag/tag36h11.h"
#include "apriltag/tag25h9.h"
#include "apriltag/tag16h5.h"
#include "apriltag/tagCircle21h7.h"
#include "apriltag/tagCircle49h12.h"
#include "apriltag/tagCustom48h12.h"
#include "apriltag/tagStandard41h12.h"
#include "apriltag/tagStandard52h13.h"

#include "apriltag/common/getopt.h"
#include "apriltag/common/image_u8.h"
#include "apriltag/common/pjpeg.h"
#include "apriltag/common/zarray.h"

#define HAMM_HIST_MAX 10

Expand Down
20 changes: 10 additions & 10 deletions example/opencv_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ either expressed or implied, of the Regents of The University of Michigan.
#include "opencv2/opencv.hpp"

extern "C" {
#include "apriltag.h"
#include "tag36h11.h"
#include "tag25h9.h"
#include "tag16h5.h"
#include "tagCircle21h7.h"
#include "tagCircle49h12.h"
#include "tagCustom48h12.h"
#include "tagStandard41h12.h"
#include "tagStandard52h13.h"
#include "common/getopt.h"
#include "apriltag/apriltag.h"
#include "apriltag/tag36h11.h"
#include "apriltag/tag25h9.h"
#include "apriltag/tag16h5.h"
#include "apriltag/tagCircle21h7.h"
#include "apriltag/tagCircle49h12.h"
#include "apriltag/tagCustom48h12.h"
#include "apriltag/tagStandard41h12.h"
#include "apriltag/tagStandard52h13.h"
#include "apriltag/common/getopt.h"
}

using namespace std;
Expand Down
28 changes: 28 additions & 0 deletions libs/apriltag/CMake/apriltagHelperFunctions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Helper Functions
function(set_apriltag_lib_property_defaults target_name)
set_target_properties(${target_name} PROPERTIES SOVERSION 3 VERSION ${PROJECT_VERSION})
set_target_properties(${target_name} PROPERTIES DEBUG_POSTFIX "d")
set_target_properties(${target_name} PROPERTIES POSITION_INDEPENDENT_CODE ON)
endfunction()

function(set_apriltag_named_exports_only target_name)
set_target_properties(${target_name} PROPERTIES
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
WINDOWS_EXPORT_ALL_SYMBOLS OFF
# multiple libs sharing same auto-generated header so override default to use apriltag_EXPORTS
DEFINE_SYMBOL apriltag_EXPORTS
)
endfunction()

function(set_apriltag_export_all target_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a 1~2 line comment to each of the three functions to explain what they are doing?

set_target_properties(${target_name} PROPERTIES
C_VISIBILITY_PRESET default
CXX_VISIBILITY_PRESET default
VISIBILITY_INLINES_HIDDEN OFF
WINDOWS_EXPORT_ALL_SYMBOLS ON
# multiple libs sharing same auto-generated header so override default to use apriltag_EXPORTS
DEFINE_SYMBOL apriltag_EXPORTS
)
endfunction()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line missing

Loading