This shows off transitive linking
Last active
June 19, 2020 11:30
-
-
Save knedlsepp/4de8a0dd233c2a39bbcb3a2f72962dae to your computer and use it in GitHub Desktop.
cmake-transitive-linking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void f(); | |
int main(int argc, char* argv[]){ | |
f(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
void low(const std::string&); | |
void f(){ | |
low("/tmp/asdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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