Skip to content

Commit

Permalink
Merge pull request #4 from Skaginn3x/add_install
Browse files Browse the repository at this point in the history
add install
  • Loading branch information
magni-mar authored Feb 29, 2024
2 parents 3784168 + 7abff22 commit d2175b7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ cmake-build*
vcpkg/
.vscode
CMakeUserPresets.json
*.kdev4
*.kdev4
install/*
54 changes: 53 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,23 @@ add_library(modbus
src/error.cpp)

target_link_libraries(modbus PUBLIC asio)
target_include_directories(modbus PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_include_directories(modbus PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

include(GNUInstallDirs)

install(TARGETS modbus
EXPORT modbusTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/ DESTINATION include)


if (BUILD_EXAMPLES)
add_subdirectory(examples)
Expand All @@ -56,3 +72,39 @@ add_custom_target(
--dry-run
${ALL_SOURCE_FILES}
)



# Let's go ahead and install everything properly
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

set(modbus_PACKAGE_NAME modbus)
set(modbus_INSTALL_CMAKEDIR ${CMAKE_INSTALL_DATADIR}/${modbus_PACKAGE_NAME})

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${modbus_PACKAGE_NAME}ConfigVersion.cmake"
VERSION ${CMAKE_PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/${modbus_PACKAGE_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${modbus_PACKAGE_NAME}Config.cmake"
INSTALL_DESTINATION ${modbus_INSTALL_CMAKEDIR}
)

install(EXPORT ${modbus_PACKAGE_NAME}Targets DESTINATION ${modbus_INSTALL_CMAKEDIR})
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${modbus_PACKAGE_NAME}ConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${modbus_PACKAGE_NAME}Config.cmake"
DESTINATION ${modbus_INSTALL_CMAKEDIR}
)

install(
EXPORT ${modbus_PACKAGE_NAME}Targets
NAMESPACE modbus::
DESTINATION ${modbus_INSTALL_CMAKEDIR}
)

3 changes: 2 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
{
"name": "conf-gcc",
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x64-linux-gcc"
"VCPKG_TARGET_TRIPLET": "x64-linux-gcc",
"CMAKE_INSTALL_PREFIX": "${fileDir}/install/${presetName}"
},
"inherits": [
"conf-base"
Expand Down
Empty file added modbusConfig.cmake.in
Empty file.

0 comments on commit d2175b7

Please sign in to comment.