Skip to content

Instantly share code, notes, and snippets.

@knedlsepp
Last active June 19, 2020 11:30
Show Gist options
  • Save knedlsepp/4de8a0dd233c2a39bbcb3a2f72962dae to your computer and use it in GitHub Desktop.
Save knedlsepp/4de8a0dd233c2a39bbcb3a2f72962dae to your computer and use it in GitHub Desktop.
cmake-transitive-linking

This shows off transitive linking

cmake_minimum_required(VERSION 3.14)
project(asdf LANGUAGES CXX)
find_package(Boost REQUIRED COMPONENTS thread)
add_library(low SHARED low.cpp)
target_link_libraries(low PRIVATE Boost::thread)
add_library(high SHARED high.cpp)
target_link_libraries(high PRIVATE low)
add_executable(exe exe.cpp)
target_link_libraries(exe PRIVATE high)
install(TARGETS low high exe)
with import <nixpkgs> {};
pkgs.stdenv.mkDerivation {
name = "transitive-cmake";
src = builtins.fetchGit ./.;
nativeBuildInputs = with pkgs; [
cmake
];
buildInputs = with pkgs; [
boost
];
cmakeFlags = [
"-DCMAKE_VERBOSE_MAKEFILE=ON"
];
}
void f();
int main(int argc, char* argv[]){
f();
}
#include <string>
void low(const std::string&);
void f(){
low("/tmp/asdf");
}
#include <boost/chrono.hpp>
#include <boost/thread.hpp>
#include <iostream>
#include <string>
void work() {
try {
for (int i = 0; i < 5; ++i) {
sleep(1);
std::cout << i << '\n';
}
} catch (boost::thread_interrupted &) {
}
}
void low(const std::string &f) {
boost::thread t{work};
sleep(3);
t.interrupt();
t.join();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment