Skip to content
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 examples using native CMake #301

Merged
merged 18 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
64 changes: 64 additions & 0 deletions cmake/GzUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,70 @@ macro(_gz_add_library_or_component)
endmacro()


#################################################
# gz_build_examples(
# SOURCE_DIR <source_dir>
# BINARY_DIR <binary_dir>
#
# Build examples for a Gazebo project.
mjcarroll marked this conversation as resolved.
Show resolved Hide resolved
# Requires a CMakeLists.txt file to be in SOURCE_DIR that acts
# as a top level project.
#
# This generates two test targets
# * EXAMPLES_Configure_TEST - Equivalent of calling "cmake .." on
# the examples directory
#
# * EXAMPLES_Build_TEST - Equivalent of calling "make" on the
# examples directory
#
# These tests are run during "make test" or can be run specifically
# via "ctest -R EXAMPLES_ -V"
#
# Arguments are as follows:
#
# SOURCE_DIR: Required. Path to the examples folder.
# For example ${CMAKE_CURRENT_SOURCE_DIR}/examples
#
# BINARY_DIR: Required. Path to the output binary folder
# For example ${CMAKE_CURRENT_BINARY_DIR}/examples
#
macro(gz_build_examples)
#------------------------------------
# Define the expected arguments
set(options)
set(oneValueArgs SOURCE_DIR BINARY_DIR)

#------------------------------------
# Parse the arguments
_gz_cmake_parse_arguments(gz_build_examples "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

set(gz_build_examples_CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
string(REPLACE ":" ";" gz_build_examples_CMAKE_PREFIX_PATH ${gz_build_examples_CMAKE_PREFIX_PATH})
list(APPEND gz_build_examples_CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX})

add_test(
NAME EXAMPLES_Configure_TEST
COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR}
--no-warn-unused-cli
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
"-DCMAKE_PREFIX_PATH=${gz_build_examples_CMAKE_PREFIX_PATH}"
-S ${gz_build_examples_SOURCE_DIR}
-B ${gz_build_examples_BINARY_DIR}
)

add_test(
NAME EXAMPLES_Build_TEST
COMMAND ${CMAKE_COMMAND} --build ${gz_build_examples_BINARY_DIR}
--config $<CONFIG>
)
set_tests_properties(EXAMPLES_Build_TEST
PROPERTIES DEPENDS "EXAMPLES_Configure_TEST")
endmacro()

#################################################
# _gz_cmake_parse_arguments(<prefix> <options> <oneValueArgs> <multiValueArgs> [ARGN])
#
Expand Down
7 changes: 6 additions & 1 deletion cmake/gz-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ endif()
# contain imported targets, so @PKG_NAME@_INCLUDE_DIRS is never needed.
set(@PKG_NAME@_CORE_LIBRARY @simple_import_name@)
set(@PKG_NAME@_LIBRARIES @gz_namespace@requested)
set_and_check(@PKG_NAME@_INCLUDE_DIRS "@PACKAGE_GZ_INCLUDE_INSTALL_DIR_FULL@")

if (NOT @PKG_NAME@_INCLUDE_DIRS_OVERRIDE)
set_and_check(@PKG_NAME@_INCLUDE_DIRS "@PACKAGE_GZ_INCLUDE_INSTALL_DIR_FULL@")
else()
set_and_check(@PKG_NAME@_INCLUDE_DIRS ${@PKG_NAME@_INCLUDE_DIRS_OVERRIDE})
endif()

# Backwards compatibility variables
set(@LEGACY_PROJECT_PREFIX@_LIBRARIES ${@PKG_NAME@_LIBRARIES})
Expand Down