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

CMakeLists.txt install library #25

Open
wants to merge 8 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
56 changes: 41 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.1)
project(modbuspp)
project(modbuspp VERSION 0.3.1)
set(CMAKE_CXX_STANDARD 11)


Expand All @@ -10,19 +10,45 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
endif()

# BUILD INTERFACE LIB
install(FILES
"modbus.h"
DESTINATION
include/modbuspp
add_library(modbuspp_lib INTERFACE)
target_include_directories(modbuspp_lib INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/modbus.h>
$<INSTALL_INTERFACE:include>
)

include(CMakePackageConfigHelpers)
install(TARGETS modbuspp_lib
EXPORT modbusppTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include )

write_basic_package_version_file("modbusppConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/modbusppConfig.cmake.in"
"${PROJECT_BINARY_DIR}/modbusppConfig.cmake"
INSTALL_DESTINATION lib/cmake/modbuspp
)
install(EXPORT modbusppTargets DESTINATION lib/cmake/modbuspp)
install(FILES "${PROJECT_BINARY_DIR}/modbusppConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/modbusppConfig.cmake"
DESTINATION lib/cmake/modbuspp)
install(FILES ${PROJECT_SOURCE_DIR}/modbus.h DESTINATION include)

# BUILD EXAMPLE
set(EXAMPLE_FILES example/example.cpp)
add_executable(modbuspp_example ${EXAMPLE_FILES})
target_compile_definitions(modbuspp_example
PUBLIC
ENABLE_MODBUSPP_LOGGING
)
target_include_directories(modbuspp_example
PUBLIC
.
)
IF(BUILD_EXAMPLE)
Copy link
Owner

Choose a reason for hiding this comment

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

Could you please update the README?

set(EXAMPLE_FILES example/example.cpp)
add_executable(modbuspp_example ${EXAMPLE_FILES})
target_compile_definitions(modbuspp_example
PUBLIC
ENABLE_MODBUSPP_LOGGING
)
target_include_directories(modbuspp_example
PUBLIC
.
)
ENDIF()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MODBUS++ [(MODBSPP)](https://github.com/fanzhe98/modbuspp.git) v0.3
# MODBUS++ [(MODBSPP)](https://github.com/fanzhe98/modbuspp.git) v0.3.1
[![CMake](https://github.com/fanzhe98/modbuspp/actions/workflows/cmake.yml/badge.svg)](https://github.com/fanzhe98/modbuspp/actions/workflows/cmake.yml)
# 0 Info, Updates and Discalimer
## 0.0 Info
Expand Down
4 changes: 4 additions & 0 deletions cmake/modbusppConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/modbusppTargets.cmake")
check_required_components("@PROJECT_NAME@")
Copy link
Owner

Choose a reason for hiding this comment

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

[nit] please insert a new line