mattgodbolt / seasocks

Simple, small, C++ embeddable webserver with WebSockets support
BSD 2-Clause "Simplified" License
734 stars 120 forks source link

Provide SeasocksConfig.cmake files when installed. #116

Closed iwanders closed 5 years ago

iwanders commented 5 years ago

Back again with more cmake improvements, I've finally got to the point where I had to make install rules for my tracing framework Scalopus. I had fixed using Seasocks through find_package from the build tree with https://github.com/mattgodbolt/seasocks/pull/108, but hadn't tried compiling against an installed version of Seasocks yet. When I tried that my find_package(Seasocks) instruction failed. The current make install of Seasocks only installs the headers and the libraries. This PR adds installing a SeasocksConfig.cmake which allows cmake to find the installed Seasocks through find_package. To do this we rely on install(EXPORT), this exports the targets in the Seasocks:: namespace as is convention.

This can be tested by setting -DCMAKE_INSTALL_PREFIX:PATH=/tmp/upstream_prefix/ during compilation, this prefixes the make install step with that folder. Current upstream installs:

./upstream_prefix/lib/libseasocks.a
./upstream_prefix/lib/libseasocks.so.1.4.1
./upstream_prefix/lib/libseasocks.so
./upstream_prefix/include/seasocks/Response.h
<snip>

With this change, prefix set to /tmp/with_change_prefix/:

./with_change_prefix/lib/libseasocks.a
./with_change_prefix/lib/libseasocks.so.1.4.1
./with_change_prefix/lib/libseasocks.so
./with_change_prefix/lib/cmake/Seasocks/SeasocksConfig-noconfig.cmake
./with_change_prefix/lib/cmake/Seasocks/SeasocksConfig.cmake
./with_change_prefix/lib/cmake/Seasocks/SeasocksConfigVersion.cmake
./with_change_prefix/include/seasocks/Response.h
<snip>

So we install both the SeasocksConfig.cmake file and the associated version file. This allows us to use the find_package command for Seasocks and also allows using the version field in this command. After using make install we can now use a CMakeLists.txt like:

cmake_minimum_required(VERSION 3.3)
find_package(Seasocks 1.4.0) # Requires at least version 1.4.0.
add_executable(my_server serve.cpp)
target_link_libraries(my_server Seasocks::seasocks)

With serve.cpp from anywhere on our system and cmake will be able to find the installed version of Seasocks.

codecov[bot] commented 5 years ago

Codecov Report

Merging #116 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #116   +/-   ##
=======================================
  Coverage   36.35%   36.35%           
=======================================
  Files          52       52           
  Lines        2247     2247           
=======================================
  Hits          817      817           
  Misses       1430     1430

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 125dd89...27ab414. Read the comment docs.

codecov[bot] commented 5 years ago

Codecov Report

Merging #116 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #116   +/-   ##
=======================================
  Coverage   36.35%   36.35%           
=======================================
  Files          52       52           
  Lines        2247     2247           
=======================================
  Hits          817      817           
  Misses       1430     1430

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 125dd89...27ab414. Read the comment docs.

offa commented 5 years ago

Thanks for this contribution @iwanders, great enhancement for Cmake integration! :+1:

iwanders commented 5 years ago

My pleasure, thanks for the quick turnaround. :+1: