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 cmake build support #66

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add cmake build support #66

wants to merge 3 commits into from

Conversation

abhaybd
Copy link

@abhaybd abhaybd commented Jan 11, 2024

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!

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

Successfully merging this pull request may close these issues.

1 participant