Project won't build because CMAKE_PROJECT_NAME variable not present

asked 2020-06-04 14:50:20 -0600

nightduck gravatar image

I'm migrating part of a project, mav_trajectory_generation, to ROS2 to make use of it as a library. The code itself does not have any ROS components, but used the catkin build tools, so I'm migrating it to ament. I'm getting a bizarre bug that prevents building:

oren@ubuntu-workstation:~/git/AirSim-ROS2$colcon build --packages-select mav_trajectory_generation
Starting >>> mav_trajectory_generation
[1.536s] WARNING:colcon.colcon_cmake.task.cmake.build:Could not build CMake package 'mav_trajectory_generation' because the CMake cache has no 'CMAKE_PROJECT_NAME' variable
Finished <<< mav_trajectory_generation [1.31s]

Summary: 1 package finished [1.51s]

However, the project(...) macro is already used in the CMakeList.txt file:

cmake_minimum_required(VERSION 3.5)
project(mav_trajectory_generation)

#set(CMAKE_MACOSX_RPATH 0)

# Default to C++14CMakeList.txt
if(NOT CMAKE_CXX_STANDARD)
    set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Link against system catkin yaml-cpp if installed.
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
#find_package(PkgConfig)
pkg_check_modules(YamlCpp REQUIRED yaml-cpp>=0.5)

#############
# LIBRARIES #
#############
add_library(${PROJECT_NAME}
  src/motion_defines.cpp
  src/polynomial.cpp
  src/segment.cpp
  src/timing.cpp
  src/trajectory.cpp
  src/trajectory_sampling.cpp
  src/vertex.cpp
  src/io.cpp
  src/rpoly/rpoly_ak1.cpp
)
# Link against yaml-cpp.
ament_target_dependencies(${PROJECT_NAME} ${YamlCpp_LIBRARIES})

############
# BINARIES #
############
add_executable(polynomial_timing_evaluation
  src/polynomial_timing_evaluation.cpp
)
target_link_libraries(polynomial_timing_evaluation ${PROJECT_NAME})

#########
# TESTS #
#########
find_package(ament_cmake_gtest)
ament_add_gtest(test_polynomial
  test/test_polynomial.cpp
)
target_link_libraries(test_polynomial ${PROJECT_NAME})

ament_add_gtest(test_polynomial_optimization
  test/test_polynomial_optimization.cpp
)
target_link_libraries(test_polynomial_optimization ${PROJECT_NAME})

##########
# EXPORT #
##########
ament_export_include_directories(include)

install(TARGETS
        polynomial_timing_evaluation
        DESTINATION lib/${PROJECT_NAME})
install(DIRECTORY include/
        DESTINATION include)


ament_package()

See the original ROS1 CMakeList.txt file here

If you catch any unrelated stupid mistakes, let me know.

edit retag flag offensive close merge delete