From 6e2444ff97616f68a2bcfd97b4cd2acec880b93b Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Mon, 28 Aug 2023 09:04:28 -0500 Subject: [PATCH] Build examples from CMake rather than executable (#502) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Carroll Signed-off-by: Michael Carroll Signed-off-by: Michael Carroll Co-authored-by: Alejandro Hernández Cordero Co-authored-by: Ian Chen --- .github/workflows/macos.yml | 10 ++++++---- CMakeLists.txt | 11 ++++++++++- examples/CMakeLists.txt | 4 +++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 54e002fd..de4fd5d0 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -48,12 +48,14 @@ jobs: run: cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/${PACKAGE}/HEAD - run: make working-directory: build - - run: make test - working-directory: build - env: - CTEST_OUTPUT_ON_FAILURE: 1 + # Run make install before make test so that the package will be available to + # build examples as part of the test - name: make install working-directory: build run: | make install; brew link ${PACKAGE}; + - run: make test + working-directory: build + env: + CTEST_OUTPUT_ON_FAILURE: 1 diff --git a/CMakeLists.txt b/CMakeLists.txt index b13ff3b9..ad621374 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,7 +144,6 @@ gz_configure_build(QUIT_IF_BUILD_ERRORS #============================================================================ gz_create_packages() - #============================================================================ # Create documentation #============================================================================ @@ -157,3 +156,13 @@ gz_create_docs( TAGFILES "${GZ-MATH_DOXYGEN_TAGFILE} = ${GZ-MATH_API_URL}" ) + +#============================================================================ +# Build examples +#============================================================================ +if (BUILD_TESTING) + gz_build_examples( + SOURCE_DIR ${PROJECT_SOURCE_DIR}/examples + BINARY_DIR ${PROJECT_BINARY_DIR}/examples + ) +endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 22f20252..3908f387 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,4 +1,6 @@ -cmake_minimum_required(VERSION 2.8 FATAL_ERROR) +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) + +project(gz-common-examples) # Find the gz-common library find_package(gz-common5 QUIET REQUIRED COMPONENTS events profiler)