Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 39 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.15)

set(libcmaes_VERSION 0.10.2)
set(libcmaes_VERSION 0.10.3)

project (libcmaes
VERSION ${libcmaes_VERSION}
Expand Down Expand Up @@ -28,6 +28,7 @@ option (LIBCMAES_BUILD_TESTS "build tests" OFF)
option (LIBCMAES_BUILD_EXAMPLES "build examples" ${LIBCMAES_TOP_LEVEL})
option (LIBCMAES_USE_OPENMP "Use OpenMP for multithreading" ON)
option (LIBCMAES_ENABLE_SURROG "support for surrogates" ON)
option (LIBCMAES_EIGEN_5 "Use Eigen v5" OFF)

# Offer the user the choice of overriding the installation directories
set (INSTALL_LIB_DIR lib${LIB_SUFFIX}
Expand Down Expand Up @@ -78,8 +79,44 @@ if(LIBCMAES_BUILD_PYTHON)
endif ()
endif()

if (LIBCMAES_EIGEN_5)
set (LIBCMAES_EIGEN_MIN_VERSION 5.0.0)
else ()
set (LIBCMAES_EIGEN_MIN_VERSION 3.4.0)
endif ()

find_package (Eigen3 REQUIRED)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an issue with this line
for eigen5 it doesn't work
can you put this line with the else() statement?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works for me:

cmake -S /path/to/eigen-5.0.1 -B /path/to/eigen-5.0.1/build

and

cmake .. -DCMAKE_INSTALL_PREFIX=~/.local/ -DLIBCMAES_BUILD_TESTS=ON -DLIBCMAES_EIGEN_5=ON -DEigen3_DIR=/path/to/eigen-5.0.1/build

What exactly is your error ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is because I build it directly with conan and add the requirements from our conan remote

def requirements(self):
        self.requires.add("eigen/5.0.0+0@jenkins/stable")

thus I have:

CMake Error at CMakeLists.txt:88 (find_package):

By not providing "FindEigen3.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Eigen3", but
CMake did not find one.

Could not find a package configuration file provided by "Eigen3" with any
of the following names:
Eigen3Config.cmake
eigen3-config.cmake

Add the installation prefix of "Eigen3" to CMAKE_PREFIX_PATH or set
"Eigen3_DIR" to a directory containing one of the above files. If "Eigen3"
provides a separate development package or SDK, be sure it has been
installed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you need the cmake -S step above when not using conan, as it does create the missing Eigen3 config files.
I am not familiar with the conan path, can you provide the full set of steps to reproduce ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your answer, I added :
cmake.definitions["Eigen3_DIR"]
in my conanfile and it worked !!!!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add it to the conan .py file ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my part, I would have say no, it's not mandatory


set (LIBCMAES_EIGEN_FOUND_VERSION ${Eigen3_VERSION})
if (NOT LIBCMAES_EIGEN_FOUND_VERSION AND DEFINED EIGEN3_VERSION_STRING)
set (LIBCMAES_EIGEN_FOUND_VERSION ${EIGEN3_VERSION_STRING})
endif ()

if (NOT LIBCMAES_EIGEN_FOUND_VERSION)
message (FATAL_ERROR "Could not determine the Eigen version exposed by package Eigen3.")
endif ()

find_package (Eigen3 3.4.0 REQUIRED)
set (LIBCMAES_EIGEN_LOCATION "")
if (DEFINED Eigen3_DIR AND NOT "${Eigen3_DIR}" STREQUAL "")
set (LIBCMAES_EIGEN_LOCATION "package dir: ${Eigen3_DIR}")
elseif (DEFINED EIGEN3_ROOT_DIR AND NOT "${EIGEN3_ROOT_DIR}" STREQUAL "")
set (LIBCMAES_EIGEN_LOCATION "root: ${EIGEN3_ROOT_DIR}")
elseif (DEFINED EIGEN3_INCLUDE_DIRS AND NOT "${EIGEN3_INCLUDE_DIRS}" STREQUAL "")
set (LIBCMAES_EIGEN_LOCATION "includes: ${EIGEN3_INCLUDE_DIRS}")
endif ()

if (LIBCMAES_EIGEN_LOCATION)
message (STATUS "Using Eigen ${LIBCMAES_EIGEN_FOUND_VERSION} (${LIBCMAES_EIGEN_LOCATION})")
else ()
message (STATUS "Using Eigen ${LIBCMAES_EIGEN_FOUND_VERSION}")
endif ()

if (LIBCMAES_EIGEN_FOUND_VERSION VERSION_LESS LIBCMAES_EIGEN_MIN_VERSION)
message (
FATAL_ERROR
"LIBCMAES_EIGEN_5=${LIBCMAES_EIGEN_5} requires Eigen >= ${LIBCMAES_EIGEN_MIN_VERSION}, "
"but found ${LIBCMAES_EIGEN_FOUND_VERSION}. Set Eigen3_DIR or CMAKE_PREFIX_PATH to an appropriate Eigen installation.")
endif ()

if (LIBCMAES_USE_OPENMP)
find_package (OpenMP QUIET)
Expand Down
30 changes: 25 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,41 @@ clone_folder: C:\projects\libcmaes
environment:
matrix:
- CMAKE_PLATFORM: "Visual Studio 14 2015"
EIGEN_VERSION: "3.3.4"
EIGEN_URL: "https://bitbucket.org/eigen/eigen/get/3.3.4.tar.gz"
EIGEN_ZIP: "3.3.4.tar.gz"
LIBCMAES_EIGEN_5: OFF
- CMAKE_PLATFORM: "Visual Studio 14 2015"
EIGEN_VERSION: "5.0.0"
EIGEN_URL: "https://gitlab.com/libeigen/eigen/-/archive/5.0.0/eigen-5.0.0.tar.gz"
EIGEN_ZIP: "eigen-5.0.0.tar.gz"
LIBCMAES_EIGEN_5: ON
- CMAKE_PLATFORM: "Visual Studio 14 2015 Win64"
EIGEN_VERSION: "3.3.4"
EIGEN_URL: "https://bitbucket.org/eigen/eigen/get/3.3.4.tar.gz"
EIGEN_ZIP: "3.3.4.tar.gz"
LIBCMAES_EIGEN_5: OFF
- CMAKE_PLATFORM: "Visual Studio 14 2015 Win64"
EIGEN_VERSION: "5.0.0"
EIGEN_URL: "https://gitlab.com/libeigen/eigen/-/archive/5.0.0/eigen-5.0.0.tar.gz"
EIGEN_ZIP: "eigen-5.0.0.tar.gz"
LIBCMAES_EIGEN_5: ON

install:
- cinstall: python
- appveyor-retry appveyor DownloadFile https://bitbucket.org/eigen/eigen/get/3.3.4.tar.gz
- 7z x 3.3.4.tar.gz -oc:\projects > nul
- 7z x c:\projects\3.3.4.tar -oc:\projects > nul
- cd c:\projects\eigen-eigen-5a0156e40feb
- appveyor-retry appveyor DownloadFile "%EIGEN_URL%" -FileName eigen.tar.gz
- 7z x eigen.tar.gz -oc:\projects > nul
- 7z x c:\projects\eigen.tar -oc:\projects > nul
- cd c:\projects
- for /d %%i in (eigen-*) do set EIGEN_DIR=%%i
- cd %EIGEN_DIR%
- mkdir build && cd build
- cmake -G "%CMAKE_PLATFORM%" -DCMAKE_INSTALL_PREFIX=c:\Libraries\eigen -DCMAKE_BUILD_TYPE=Release ..
- cmake --build . --config Release --target install

build_script:
- cd c:\projects\libcmaes
- mkdir build && cd build
- cmake -G "%CMAKE_PLATFORM%" -DCMAKE_INSTALL_PREFIX=c:\Libraries\libcmaes -DEigen3_DIR=c:\Libraries\eigen\share\eigen3\cmake -DBOOST_ROOT="C:/Libraries/boost_1_63_0" ..
- cmake -G "%CMAKE_PLATFORM%" -DCMAKE_INSTALL_PREFIX=c:\Libraries\libcmaes -DLIBCMAES_EIGEN_5=%LIBCMAES_EIGEN_5% -DEigen3_DIR=c:\Libraries\eigen\share\eigen3\cmake -DBOOST_ROOT="C:/Libraries/boost_1_63_0" ..
- cmake --build . --config Release --target install
- ctest -C Release
18 changes: 11 additions & 7 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import re, os, functools

from conan import ConanFile, tools
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
from conan.tools.files import load
from conan.tools.env import Environment
import os
import re

from conan.tools.scm import Git


class CmaesConan(ConanFile):
name = "libcmaes"

generators = "CMakeDeps"

# Optional metadata
license = "MIT"
author = "<Put your name here> <And your email here>"
Expand All @@ -23,18 +20,22 @@ class CmaesConan(ConanFile):

# Binary configuration
settings = "os", "compiler", "build_type", "arch"

generators = "CMakeDeps"
options = {
"shared": [True, False],
"openmp": [True, False],
"surrog": [True, False],
"enable_tests": [True, False],
"eigen_5": [True, False],
}
default_options = {
"shared": True,
"openmp": True,
"surrog": True,
"enable_tests": False,
"boost/*:without_python": False,
"eigen_5": False,
}

# Sources are located in the same place as this recipe, copy them to the recipe
Expand All @@ -55,8 +56,10 @@ def build_requirements(self):
self.test_requires("boost/1.85.0")

def requirements(self):
self.requires("eigen/3.4.0", transitive_headers=True)

if self.options.eigen_5:
self.requires("eigen/5.0.0")
else:
self.requires("eigen/3.4.0", transitive_headers=True)
if self.options.openmp and self.settings.os != "Windows":
self.requires("llvm-openmp/17.0.6", transitive_headers=True)

Expand Down Expand Up @@ -94,6 +97,7 @@ def generate(self):
tc.variables["LIBCMAES_ENABLE_SURROG"] = self.options.surrog
tc.variables["LIBCMAES_BUILD_PYTHON"] = self.options.enable_tests
tc.variables["LIBCMAES_BUILD_TESTS"] = self.options.enable_tests
tc.variables["LIBCMAES_EIGEN_5"] = self.options.eigen_5
tc.generate()

def build(self):
Expand Down
17 changes: 16 additions & 1 deletion libcmaes-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
include(CMakeFindDependencyMacro)
list (APPEND CMAKE_MODULE_PATH @CMAKE_CURRENT_SOURCE_DIR@/lib/cmake/libcmaes ${CMAKE_CURRENT_LIST_DIR})

find_dependency(Eigen3 @EIGEN3_VERSION@ REQUIRED)
find_dependency(Eigen3 REQUIRED)

set (_libcmaes_eigen_version "${Eigen3_VERSION}")
if (NOT _libcmaes_eigen_version AND DEFINED EIGEN3_VERSION_STRING)
set (_libcmaes_eigen_version "${EIGEN3_VERSION_STRING}")
endif ()

if (NOT _libcmaes_eigen_version)
message (FATAL_ERROR "Could not determine the Eigen version exposed by package Eigen3.")
endif ()

if (_libcmaes_eigen_version VERSION_LESS "@LIBCMAES_EIGEN_MIN_VERSION@")
message (
FATAL_ERROR
"libcmaes requires Eigen >= @LIBCMAES_EIGEN_MIN_VERSION@, but found ${_libcmaes_eigen_version}.")
endif ()


if(@LIBCMAES_USE_OPENMP@)
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ target_include_directories (
cmaes PUBLIC $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)

target_link_libraries (cmaes PUBLIC Eigen3::Eigen)

if (LIBCMAES_USE_OPENMP)
target_link_libraries (cmaes PUBLIC OpenMP::OpenMP_CXX)
endif ()
Expand Down
4 changes: 2 additions & 2 deletions src/ipopcmastrategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ namespace libcmaes
reset_search_state();

// Update remaining budget
int fevals_global = CMAStrategy<TCovarianceUpdate,TGenoPheno>::_nevals;
int fevals_remaining = fevals_max - fevals_global;
int fevals_global = CMAStrategy<TCovarianceUpdate,TGenoPheno>::_nevals;
int fevals_remaining = fevals_max - fevals_global;

// do not restart if max budget function calls is reached.
if (has_max_fevals && fevals_remaining <= 0)
Expand Down
13 changes: 12 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
find_package(gflags REQUIRED)

if (TARGET gflags::gflags)
set (LIBCMAES_GFLAGS_TARGET gflags::gflags)
elseif (TARGET gflags)
set (LIBCMAES_GFLAGS_TARGET gflags)
elseif (DEFINED GFLAGS_TARGET)
set (LIBCMAES_GFLAGS_TARGET ${GFLAGS_TARGET})
else ()
message (FATAL_ERROR "Could not determine a usable gflags target.")
endif ()

macro (cmaes_add_test name)
add_executable (${name} ${name}.cc)
target_link_libraries (${name} cmaes gflags)
target_link_libraries (${name} cmaes ${LIBCMAES_GFLAGS_TARGET})
if(MSVC)
target_compile_definitions(${name} PUBLIC _USE_MATH_DEFINES)
endif()
Expand Down
Loading