Add cmake build support
OptimLib doesn't provide any automated method for users to download and link against it, and in my opinion, doesn't integrate well into modern build systems. For example, my preferred method for including dependencies is using FetchContent with CMake to download and link against the dependencies without having to install it to the system, but this is not cleanly possible with OptimLib. Therefore, this PR adds a small CMakeLists.txt to this project, making it very easy to include in other CMake projects without having to build and install manually from source.
With this PR, building the Ackley example with CMake is as easy as:
cmake_minimum_required(VERSION 3.13)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(foo LANGUAGES CXX)
include(FetchContent)
FetchContent_Declare(
Eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.4.0
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)
FetchContent_MakeAvailable(Eigen)
FetchContent_Declare(
Optim
GIT_REPOSITORY https://github.com/abhaybd/optim.git
GIT_TAG add-cmake
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)
FetchContent_MakeAvailable(Optim)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE Eigen3::Eigen optim)
Note that this example pulls from my fork, but if this PR is merged it should pull from the original repo and the main branch.
I'm not sure that I recreated all the compile-time flags properly, as the configure script was rather long, but I can confirm that this example does build and run correctly. If any flags aren't set properly, I'd welcome any modifications/fixes!