palacaze / sigslot

A simple C++14 signal-slots implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sigslot as a submodule, how to use the CMake files?

stijnfrishert opened this issue · comments

I've got SigSlot added as a git submodule to my project (in root/dependencies/sigslot).

I'm currently using just add_subdirectory() to import all sigslot's targets, but that's not really sustainable. I'd very much like to use modern CMake, find_package(), and depend on SigSlot, but it's a bit unclear to me how to use the CMake files provided by this library.

Am I supposed to write my own FindPalSigSlot.cmake that somehow uses PalSigslotConfig.cmake.in and SigslotUtils.cmake? The readme makes me believe I must build and install...but why? Isn't this a header-only library?

You do not need to build anything to use Sigslot.
If you use a git submodule, add_subdirectory is the way to go.

cmake_minimum_required(VERSION 3.15)
project(test_sig LANGUAGES CXX)

# The first two lines are optional, they deactivate example and test targets
#option(SIGSLOT_COMPILE_EXAMPLES "" OFF)
#option(SIGSLOT_COMPILE_TESTS "" OFF)
add_subdirectory(root/dependencies/sigslot)

add_executable(test_sig main.cpp)
target_link_libraries(test_sig PRIVATE Pal::Sigslot)

And in the C++ files, you can #include <sigslot/whatever> directly. This is already "Modern CMake".

#include <iostream>
#include <sigslot/signal.hpp>

int main(int argc, char **argv) {
    sigslot::signal<int> s;
    s.connect([](int i) { std::cout << "Got a " << i << std::endl;  });
    s(2);
    return 0;
}

Shameless plug, if you want to explore "Modern CMake" usage, my other project Gateau may be of interest to you.

Thank you for replying 👍

Alright, then I’m actually doing it the correct way already. I’ll take a look at gateau as well, seems interesting 😄