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 install #24

Merged
merged 1 commit into from
Mar 29, 2022
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
85 changes: 85 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
cmake_minimum_required(VERSION 3.3)
project(lbfgspp VERSION 0.1.1 LANGUAGES CXX)

# + ----------------- +
# | BUILDING SETTINGS |
# + ----------------- +

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)

# + ----------------- +
# | COMPILATION FLAGS |
# + ----------------- +

include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-Wall WALL_SUPPORTED)
if(${WALL_SUPPORTED})
add_compile_options(-Wall)
endif()

# + --------------- +
# | LBFGSpp LIBRARY |
# + --------------- +

add_library(lbfgspp INTERFACE)

# + -------- +
# | INCLUDES |
# + -------- +

target_include_directories(lbfgspp INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
)

# + ----------------------- +
# | FIND EXTERNAL LIBRARIES |
# + ----------------------- +

find_package(Eigen3 3.0 REQUIRED)
target_link_libraries(lbfgspp INTERFACE Eigen3::Eigen)
message("-- Eigen3 version: " ${EIGEN3_VERSION_STRING})

# + ------------ +
# | INSTALLATION |
# + ------------ +

# Copy headers folder
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION include
)
# Create an export set
install(TARGETS lbfgspp EXPORT lbfgsppTargets)

include(CMakePackageConfigHelpers)
# Version file
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/lbfgspp-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
# Config file
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/lbfgspp-config.cmake
INSTALL_DESTINATION lib/cmake/lbfgspp
)
# Targets files
export(
EXPORT lbfgsppTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/lbfgspp-targets.cmake
)
install(
EXPORT lbfgsppTargets
FILE lbfgspp-targets.cmake
DESTINATION lib/cmake/lbfgspp
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/lbfgspp-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/lbfgspp-config-version.cmake
DESTINATION lib/cmake/lbfgspp
)
6 changes: 6 additions & 0 deletions config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Dependencies
include(CMakeFindDependencyMacro)

find_dependency(Eigen3 3.0 REQUIRED)

include(${CMAKE_CURRENT_LIST_DIR}/lbfgspp-targets.cmake)