Skip to content

Commit

Permalink
Merge pull request #2 from ZhenshengLee/fix-compile-issue
Browse files Browse the repository at this point in the history
Fix compile issue #1.
  • Loading branch information
ZhenshengLee authored Aug 13, 2021
2 parents f4f6877 + 718f0c0 commit 3fa326b
Show file tree
Hide file tree
Showing 10 changed files with 897 additions and 4 deletions.
9 changes: 6 additions & 3 deletions cupoch_conversions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
cmake_minimum_required(VERSION 3.5.0)
project(cupoch_conversions)

find_package(gpuac_base REQUIRED)
# Add this repository's cmake modules to CMAKE_MODULE_PATH
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_LIST_DIR}/cmake)

include(ga_build_common)

find_package(ament_cmake REQUIRED)
find_package(ament_cmake_ros REQUIRED)

Expand Down Expand Up @@ -38,7 +42,6 @@ cuda_add_library(cupoch_conversions STATIC src/cupoch_conversions.cu)
ament_target_dependencies(cupoch_conversions
rclcpp
sensor_msgs
gpuac_base
urdfdom
)
target_include_directories(cupoch_conversions PRIVATE
Expand Down Expand Up @@ -74,4 +77,4 @@ ament_export_libraries(cupoch_conversions)
# ament_export_interfaces(export_${PROJECT_NAME})
ament_export_dependencies(rclcpp)

ament_package()
ament_package()
43 changes: 43 additions & 0 deletions cupoch_conversions/cmake/CudaComputeTargetFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Compute target flags macros by Anatoly Baksheev
#
# Usage in CmakeLists.txt:
# include(CudaComputeTargetFlags.cmake)
# APPEND_TARGET_ARCH_FLAGS()

#compute flags macros
MACRO(CUDA_COMPUTE_TARGET_FLAGS arch_bin arch_ptx cuda_nvcc_target_flags)
string(REGEX REPLACE "\\." "" ARCH_BIN_WITHOUT_DOTS "${${arch_bin}}")
string(REGEX REPLACE "\\." "" ARCH_PTX_WITHOUT_DOTS "${${arch_ptx}}")

set(cuda_computer_target_flags_temp "")

# Tell NVCC to add binaries for the specified GPUs
string(REGEX MATCHALL "[0-9()]+" ARCH_LIST "${ARCH_BIN_WITHOUT_DOTS}")
foreach(ARCH IN LISTS ARCH_LIST)
if (ARCH MATCHES "([0-9]+)\\(([0-9]+)\\)")
# User explicitly specified PTX for the concrete BIN
set(cuda_computer_target_flags_temp ${cuda_computer_target_flags_temp} -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})
else()
# User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN
set(cuda_computer_target_flags_temp ${cuda_computer_target_flags_temp} -gencode arch=compute_${ARCH},code=sm_${ARCH})
endif()
endforeach()

# Tell NVCC to add PTX intermediate code for the specified architectures
string(REGEX MATCHALL "[0-9]+" ARCH_LIST "${ARCH_PTX_WITHOUT_DOTS}")
foreach(ARCH IN LISTS ARCH_LIST)
set(cuda_computer_target_flags_temp ${cuda_computer_target_flags_temp} -gencode arch=compute_${ARCH},code=compute_${ARCH})
endforeach()

set(${cuda_nvcc_target_flags} ${cuda_computer_target_flags_temp})
ENDMACRO()

MACRO(APPEND_TARGET_ARCH_FLAGS)
set(cuda_nvcc_target_flags "")
CUDA_COMPUTE_TARGET_FLAGS(CUDA_ARCH_BIN CUDA_ARCH_PTX cuda_nvcc_target_flags)
if (cuda_nvcc_target_flags)
message(STATUS "CUDA NVCC target flags: ${cuda_nvcc_target_flags}")
list(APPEND CUDA_NVCC_FLAGS ${cuda_nvcc_target_flags})
endif()
ENDMACRO()
50 changes: 50 additions & 0 deletions cupoch_conversions/cmake/FindGFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# - Try to find GFLAGS
#
# The following variables are optionally searched for defaults
# GFLAGS_ROOT_DIR: Base directory where all GFLAGS components are found
#
# The following are set after configuration is done:
# GFLAGS_FOUND
# GFLAGS_INCLUDE_DIRS
# GFLAGS_LIBRARIES
# GFLAGS_LIBRARYRARY_DIRS

include(FindPackageHandleStandardArgs)

set(GFLAGS_ROOT_DIR "" CACHE PATH "Folder contains Gflags")

# We are testing only a couple of files in the include directories
if(WIN32)
find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h
PATHS ${GFLAGS_ROOT_DIR}/src/windows)
else()
find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h
PATHS ${GFLAGS_ROOT_DIR})
endif()

if(MSVC)
find_library(GFLAGS_LIBRARY_RELEASE
NAMES libgflags
PATHS ${GFLAGS_ROOT_DIR}
PATH_SUFFIXES Release)

find_library(GFLAGS_LIBRARY_DEBUG
NAMES libgflags-debug
PATHS ${GFLAGS_ROOT_DIR}
PATH_SUFFIXES Debug)

set(GFLAGS_LIBRARY optimized ${GFLAGS_LIBRARY_RELEASE} debug ${GFLAGS_LIBRARY_DEBUG})
else()
find_library(GFLAGS_LIBRARY gflags)
endif()

find_package_handle_standard_args(GFlags DEFAULT_MSG GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY)


if(GFLAGS_FOUND)
set(GFLAGS_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIR})
set(GFLAGS_LIBRARIES ${GFLAGS_LIBRARY})
message(STATUS "Found gflags (include: ${GFLAGS_INCLUDE_DIR}, library: ${GFLAGS_LIBRARY})")
mark_as_advanced(GFLAGS_LIBRARY_DEBUG GFLAGS_LIBRARY_RELEASE
GFLAGS_LIBRARY GFLAGS_INCLUDE_DIR GFLAGS_ROOT_DIR)
endif()
72 changes: 72 additions & 0 deletions cupoch_conversions/cmake/FindTensorRT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# This module defines the following variables:
#
# ::
#
# TensorRT_INCLUDE_DIRS
# TensorRT_LIBRARIES
# TensorRT_FOUND
#
# ::
#
# TensorRT_VERSION_STRING - version (x.y.z)
# TensorRT_VERSION_MAJOR - major version (x)
# TensorRT_VERSION_MINOR - minor version (y)
# TensorRT_VERSION_PATCH - patch version (z)
#
# Hints
# ^^^^^
# A user may set ``TensorRT_ROOT`` to an installation root to tell this module where to look.
#
set(_TensorRT_SEARCHES)

if(TensorRT_ROOT)
set(_TensorRT_SEARCH_ROOT PATHS ${TensorRT_ROOT} NO_DEFAULT_PATH)
list(APPEND _TensorRT_SEARCHES _TensorRT_SEARCH_ROOT)
endif()

# appends some common paths
set(_TensorRT_SEARCH_NORMAL
PATHS "/usr"
)
list(APPEND _TensorRT_SEARCHES _TensorRT_SEARCH_NORMAL)

# Include dir
foreach(search ${_TensorRT_SEARCHES})
find_path(TensorRT_INCLUDE_DIR NAMES NvInfer.h ${${search}} PATH_SUFFIXES include)
endforeach()

if(NOT TensorRT_LIBRARY)
foreach(search ${_TensorRT_SEARCHES})
find_library(TensorRT_LIBRARY NAMES nvinfer ${${search}} PATH_SUFFIXES lib)
endforeach()
endif()

mark_as_advanced(TensorRT_INCLUDE_DIR)

if(TensorRT_INCLUDE_DIR AND EXISTS "${TensorRT_INCLUDE_DIR}/NvInfer.h")
file(STRINGS "${TensorRT_INCLUDE_DIR}/NvInfer.h" TensorRT_MAJOR REGEX "^#define NV_TENSORRT_MAJOR [0-9]+.*$")
file(STRINGS "${TensorRT_INCLUDE_DIR}/NvInfer.h" TensorRT_MINOR REGEX "^#define NV_TENSORRT_MINOR [0-9]+.*$")
file(STRINGS "${TensorRT_INCLUDE_DIR}/NvInfer.h" TensorRT_PATCH REGEX "^#define NV_TENSORRT_PATCH [0-9]+.*$")

string(REGEX REPLACE "^#define NV_TENSORRT_MAJOR ([0-9]+).*$" "\\1" TensorRT_VERSION_MAJOR "${TensorRT_MAJOR}")
string(REGEX REPLACE "^#define NV_TENSORRT_MINOR ([0-9]+).*$" "\\1" TensorRT_VERSION_MINOR "${TensorRT_MINOR}")
string(REGEX REPLACE "^#define NV_TENSORRT_PATCH ([0-9]+).*$" "\\1" TensorRT_VERSION_PATCH "${TensorRT_PATCH}")
set(TensorRT_VERSION_STRING "${TensorRT_VERSION_MAJOR}.${TensorRT_VERSION_MINOR}.${TensorRT_VERSION_PATCH}")
endif()

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(TensorRT REQUIRED_VARS TensorRT_LIBRARY TensorRT_INCLUDE_DIR VERSION_VAR TensorRT_VERSION_STRING)

if(TensorRT_FOUND)
set(TensorRT_INCLUDE_DIRS ${TensorRT_INCLUDE_DIR})

if(NOT TensorRT_LIBRARIES)
set(TensorRT_LIBRARIES ${TensorRT_LIBRARY})
endif()

if(NOT TARGET TensorRT::TensorRT)
add_library(TensorRT::TensorRT UNKNOWN IMPORTED)
set_target_properties(TensorRT::TensorRT PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${TensorRT_INCLUDE_DIRS}")
set_property(TARGET TensorRT::TensorRT APPEND PROPERTY IMPORTED_LOCATION "${TensorRT_LIBRARY}")
endif()
endif()
40 changes: 40 additions & 0 deletions cupoch_conversions/cmake/Findthrust.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

find_path(THRUST_INCLUDE_DIR
HINTS
"/usr/include"
"/usr/local/include"
"/usr/local/cuda/include"
NAMES
"thrust/version.h")

if(THRUST_INCLUDE_DIR)
file(STRINGS "${THRUST_INCLUDE_DIR}/thrust/version.h"
THRUST_VERSION_STRING
REGEX "#define THRUST_VERSION[ \t]+([0-9x]+)")

string(REGEX REPLACE "#define THRUST_VERSION[ \t]+" "" THRUST_VERSION_STRING ${THRUST_VERSION_STRING})

math(EXPR THRUST_VERSION_MAJOR "${THRUST_VERSION_STRING} / 100000")
math(EXPR THRUST_VERSION_MINOR "(${THRUST_VERSION_STRING} / 100) % 1000")
math(EXPR THRUST_VERSION_PATCH "${THRUST_VERSION_STRING} % 100")
unset(THRUST_VERSION_STRING)

set(THRUST_VERSION "${THRUST_VERSION_MAJOR}.${THRUST_VERSION_MINOR}.${THRUST_VERSION_PATCH}")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(thrust
REQUIRED_VARS THRUST_INCLUDE_DIR
VERSION_VAR THRUST_VERSION)


if(thrust_FOUND)
add_library(thrust::thrust INTERFACE IMPORTED)
set_target_properties(thrust::thrust PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${THRUST_INCLUDE_DIR}")

mark_as_advanced(THRUST_INCLUDE_DIR
THRUST_VERSION
THRUST_VERSION_MAJOR
THRUST_VERSION_MINOR
THRUST_VERSION_PATCH)
endif()
49 changes: 49 additions & 0 deletions cupoch_conversions/cmake/GACompilerFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
if (NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "${CMAKE_CXX_COMPILER_ID}"))
message(FATAL_ERROR "C compiler (${CMAKE_C_COMPILER_ID}) does not match C++ compiler (${CMAKE_CXX_COMPILER_ID})")
endif()

if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(CLANG_ALL_WARNINGS "-Weverything")
list(APPEND CLANG_ALL_WARNINGS "-Wno-missing-field-initializers") # Allow c structs without all fields initialized
list(APPEND CLANG_ALL_WARNINGS "-Wno-reserved-id-macro") # Needed for azure-c-shared-utility which defines new macros that start with "_"
list(APPEND CLANG_ALL_WARNINGS "-Wno-gnu-zero-variadic-macro-arguments") # Needed too allow variadic macros with zero args
list(APPEND CLANG_ALL_WARNINGS "-Wno-extra-semi") # Allow for multiple semi-colons in a row
list(APPEND CLANG_ALL_WARNINGS "-Wno-c++98-compat-pedantic") # Allow commas on the last enum value
list(APPEND CLANG_ALL_WARNINGS "-Wno-padded") # Do not warn about inserted padding to structs
list(APPEND CLANG_ALL_WARNINGS "-Wno-switch-enum") # Do not warn about missing case statements in enums
list(APPEND CLANG_ALL_WARNINGS "-Wno-old-style-cast") # Allow old style c casts
list(APPEND CLANG_ALL_WARNINGS "-Wno-global-constructors") # Allow global constructors. Needed for gtest
list(APPEND CLANG_ALL_WARNINGS "-Wno-newline-eof") # Allow no newline at eof. Needed for azure-c-utility
list(APPEND CLANG_ALL_WARNINGS "-Wno-exit-time-destructors") # Allow exit time destructors. Needed for spdlog
list(APPEND CLANG_ALL_WARNINGS "-Wno-weak-vtables") # Allow weak vtables. Needed for spdlog
list(APPEND CLANG_ALL_WARNINGS "-Wno-undef") # Allow undefined macros. Needed for azure-c-shared-utility
list(APPEND CLANG_ALL_WARNINGS "-Wno-disabled-macro-expansion") # Allow recursive macro expansion
list(APPEND CLANG_ALL_WARNINGS "-Wno-documentation-unknown-command") # Allow undocumented documentation commands used by doxygen
list(APPEND CLANG_ALL_WARNINGS "-Wno-covered-switch-default") # Allow default: in switch statements that cover all enum values
list(APPEND CLANG_ALL_WARNINGS "-Wno-unreachable-code-break") # Allow break even if it is unreachable
list(APPEND CLANG_ALL_WARNINGS "-Wno-double-promotion") # Allow floats to be promoted to doubles. Needed for isnan() on some systems
if (NOT (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS "5.0.0"))
# Added in clang 5
list(APPEND CLANG_ALL_WARNINGS "-Wno-zero-as-null-pointer-constant") # Allow zero as nullptr
endif()
set(CLANG_WARNINGS_AS_ERRORS "-Werror")
add_compile_options(${CLANG_ALL_WARNINGS})
# zs: 太严格了
# add_compile_options(${CLANG_WARNINGS_AS_ERRORS})
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(GNU_ALL_WARNINGS "-Wall" "-Wextra")
list(APPEND GNU_ALL_WARNINGS "-Wno-missing-field-initializers") # Allow c structs without all fields initialized
set(GNU_WARNINGS_AS_ERRORS "-Werror")
add_compile_options(${GNU_ALL_WARNINGS})
# zs: 太严格了
# add_compile_options(${GNU_WARNINGS_AS_ERRORS})
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
set(MSVC_ALL_WARNINGS "/W4" "/wd4200") #Note: allow zero length arrays
set(MSVC_WARNINGS_AS_ERRORS "/WX")
string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
add_compile_options(${MSVC_ALL_WARNINGS})
add_compile_options(${MSVC_WARNINGS_AS_ERRORS})
else()
message(FATAL_ERROR "Unknown C++ compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()
Loading

0 comments on commit 3fa326b

Please sign in to comment.