Skip to content

Commit

Permalink
Convert to pure CMake, remove ROS node
Browse files Browse the repository at this point in the history
  • Loading branch information
schornakj committed Jul 7, 2020
1 parent 4190858 commit dc60696
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 81 deletions.
144 changes: 72 additions & 72 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,112 +1,112 @@
cmake_minimum_required(VERSION 2.8.3)
project(gl_depth_sim)

add_compile_options(-std=c++14 -Wall -Wextra)

find_package(catkin REQUIRED COMPONENTS
roscpp # Used for ROS examples
pcl_ros # Used for interfaces extension
tf # Used for ROS example
tf_conversions # Used for ROS example
)
cmake_minimum_required(VERSION 3.5.0)
project(gl_depth_sim VERSION 0.2.0 LANGUAGES C CXX)

# Required for core functionality
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(PCL REQUIRED)

# Extensions
find_package(assimp REQUIRED) # Just used for loading models in mesh_loader.h
find_package(OpenCV REQUIRED) # Used for interface extension

catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME} ${PROJECT_NAME}_interfaces
CATKIN_DEPENDS pcl_ros
DEPENDS OpenCV
)

include_directories(
include
${catkin_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
)
add_library(glad SHARED src/${PROJECT_NAME}/glad.c)
target_include_directories(glad PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")

# Primary rendering library
# Independent of ROS, but does need glfw3 and assimp for model loading
add_library(${PROJECT_NAME}
add_library(${PROJECT_NAME} SHARED
src/${PROJECT_NAME}/sim_depth_camera.cpp
src/${PROJECT_NAME}/mesh_loader.cpp
src/${PROJECT_NAME}/mesh.cpp
src/${PROJECT_NAME}/renderable_mesh.cpp
src/${PROJECT_NAME}/shader_program.cpp
src/${PROJECT_NAME}/glad.c
src/${PROJECT_NAME}/glfw_guard.cpp
)

add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME}
${OPENGL_LIBRARIES}
src/${PROJECT_NAME}/glfw_guard.cpp)
target_compile_options(${PROJECT_NAME} PRIVATE -std=c++11)
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
target_link_libraries(${PROJECT_NAME} PUBLIC
${ASSIMP_LIBRARIES}
OpenGL::OpenGL
glad
dl
glfw
)
Eigen3::Eigen
)

# Libaries for interfacing with opencv and pcl
add_library(${PROJECT_NAME}_interfaces
add_library(${PROJECT_NAME}_interfaces SHARED
src/interfaces/pcl_interface.cpp
src/interfaces/opencv_interface.cpp
)

add_dependencies(${PROJECT_NAME}_interfaces ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME}_interfaces
src/interfaces/opencv_interface.cpp)
target_compile_options(${PROJECT_NAME}_interfaces PRIVATE -std=c++11)
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
target_include_directories(${PROJECT_NAME}_interfaces SYSTEM PUBLIC
${PCL_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}_interfaces PUBLIC
${PROJECT_NAME}
${catkin_LIBRARIES}
${OpenCV_LIBRARIES}
${PCL_LIBRARIES}
)

# Example showing basic usage
add_executable(${PROJECT_NAME}_test src/usage_example.cpp)

target_compile_options(${PROJECT_NAME}_test PRIVATE -std=c++11)
set_target_properties(${PROJECT_NAME}_test PROPERTIES OUTPUT_NAME depth_example PREFIX "")

target_link_libraries(${PROJECT_NAME}_test
target_include_directories(${PROJECT_NAME}_test PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
target_link_libraries(${PROJECT_NAME}_test PUBLIC
${PROJECT_NAME}
${PROJECT_NAME}_interfaces
${catkin_LIBRARIES}
)
${PROJECT_NAME}_interfaces)

# Example showing an orbiting camera
add_executable(${PROJECT_NAME}_orbit src/camera_orbit_example.cpp)

target_compile_options(${PROJECT_NAME}_orbit PRIVATE -std=c++11)
set_target_properties(${PROJECT_NAME}_orbit PROPERTIES OUTPUT_NAME orbit_example PREFIX "")

target_link_libraries(${PROJECT_NAME}_orbit
target_include_directories(${PROJECT_NAME}_orbit PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
target_link_libraries(${PROJECT_NAME}_orbit PUBLIC
${PROJECT_NAME}
${PROJECT_NAME}_interfaces
${catkin_LIBRARIES}
)

# Example showing orbiting camera with point cloud publishing in ROS
add_executable(${PROJECT_NAME}_ros_orbit src/camera_ros_example.cpp)

set_target_properties(${PROJECT_NAME}_ros_orbit PROPERTIES OUTPUT_NAME ros_example PREFIX "")
${PROJECT_NAME}_interfaces)
install(DIRECTORY include/${PROJECT_NAME}
DESTINATION include
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE)

target_link_libraries(${PROJECT_NAME}_ros_orbit
install(TARGETS
glad
${PROJECT_NAME}
${PROJECT_NAME}_interfaces
${catkin_LIBRARIES}
)

install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_interfaces
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
)
${PROJECT_NAME}_test
${PROJECT_NAME}_orbit
EXPORT ${PROJECT_NAME}-targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(EXPORT ${PROJECT_NAME}-targets NAMESPACE gl_depth_sim:: DESTINATION lib/cmake/${PROJECT_NAME})

install(FILES package.xml DESTINATION share/${PROJECT_NAME})

# Create cmake config files
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}
NO_CHECK_REQUIRED_COMPONENTS_MACRO)

write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
VERSION ${PROJECT_VERSION} COMPATIBILITY ExactVersion)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
DESTINATION lib/cmake/${PROJECT_NAME})

export(EXPORT ${PROJECT_NAME}-targets NAMESPACE gl_depth_sim:: FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-targets.cmake)
15 changes: 15 additions & 0 deletions cmake/gl_depth_sim-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@PACKAGE_INIT@

set(@PROJECT_NAME@_FOUND ON)
set_and_check(@PROJECT_NAME@_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include")
set_and_check(@PROJECT_NAME@_LIBRARY_DIRS "${PACKAGE_PREFIX_DIR}/lib")

include(CMakeFindDependencyMacro)
find_dependency(Eigen3)
find_dependency(assimp)
find_dependency(OpenCV)
find_dependency(OpenGL)
find_dependency(glfw3)


include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
2 changes: 2 additions & 0 deletions include/gl_depth_sim/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ using EigenAlignedVec = std::vector<T, Eigen::aligned_allocator<T>>;
class Mesh
{
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW

Mesh(const EigenAlignedVec<Eigen::Vector3f>& vertices, const std::vector<unsigned>& indices);

std::size_t numIndices() const { return indices_.size(); }
Expand Down
2 changes: 2 additions & 0 deletions include/gl_depth_sim/shader_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace gl_depth_sim
class ShaderProgram
{
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW

ShaderProgram(const std::string& vertex_shader, const std::string& frag_shader);
~ShaderProgram();

Expand Down
4 changes: 4 additions & 0 deletions include/gl_depth_sim/sim_depth_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct RenderableObjectState
{
std::unique_ptr<RenderableMesh> mesh;
Eigen::Isometry3d pose;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

/**
Expand Down Expand Up @@ -82,6 +83,9 @@ class SimDepthCamera
GLFWwindow* window_;
std::unique_ptr<ShaderProgram> depth_program_;
unsigned int fbo_;

public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

}
Expand Down
15 changes: 6 additions & 9 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@

<license>LGPLv3</license>

<buildtool_depend>catkin</buildtool_depend>
<depend>roscpp</depend>

<!--Used for examples and interfacing-->
<depend>tf</depend>
<depend>tf_conversions</depend>
<depend>pcl_ros</depend>

<!-- system dependency -->
<build_depend>libglfw3-dev</build_depend>

<depend>assimp</depend>
<depend>libopencv-dev</depend>

<depend>eigen</depend>

<export>
<build_type>cmake</build_type>
</export>
</package>

0 comments on commit dc60696

Please sign in to comment.