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 doesn't build a library #72

Open
oedze opened this issue Nov 11, 2024 · 7 comments
Open

CMakeLists doesn't build a library #72

oedze opened this issue Nov 11, 2024 · 7 comments

Comments

@oedze
Copy link

oedze commented Nov 11, 2024

The CMakeLists is now used to create a few executables with different settings.

It can't however be used as a static library right now which is usefull for embedded devices.

being able to do

add_subdirectory(path/to/nanoMODBUS)

add_executable(myproject main.c)

target_link_libaries(myproject PRIVATE nanomodbus)

in our main projects CMakeLists.txt would be ideal for our scenario.

To be able to do this requires some change to the current CMakeLists.txt. If anyone's interested i can make a pull request.
If i do this i would also prefer to move the nanomodbus.h to a include folder.

@debevv
Copy link
Owner

debevv commented Nov 25, 2024

Hi, the CMakeLists in the repo was never meant to be used by the user, really is there just to build the various test/examples that were useful to me during development.
The "official" way to use nanomodbus is to copy the .c and .h in your codebase and compile everything together.

@donghoonpark
Copy link
Contributor

How about supporting both approaches?
Adding nanomodbus as a library in CMake and compiling test examples with the library link would be the easiest way to achieve this.
Furthermore, for the project's CI, adopting a unit testing framework is also worth considering. If you don’t have time to implement it, I’d be happy to create a PR for it. Is there any particular reason you don’t want to make it a CMake-integrable library?

@debevv
Copy link
Owner

debevv commented Dec 12, 2024

No reason really, I just think that dropping the sources in the codebase is the simplest option. Anyway, if you find it useful, I will add a couple of lines in the CMakeLists to build a library.
Regarding the tests, what do you mean with a unit testing framework?

@debevv
Copy link
Owner

debevv commented Dec 12, 2024

Added library target in a1705c0

@donghoonpark
Copy link
Contributor

I really appreciate your quick feedback.
Library definition is quite useful when I use library with internet loading cmake command such as FetchContent.
Regarding the unittest framework, to build test cases with minimal code and integrate them easily into the development environment, frameworks such as GoogleTest or Catch2 are commonly used, as they offer efficiency and compatibility.

@oedze
Copy link
Author

oedze commented Dec 17, 2024

Great! I can't test it right now, but if i include the subdirectory using add_subdirectory call, it will also create all the extra libraries right?
to allow the use of the header files in the libraries the target_include_directories(nanomodbus PUBLIC .) can be added

or even better (in my opionin) move the nanomodbus.h file to a folder called include/nanomodbus/ If you then do target_include_directories(nanomodbus PUBLIC include) you can always include #include "nanomodbus/nanomodbus.h" in your c/c++ file

@donghoonpark
Copy link
Contributor

donghoonpark commented Dec 17, 2024

nanomodbus have no extra library. If you call add_subdirectory, it gives you nanomodbus library suite. I already made a PR #79 that includes header file in library suite as well. Until the PR merge into master, you can refer the example HERE.

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

3 participants