diff --git a/Migration.md b/Migration.md index c0b90136..12c3d352 100644 --- a/Migration.md +++ b/Migration.md @@ -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: diff --git a/cmake/GzBuildExamples.cmake b/cmake/GzBuildExamples.cmake index 5f202385..139d5be7 100644 --- a/cmake/GzBuildExamples.cmake +++ b/cmake/GzBuildExamples.cmake @@ -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 $ - ) - 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 $ + ) + set_tests_properties(EXAMPLES_Build_TEST + PROPERTIES DEPENDS "EXAMPLES_Configure_TEST") + endif() endmacro()