Skip to content

CMake build system support #24

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.swp
out/*
cscope.*
.vscode/
56 changes: 56 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
cmake_minimum_required(VERSION 3.2)
set(TARGET_NAME "libnop")
project(${TARGET_NAME} LANGUAGES CXX)

# Set modules path
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)

# Build tests
option(LIBNOP_BUILD_TESTS "Build libnop tests" OFF)
# Build examples
option(LIBNOP_BUILD_EXAMPLES "Build libnop examples" OFF)

add_library(${TARGET_NAME} INTERFACE)
# Set C++14 version
if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
target_compile_features(${TARGET_NAME} INTERFACE cxx_generic_lambdas)
else()
target_compile_features(${TARGET_NAME} INTERFACE cxx_std_14)
endif()

target_include_directories(${TARGET_NAME} INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:include>
)

# Tests
if(LIBNOP_BUILD_TESTS)
# Add CMake testing infrastructure
include(CTest)
enable_testing()
add_subdirectory(test)
endif()

# Examples
if(LIBNOP_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

include(GNUInstallDirs)
install(TARGETS ${TARGET_NAME}
EXPORT "${TARGET_NAME}Config"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME}")
export(TARGETS
${TARGET_NAME}
FILE "${config_install_dir}/${TARGET_NAME}Config.cmake"
)
install(EXPORT
"${TARGET_NAME}Config"
DESTINATION "${config_install_dir}"
)
Loading