Improve CMake integration for add_subdirectory consumers#15
Open
ros-dorian wants to merge 5 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi @serhmarch , thank you for sharing your work! Really useful and well written.
I encountered a few quirks while integrating your library in a project using CMake's
add_subdirectory.Description
Although ModbusLib builds fine standalone, integrating it as a subproject (git submodule, cmake
add_subdirectory) is not as straight forward for the following reasons:Modbus_config.his generated into the source tree, leading to a dirty submodule statusBUILD_SHARED_LIBS. No fine control possibleSolution
Here are the fixes that I made to address each of the points above:
target_include_directoriesfor the modbus target with the relevant pathsMB_BUILD_SHAREDto selectively build shared/static libraries. It defaults toBUILD_SHARED_LIBSto not break current behavior.Result
Here is a concrete example. The code below integrates the ModbusLib inside an existing CMake project, forcing static linkage:
Now with the fixes applied:
Notes
modbus.profile, looking at the history it does not look like it is actively maintained. Let me know if it still needs to be supported (I'm not really familiar with QMake however).Environment
ModbusLib v0.5.0
Windows 11, Visual Studio 2026