Skip to content

Commit

Permalink
Disable building examples by default (#377)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
Co-authored-by: Jose Luis Rivero <[email protected]>
  • Loading branch information
mjcarroll and j-rivero authored Aug 22, 2023
1 parent 87c2a54 commit 93c2059
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 36 deletions.
5 changes: 5 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ release will remove the deprecated code.

## Gazebo CMake 2.X to 3.X

1. **Breaking**: Examples are now built using native cmake.
Two targets will be generated for each set of examples: `EXAMPLES_Build_TEST` and `EXAMPLES_Configure_TEST`
Examples are not built by default, but instead require `BUILD_EXAMPLES:bool=True` to be set.
This is because examples require the package of interest to be installed via `make install`.

1. **Breaking**: The project name has been changed to use the `gz-` prefix, you **must** use the `gz` prefix!
* This also means that any generated code that use the project name (e.g. CMake variables, in-source macros) would have to be migrated.
* Some non-exhaustive examples of this include:
Expand Down
78 changes: 42 additions & 36 deletions cmake/GzBuildExamples.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,52 @@
# For example ${CMAKE_CURRENT_BINARY_DIR}/examples
#
macro(gz_build_examples)
#------------------------------------
# Define the expected arguments
set(options)
set(oneValueArgs SOURCE_DIR BINARY_DIR)
option(BUILD_EXAMPLES "Build examples (requires a system installation of the software first)" OFF)

#------------------------------------
# Parse the arguments
_gz_cmake_parse_arguments(gz_build_examples "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT ${BUILD_EXAMPLES})
message(STATUS "Building examples disabled")
else()
#------------------------------------
# Define the expected arguments
set(options)
set(oneValueArgs SOURCE_DIR BINARY_DIR)

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

if (gz_build_examples_CMAKE_PREFIX_PATH)
# Replace colons from environment variable with semicolon cmake list delimiter
# Only perform if string has contents, otherwise cmake will complain about REPLACE command
string(REPLACE ":" ";" gz_build_examples_CMAKE_PREFIX_PATH ${gz_build_examples_CMAKE_PREFIX_PATH})
endif()
set(gz_build_examples_CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})

if (CMAKE_INSTALL_PREFIX)
list(APPEND gz_build_examples_CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX})
endif()
if (gz_build_examples_CMAKE_PREFIX_PATH)
# Replace colons from environment variable with semicolon cmake list delimiter
# Only perform if string has contents, otherwise cmake will complain about REPLACE command
string(REPLACE ":" ";" gz_build_examples_CMAKE_PREFIX_PATH ${gz_build_examples_CMAKE_PREFIX_PATH})
endif()

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}
)
if (CMAKE_INSTALL_PREFIX)
list(APPEND gz_build_examples_CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX})
endif()

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")
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")
endif()
endmacro()

0 comments on commit 93c2059

Please sign in to comment.