-
Notifications
You must be signed in to change notification settings - Fork 538
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
|
@@ -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 | ||
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a new line missing here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line missing |
This file was deleted.
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}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line missing |
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line missing |
There was a problem hiding this comment.
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.