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

How to include externally using CMake #17

Open
ferdymercury opened this issue Nov 15, 2021 · 1 comment
Open

How to include externally using CMake #17

ferdymercury opened this issue Nov 15, 2021 · 1 comment

Comments

@ferdymercury
Copy link

ferdymercury commented Nov 15, 2021

Hello, thanks for the repository!

Is there a clean way to include it from other projects, using find_package(Modbus) or something similar, instead of hard-coding the paths? (I installed it using apt)

If yes, could this info be added to the README ?

@ferdymercury
Copy link
Author

Ok, I managed the following, using https://github.com/ferdymercury/cmake-modules/blob/main/FindModbus.cmake:

find_package(Modbus REQUIRED)
set (modbuspp_DIR "/usr/local/lib/modbuspp/cmake/" CACHE STRING "modbuspp cmake folder")
find_package(modbuspp REQUIRED)

add_executable(foo foo.cpp)
target_compile_options(foo PRIVATE)
target_include_directories(foo PRIVATE ${MODBUS_INCLUDE_DIR} ${MODBUSPP_INCLUDE_DIRS})
target_link_libraries(foo PUBLIC ${MODBUSPP_LIBRARIES})
add_test(
    NAME foo
    COMMAND foo ?
)

I think it would be nicer if the CMake file would automatically define the interface_directories and libraries to include, instead of having to apply those manually in your targets.

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

No branches or pull requests

1 participant