Skip to content
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
5 changes: 5 additions & 0 deletions ament_cmake_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ ament_package(
"ament_cmake_symlink_install-extras.cmake" # must be after uninstall_target
)

include(CTest)
if(BUILD_TESTING)
add_subdirectory(test)
endif()

install(
DIRECTORY cmake
DESTINATION share/${PROJECT_NAME}
Expand Down
10 changes: 6 additions & 4 deletions ament_cmake_core/ament_cmake_core-extras.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

include("${ament_cmake_core_DIR}/core/all.cmake" NO_POLICY_SCOPE)

# Add AMENT_IGNORE to CMAKE_BINARY_DIR to avoid picking up cmake specific folders created by
# CLion in `colcon build` and `colcon test` commands
file(WRITE ${CMAKE_BINARY_DIR}/AMENT_IGNORE "")

get_property(_cmake_role GLOBAL PROPERTY CMAKE_ROLE)
if("${_cmake_role}" STREQUAL "PROJECT")
# Add AMENT_IGNORE to CMAKE_BINARY_DIR to avoid picking up cmake specific folders created by
# CLion in `colcon build` and `colcon test` commands
file(WRITE ${CMAKE_BINARY_DIR}/AMENT_IGNORE "")
endif()
69 changes: 36 additions & 33 deletions ament_cmake_core/ament_cmake_package_templates-extras.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,42 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# extract information from ament_package.templates
if(NOT TARGET Python3::Interpreter)
message(FATAL_ERROR
"ament_cmake_package_templates: target 'Python3::Interpreter' must exist")
endif()
get_property(_cmake_role GLOBAL PROPERTY CMAKE_ROLE)
if("${_cmake_role}" STREQUAL "PROJECT")
# extract information from ament_package.templates
if(NOT TARGET Python3::Interpreter)
message(FATAL_ERROR
"ament_cmake_package_templates: target 'Python3::Interpreter' must exist")
endif()

# stamp script to generate CMake code
set(_generator
"${ament_cmake_core_DIR}/package_templates/templates_2_cmake.py")
stamp("${_generator}")
# stamp script to generate CMake code
set(_generator
"${ament_cmake_core_DIR}/package_templates/templates_2_cmake.py")
stamp("${_generator}")

# invoke generator script
set(_generated_file
"${CMAKE_CURRENT_BINARY_DIR}/ament_cmake_package_templates/templates.cmake")
get_executable_path(_python_interpreter Python3::Interpreter CONFIGURE)
set(_cmd
"${_python_interpreter}"
"${_generator}"
"${_generated_file}"
)
execute_process(
COMMAND ${_cmd}
RESULT_VARIABLE _res
)
if(NOT _res EQUAL 0)
string(REPLACE ";" " " _cmd_str "${_cmd}")
message(FATAL_ERROR
"execute_process(${_cmd_str}) returned error code ${_res}")
endif()
# invoke generator script
set(_generated_file
"${CMAKE_CURRENT_BINARY_DIR}/ament_cmake_package_templates/templates.cmake")
get_executable_path(_python_interpreter Python3::Interpreter CONFIGURE)
set(_cmd
"${_python_interpreter}"
"${_generator}"
"${_generated_file}"
)
execute_process(
COMMAND ${_cmd}
RESULT_VARIABLE _res
)
if(NOT _res EQUAL 0)
string(REPLACE ";" " " _cmd_str "${_cmd}")
message(FATAL_ERROR
"execute_process(${_cmd_str}) returned error code ${_res}")
endif()

# load extracted variables into cmake
# for each environment hook defined in `ament_package`
# (e.g. `library_path.bat|sh`) a CMake variable is defined starting with
# `ament_cmake_package_templates_ENVIRONMENT_HOOK_`
# (e.g. `ament_cmake_package_templates_ENVIRONMENT_HOOK_LIBRARY_PATH`)
include("${_generated_file}")
# load extracted variables into cmake
# for each environment hook defined in `ament_package`
# (e.g. `library_path.bat|sh`) a CMake variable is defined starting with
# `ament_cmake_package_templates_ENVIRONMENT_HOOK_`
# (e.g. `ament_cmake_package_templates_ENVIRONMENT_HOOK_LIBRARY_PATH`)
include("${_generated_file}")
endif()
37 changes: 20 additions & 17 deletions ament_cmake_core/ament_cmake_uninstall_target-extras.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,27 @@ if(AMENT_CMAKE_UNINSTALL_TARGET)
include(
"${ament_cmake_core_DIR}/uninstall_target/ament_cmake_uninstall_target_append_uninstall_code.cmake")

# create the install script from the template
# ament_cmake_core/uninstall_target/ament_cmake_uninstall_target.cmake.in
set(AMENT_CMAKE_UNINSTALL_TARGET_UNINSTALL_SCRIPT
"${CMAKE_CURRENT_BINARY_DIR}/ament_cmake_uninstall_target/ament_cmake_uninstall_target.cmake")
configure_file(
"${ament_cmake_core_DIR}/uninstall_target/ament_cmake_uninstall_target.cmake.in"
"${AMENT_CMAKE_UNINSTALL_TARGET_UNINSTALL_SCRIPT}"
@ONLY
)
get_property(_cmake_role GLOBAL PROPERTY CMAKE_ROLE)
if("${_cmake_role}" STREQUAL "PROJECT")
# create the install script from the template
# ament_cmake_core/uninstall_target/ament_cmake_uninstall_target.cmake.in
set(AMENT_CMAKE_UNINSTALL_TARGET_UNINSTALL_SCRIPT
"${CMAKE_CURRENT_BINARY_DIR}/ament_cmake_uninstall_target/ament_cmake_uninstall_target.cmake")
configure_file(
"${ament_cmake_core_DIR}/uninstall_target/ament_cmake_uninstall_target.cmake.in"
"${AMENT_CMAKE_UNINSTALL_TARGET_UNINSTALL_SCRIPT}"
@ONLY
)

if(NOT TARGET uninstall)
add_custom_target(uninstall)
endif()
if(NOT TARGET uninstall)
add_custom_target(uninstall)
endif()

if(NOT TARGET ${PROJECT_NAME}_uninstall)
# register uninstall target to run generated CMake script
add_custom_target(${PROJECT_NAME}_uninstall
COMMAND ${CMAKE_COMMAND} -P "${AMENT_CMAKE_UNINSTALL_TARGET_UNINSTALL_SCRIPT}")
add_dependencies(uninstall ${PROJECT_NAME}_uninstall)
if(NOT TARGET ${PROJECT_NAME}_uninstall)
# register uninstall target to run generated CMake script
add_custom_target(${PROJECT_NAME}_uninstall
COMMAND ${CMAKE_COMMAND} -P "${AMENT_CMAKE_UNINSTALL_TARGET_UNINSTALL_SCRIPT}")
add_dependencies(uninstall ${PROJECT_NAME}_uninstall)
endif()
endif()
endif()
5 changes: 4 additions & 1 deletion ament_cmake_core/cmake/core/all.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ endif()

# the following operations must be performed inside a project context
if(NOT PROJECT_NAME)
project(ament_cmake_internal NONE)
get_property(_cmake_role GLOBAL PROPERTY CMAKE_ROLE)
if("${_cmake_role}" STREQUAL "PROJECT")
project(ament_cmake_internal NONE)
endif()
endif()

# use BUILD_TESTING to avoid warnings about not using it
Expand Down
2 changes: 2 additions & 0 deletions ament_cmake_core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_test(NAME smoke
COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_SOURCE_DIR}/smoke.cmake")
2 changes: 2 additions & 0 deletions ament_cmake_core/test/smoke.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(ament_cmake_core_DIR "${CMAKE_CURRENT_LIST_DIR}/../cmake")
include("${CMAKE_CURRENT_LIST_DIR}/../ament_cmake_core-extras.cmake")
5 changes: 5 additions & 0 deletions ament_cmake_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ ament_package(
CONFIG_EXTRAS "ament_cmake_test-extras.cmake"
)

include(CTest)
if(BUILD_TESTING)
add_subdirectory(test)
endif()

install(
DIRECTORY cmake
DESTINATION share/${PROJECT_NAME}
Expand Down
7 changes: 5 additions & 2 deletions ament_cmake_test/ament_cmake_test-extras.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

# copied from ament_cmake_test/ament_cmake_test-extras.cmake

enable_testing()
get_property(_cmake_role GLOBAL PROPERTY CMAKE_ROLE)
if("${_cmake_role}" STREQUAL "PROJECT")
enable_testing()
endif()
# same option as in the CTest module
option(BUILD_TESTING "Build the testing tree." ON)

Expand All @@ -24,7 +27,7 @@ set(
CACHE PATH "The path where test results are generated"
)

if(BUILD_TESTING)
if(BUILD_TESTING AND "${_cmake_role}" STREQUAL "PROJECT")
# configure ctest not to truncate the dashboard summary
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake"
"set(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 0)\n"
Expand Down
2 changes: 2 additions & 0 deletions ament_cmake_test/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_test(NAME smoke
COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_SOURCE_DIR}/smoke.cmake")
2 changes: 2 additions & 0 deletions ament_cmake_test/test/smoke.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(ament_cmake_test_DIR "${CMAKE_CURRENT_LIST_DIR}/../cmake")
include("${CMAKE_CURRENT_LIST_DIR}/../ament_cmake_test-extras.cmake")