Skip to content

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

Open

Activity

  1. etr commented on Feb 21, 2022

    @etr
    Owner

    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?

  2. LeSpocky commented on Feb 22, 2022

    @LeSpocky
    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:

  3. brandonros commented on Feb 22, 2022

    @brandonros
    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?

  4. LeSpocky commented on Feb 22, 2022

    @LeSpocky
    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 http://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>
    )
  5. sunavlis commented on Jun 3, 2022

    @sunavlis

    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!

  6. LeSpocky commented on Jun 8, 2022

    @LeSpocky
    Contributor

    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:

    http://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.

  7. LeSpocky commented on Jun 9, 2022

    @LeSpocky
    Contributor

    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:

    http://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 http://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.

  8. hesa2020 commented on Mar 20, 2023

    @hesa2020

    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 )

  9. brandonros commented on Mar 20, 2023

    @brandonros
    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

  10. LeSpocky commented on Mar 20, 2023

    @LeSpocky
    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. 😉

  11. etr commented on Mar 20, 2023

    @etr
    Owner

    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?

  12. eli-schwartz commented on Mar 20, 2023

    @eli-schwartz

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions