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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build examples from CMake rather than executable #482

Merged
merged 15 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ project(gz-math7 VERSION 7.2.0)
#============================================================================
# If you get an error at this line, you need to install gz-cmake
find_package(gz-cmake3 REQUIRED)
set(GZ_CMAKE_VER ${gz-cmake3_VERSION_MAJOR})

#============================================================================
# Configure the project
Expand Down Expand Up @@ -144,3 +145,13 @@ configure_file(${CMAKE_SOURCE_DIR}/tutorials.md.in ${CMAKE_BINARY_DIR}/tutorials
gz_create_docs(
API_MAINPAGE_MD "${CMAKE_BINARY_DIR}/api.md"
TUTORIALS_MAINPAGE_MD "${CMAKE_BINARY_DIR}/tutorials.md")

#============================================================================
# Build examples
#============================================================================
if (BUILD_TESTING)
gz_build_examples(
SOURCE_DIR ${PROJECT_SOURCE_DIR}/examples
BINARY_DIR ${PROJECT_BINARY_DIR}/examples
)
endif()
13 changes: 6 additions & 7 deletions examples/color_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@
#include <iostream>
#include <gz/math/Color.hh>

int main(int argc, char **argv)
int main(int /*argc*/, char **/*argv*/)
{

//! [Create a color]
gz::math::Color a = gz::math::Color(0.3, 0.4, 0.5);
gz::math::Color a = gz::math::Color(0.3f, 0.4f, 0.5f);
//! [Create a color]
// The channel order is R, G, B, A and the default alpha value of a should be 1.0
std::cout << "The alpha value of a should be 1: " << a.A() << std::endl;



//! [Set a new color value]
a.gz::math::Color::Set(0.6, 0.7, 0.8, 1.0);
a.gz::math::Color::Set(0.6f, 0.7f, 0.8f, 1.0f);
//! [Set a new color value]
std::cout << "The RGBA value of a: " << a << std::endl;

Expand All @@ -41,8 +40,8 @@ int main(int argc, char **argv)

//! [Math operator]
std::cout << "Check if a is Blue: " << (a == gz::math::Color::Blue) << std::endl;
std::cout << "The RGB value of a should be (0, 0, 1): " << a[0] << ", "
<< a[1] << ", "
std::cout << "The RGB value of a should be (0, 0, 1): " << a[0] << ", "
<< a[1] << ", "
<< a[2] << std::endl;
//! [Math operator]

Expand Down
4 changes: 2 additions & 2 deletions include/gz/math/Helpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ namespace gz
T sum = 0;
for (unsigned int i = 0; i < _values.size(); ++i)
sum += _values[i];
return sum / _values.size();
return sum / static_cast<T>(_values.size());
}

/// \brief Get the variance of a vector of values.
Expand All @@ -367,7 +367,7 @@ namespace gz
T sum = 0;
for (unsigned int i = 0; i < _values.size(); ++i)
sum += (_values[i] - avg) * (_values[i] - avg);
return sum / _values.size();
return sum / static_cast<T>(_values.size());
}

/// \brief Get the maximum value of vector of values.
Expand Down
2 changes: 1 addition & 1 deletion include/gz/math/Polynomial3.hh
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ namespace gz
using std::abs; // enable ADL
const T magnitude = abs(this->coeffs[i]);
const bool sign = this->coeffs[i] < T(0);
const int exponent = 3 - i;
const int exponent = 3 - static_cast<int>(i);
if (magnitude >= epsilon)
{
if (streamStarted)
Expand Down
21 changes: 0 additions & 21 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,6 @@ include_directories (
${PROJECT_BINARY_DIR}/include
)

#============================================================================
# Do a fake install of gz-math in order to test the examples.
#============================================================================
# install to FAKE_INSTALL_PREFIX defined in root CMakeLists.txt

file(MAKE_DIRECTORY ${FAKE_INSTALL_PREFIX})

include(ExternalProject)
ExternalProject_Add(
FAKE_INSTALL

SOURCE_DIR "${CMAKE_SOURCE_DIR}"
EXCLUDE_FROM_ALL 1
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_INSTALL 1
CMAKE_ARGS
"-DBUILD_TESTING=OFF"
"-DCMAKE_INSTALL_PREFIX=${FAKE_INSTALL_PREFIX}"
)

add_subdirectory(gtest_vendor)
add_subdirectory(integration)
add_subdirectory(performance)
Expand Down
9 changes: 0 additions & 9 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,3 @@ if (UNIX AND NOT APPLE)
endif()

gz_build_tests(TYPE INTEGRATION SOURCES ${tests})

if(TARGET INTEGRATION_ExamplesBuild_TEST)
add_dependencies(INTEGRATION_ExamplesBuild_TEST FAKE_INSTALL)

set(_env_vars)
list(APPEND _env_vars "CMAKE_PREFIX_PATH=${FAKE_INSTALL_PREFIX}:$ENV{CMAKE_PREFIX_PATH}")
set_tests_properties(INTEGRATION_ExamplesBuild_TEST PROPERTIES
ENVIRONMENT "${_env_vars}")
endif()
Loading