CMA-ES / libcmaes

libcmaes is a multithreaded C++11 library with Python bindings for high performance blackbox stochastic optimization using the CMA-ES algorithm for Covariance Matrix Adaptation Evolution Strategy
Other
321 stars 78 forks source link

Issue with CMake when including libcmaes as a subproject #239

Closed joaocandre closed 1 year ago

joaocandre commented 1 year ago

I've noticed an issue in the project's CMake configuration: while there are multiple issues reporting the libcmaes/cmaes_export.h: No such file or directory error message if the build instructions for the bundled Makefile setup are not properly followed, I found that this also happens in when building with CMake as a subproject:

src/
    libcmaes/
    some_other_project/
    <...>
build/
    <...>
CMakeLists.txt

and included through the add_subdirectory command:

add_subdirectory(libcmaes)
add_subdirectory(some_other_project)
# ...

The underlying cause is that the cmaes_export.h header is placed under the root (top-level) of the build directory (i.e. build/) and not on the build subdirectory (i.e. build/libcmaes/) which then prompts the failed include.

I'm far from a CMake expert, so there may be an underlying reason for this and better ways to solve this; one "dirty" way for other projects to workaround this to move build/include into build/libcmaes after configuration and before build; A better option is to replace CMAKE_BINARY_DIR with libcmaes_BINARY_DIR in the line 81 of src/CMakeLists.txt. In any case I think should either be solved at the source or at the very least addressed in the wiki/docs.