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

Add configuration for ARGOS_USE_DOUBLE #6

Open
allsey87 opened this issue Mar 14, 2021 · 4 comments
Open

Add configuration for ARGOS_USE_DOUBLE #6

allsey87 opened this issue Mar 14, 2021 · 4 comments

Comments

@allsey87
Copy link

To add a dynamics3d model to this repository, we need to correctly identify whether argos3_simulator was built with ARGOS_USE_DOUBLE set or not. Without knowing this, Bullet defaults to using 32-bit floats while the rest of the physics engine is using 64-bit floats, leading to errors such as:

malloc(): invalid size (unsorted)
Aborted (core dumped)

My approach to detecting settings is as follows:

# find the include directory
find_path (ARGOS_INCLUDE_DIR argos3/core/config.h)

if(NOT ARGOS_INCLUDE_DIR)
   message(FATAL_ERROR "Can not locate the header file: argos3/core/config.h")
endif(NOT ARGOS_INCLUDE_DIR)

# read the config.h file to get the installations configuration
file(READ ${ARGOS_INCLUDE_DIR}/argos3/core/config.h ARGOS_CONFIGURATION)

# check and set ARGOS_USE_DOUBLE
if(${ARGOS_CONFIGURATION} MATCHES "\#define ARGOS_USE_DOUBLE")
  set(ARGOS_USE_DOUBLE ON)
else(${ARGOS_CONFIGURATION} MATCHES "\#define ARGOS_USE_DOUBLE")
  set(ARGOS_USE_DOUBLE OFF)
endif(${ARGOS_CONFIGURATION} MATCHES "\#define ARGOS_USE_DOUBLE")

In my repositories, I also read a whole bunch of other settings from config.h (see ARGoSBuildOptions.cmake for details). Once this issue is fixed, I will open a PR for dynamics3d model.

@ilpincy
Copy link
Owner

ilpincy commented Mar 14, 2021

A cleaner solution would be to augment the ARGoS pkgconfig file with the flags that are necessary for a correct compilation.

@allsey87
Copy link
Author

I don't have a strong opinion here. I've never had a close look at pkg-config although at a glance it doesn't seem to do anything that we can't already do in CMake. In any case, let me know once there is a solution for defining ARGOS_USE_DOUBLE and I'll open the PR with the 3D dynamics model after that.

@ilpincy
Copy link
Owner

ilpincy commented Mar 14, 2021

The issue with the purely CMake-based solution that matches config.h is that it must be copy-pasted in every sub-project. The pkg-config solution, instead, is portable and transparent: it automatically defines flags (for example -DARGOS_USE_DOUBE=ON) that are added upon detecting ARGoS. In this way, for example, we can also define compilation flags that Bullet-based plugins understand, without the need to use specialized #ifdef in the code.

@allsey87
Copy link
Author

allsey87 commented Mar 15, 2021

Fair enough, let's continue with pkg-config solution. I currently have:

prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib/argos3

Name: argos3_simulator
Description: ARGoS (multi-physics multi-robot simulator)
Version: 3.0.0-beta57
Cflags: -I${includedir} -Wno-unknown-pragmas 
Libs:  -Wl,--no-as-needed -L${libdir} -largos3core_simulator

How do we go about adding variables such as ARGOS_BUILD_FOR and ARGOS_USE_DOUBLE to this file and reading them back in from CMake?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants