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

Include CMakeLists.txt to make it easier to import into other projects? #261

Open
brandonros opened this issue Feb 21, 2022 · 12 comments
Open

Comments

@brandonros
Copy link

brandonros commented Feb 21, 2022

I don't think this is enough: https://github.com/etr/libhttpserver/blob/master/cmakemodule/FindLibHttpServer.cmake

Something like this: https://github.com/curl/curl/blob/master/CMakeLists.txt

https://github.com/janbar/openssl-cmake/blob/master/CMakeLists.txt

@etr
Copy link
Owner

etr commented Feb 21, 2022

Not too familiar with CMake unfortunately to give an expert comment on this, but aren't the ones you pointed basically the configurations to build those libraries.

All that we wanted to provide with FindLibHttpServer.cmake was a way to find/import the library when installed in the standard paths. Is this currently failing for you?

@LeSpocky
Copy link
Contributor

Not too familiar with CMake unfortunately to give an expert comment on this, but aren't the ones you pointed basically the configurations to build those libraries.

Correct.

All that we wanted to provide with FindLibHttpServer.cmake was a way to find/import the library when installed in the standard paths. Is this currently failing for you?

You don't need that file btw. This is (more or less) how I do it currently:

find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_HTTPSERVER REQUIRED IMPORTED_TARGET
				  libhttpserver>=0.19)
pkg_check_modules(PC_MICROHTTPD REQUIRED IMPORTED_TARGET
				  libmicrohttpd>=0.9.52)
# and later

target_link_libraries(foo
	PRIVATE
		PkgConfig::PC_HTTPSERVER
		PkgConfig::PC_MICROHTTPD
)

If all is in standard paths, you can even avoid pkg-config and just use find_library() and link httpserver and you're done.

However if libhttpserver wants to provide a CMake find module, then this should guide you to update to a modern one:

@brandonros
Copy link
Author

I don't know if it's wrong or right but I typically have issues with find_package(PkgConfig REQUIRED) and instead just set up projects to have a deps/ folder with git submodules and then do add_subdirectory

How do you pass the path of libhttpserver for example in that situation?

@LeSpocky
Copy link
Contributor

I don't know if it's wrong or right but I typically have issues with find_package(PkgConfig REQUIRED) and instead just set up projects to have a deps/ folder with git submodules and then do add_subdirectory

Which only works if all those deps are projects built with CMake. This is not the case with libhttpserver. You would have to add all those CMakeLists.txt files and this would mean either supporting an additional build system or switching over from autotools. The FindLibHttpServer.cmake is about a very different thing, not building libhttpserver with CMake, but using an already built and installed libhttpserver from other CMake projects.

How do you pass the path of libhttpserver for example in that situation?

You have to distinguish between different types of builds:

  1. libhttpserver is installed in system or sysroot (for cross builds), this is the easy way, you can do it as I have described before

  2. you want to build libhttpserver as part of your app (from a Linux distribution packaging point of view I would not recommend this) or in a superbuild along with your app, this is more complicated. I could manage to build in a superbuild with the ExternalProject CMake module, see this for example (copied from my personal superbuild project):

ExternalProject_Add(libhttpserver
	DEPENDS libmicrohttpd
	PREFIX sysroot-prefix
	GIT_REPOSITORY https://github.com/etr/libhttpserver.git
	GIT_TAG master
	UPDATE_DISCONNECTED 1
	CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR>
		--$<IF:$<CONFIG:DEBUG>,enable,disable>-debug --disable-examples
	TEST_COMMAND make check
	TEST_EXCLUDE_FROM_MAIN 1
	STEP_TARGETS update install test
)

ExternalProject_Get_Property(libhttpserver SOURCE_DIR)
ExternalProject_Add_Step(libhttpserver bootstrap
	COMMAND				./bootstrap
	DEPENDEES			update
	DEPENDERS			configure
	BYPRODUCTS			<SOURCE_DIR>/configure
	WORKING_DIRECTORY	<SOURCE_DIR>
)

@sunavlis
Copy link

sunavlis commented Jun 3, 2022

Hi LeSpocky

I try to setup my application using cMake and ExternalProject to build libhttpserver. I started with your example above, but I'm not able to link correctly to the libmicrohttpd.

Is your superbuild project available some where? Or could you share the CMakeLists of it? This would be nice and help me to setup my own project.
Thanks!

@LeSpocky
Copy link
Contributor

LeSpocky commented Jun 8, 2022

Is your superbuild project available some where?

No, and it won't be, at least not that project I use in production.

Or could you share the CMakeLists of it? This would be nice and help me to setup my own project. Thanks!

I will share a generic superbuild project with example code. As a first step I created a small project based on the hello world from libhttpserver examples:

https://github.com/LeSpocky/glowing-tribble

You can already build that without a superbuild, if recent libhttpserver is installed on your build host (which probably is not the case). I will provide a separate superbuild project as soon as I find time for that.

@LeSpocky
Copy link
Contributor

LeSpocky commented Jun 9, 2022

I will share a generic superbuild project with example code. As a first step I created a small project based on the hello world from libhttpserver examples:

https://github.com/LeSpocky/glowing-tribble

You can already build that without a superbuild, if recent libhttpserver is installed on your build host (which probably is not the case). I will provide a separate superbuild project as soon as I find time for that.

@schnudi See https://github.com/LeSpocky/glowing-tribble-build for a working superbuild including some explanation on how it works in its README.md file. Hope that helps.

@hesa2020
Copy link

This library seems great however not having a cmakelists is a bummer for me.
I like my projects to be cloned and my ide to auto compile everything for me and not having to do manually compile libraries and making sure they get found... ( FindCmake rarely works for me when swaping from a platform to another and its something that makes me lose time )

@brandonros
Copy link
Author

maybe we can combine and write Bazel for it?

i agree though, i thought bundling cmakelist was pretty standard for most c/c++ projects

@LeSpocky
Copy link
Contributor

@hesa2020 @brandonros What you essentially suggest is libhttpserver should either switch its build system to something different or add the burden to maintain two or more different build systems at the same time for a project which can be used fine with either autotools or by importing the pkgconfig file it distributes. 😉

@etr
Copy link
Owner

etr commented Mar 20, 2023

I like my projects to be cloned and my ide to auto compile everything for me and not having to do manually compile libraries and making sure they get found... ( FindCmake rarely works for me when swaping from a platform to another and its something that makes me lose time )

i agree though, i thought bundling cmakelist was pretty standard for most c/c++ projects

I agree with @LeSpocky here and wonder if I am missing the point you are both trying to make in the quotes above. How do you manage with libraries that are not compiled with CMake but use other build systems (i.e. autotools, Meson, etc.)? I guess CMake is popular but not the only one. I guess you just don't use them?

@eli-schwartz
Copy link

There are a few options. You could use something like conan/vcpkg, or build on a linux distro that provides static versions of packages. In both cases, you just import a prebuilt library via e.g. pkg-config or FindFooBar.cmake. You could also learn to use ExternalProject_Add for cmake. :)

meson has an externalproject module that's intended to support generic ./configure && make && make install style projects, if it follows the GNU coding standards for the ./configure interface (as of course all autotools projects do).

i agree though, i thought bundling cmakelist was pretty standard for most c/c++ projects

Standard? That's an intimidating term. It's certainly common, it's one of the 3 major choices after all. More common for C++ than for C, however. Also, more common on Windows than on Unix.

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

6 participants