From 70da99e4f70845da37ae368c4788ecc18546792d Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 28 Mar 2020 17:19:43 +0000 Subject: WIP: restructure A stupid attempt to reduce code duplication led me to believe that all the scripts could use _a bit_ of refactoring. This is going to be a major pain (factoring out all the things), which I'll take gladly. All the links and usage examples are broken right now, but nobody cares, so whatevs. --- examples/boost/CMakeLists.txt | 14 ++++++++++++++ examples/boost/foo.cpp | 11 +++++++++++ examples/dynamic/CMakeLists.txt | 16 ++++++++++++++++ examples/dynamic/baz.cpp | 7 +++++++ examples/dynamic/baz.hpp | 9 +++++++++ examples/dynamic/foo.cpp | 6 ++++++ examples/simple/CMakeLists.txt | 12 ++++++++++++ examples/simple/foo.cpp | 6 ++++++ examples/static/CMakeLists.txt | 16 ++++++++++++++++ examples/static/bar.cpp | 7 +++++++ examples/static/bar.hpp | 3 +++ examples/static/foo.cpp | 6 ++++++ 12 files changed, 113 insertions(+) create mode 100644 examples/boost/CMakeLists.txt create mode 100644 examples/boost/foo.cpp create mode 100644 examples/dynamic/CMakeLists.txt create mode 100644 examples/dynamic/baz.cpp create mode 100644 examples/dynamic/baz.hpp create mode 100644 examples/dynamic/foo.cpp create mode 100644 examples/simple/CMakeLists.txt create mode 100644 examples/simple/foo.cpp create mode 100644 examples/static/CMakeLists.txt create mode 100644 examples/static/bar.cpp create mode 100644 examples/static/bar.hpp create mode 100644 examples/static/foo.cpp (limited to 'examples') diff --git a/examples/boost/CMakeLists.txt b/examples/boost/CMakeLists.txt new file mode 100644 index 0000000..8c076c9 --- /dev/null +++ b/examples/boost/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.5) # for Boost::* imported targets + +project(example_boost) + +include(../../common.cmake) + +find_package(Boost REQUIRED COMPONENTS filesystem) +add_executable(foo foo.cpp) +target_link_libraries(foo PRIVATE Boost::disable_autolinking Boost::filesystem) + +install(TARGETS foo RUNTIME DESTINATION bin) +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + install(FILES "$" DESTINATION bin OPTIONAL) +endif() diff --git a/examples/boost/foo.cpp b/examples/boost/foo.cpp new file mode 100644 index 0000000..3bd0326 --- /dev/null +++ b/examples/boost/foo.cpp @@ -0,0 +1,11 @@ +#include + +#include + +int main(int argc, char* argv[]) { + std::cout << "Hello from " + << boost::filesystem::absolute(boost::filesystem::path{argv[0]}) + .string() + << "!\n"; + return 0; +} diff --git a/examples/dynamic/CMakeLists.txt b/examples/dynamic/CMakeLists.txt new file mode 100644 index 0000000..4602adb --- /dev/null +++ b/examples/dynamic/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.1) + +project(example_dynamic) + +include(../../common.cmake) + +add_library(baz SHARED baz.cpp) +target_include_directories(baz PUBLIC .) + +add_executable(foo foo.cpp) +target_link_libraries(foo PRIVATE baz) + +install(TARGETS foo baz RUNTIME DESTINATION bin LIBRARY DESTINATION lib) +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + install(FILES "$" "$" DESTINATION bin OPTIONAL) +endif() diff --git a/examples/dynamic/baz.cpp b/examples/dynamic/baz.cpp new file mode 100644 index 0000000..d108ae3 --- /dev/null +++ b/examples/dynamic/baz.cpp @@ -0,0 +1,7 @@ +#include "baz.hpp" + +#include + +void baz() { + std::cout << "baz\n"; +} diff --git a/examples/dynamic/baz.hpp b/examples/dynamic/baz.hpp new file mode 100644 index 0000000..2fc9b2a --- /dev/null +++ b/examples/dynamic/baz.hpp @@ -0,0 +1,9 @@ +#pragma once + +#ifdef _MSC_VER +#define DLLEXPORT __declspec(dllexport) +#else +#define DLLEXPORT +#endif + +DLLEXPORT void baz(); diff --git a/examples/dynamic/foo.cpp b/examples/dynamic/foo.cpp new file mode 100644 index 0000000..b7d9986 --- /dev/null +++ b/examples/dynamic/foo.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + baz(); + return 0; +} diff --git a/examples/simple/CMakeLists.txt b/examples/simple/CMakeLists.txt new file mode 100644 index 0000000..4f8859e --- /dev/null +++ b/examples/simple/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.1) + +project(example_simple) + +include(../../common.cmake) + +add_executable(foo foo.cpp) + +install(TARGETS foo RUNTIME DESTINATION bin) +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + install(FILES "$" DESTINATION bin OPTIONAL) +endif() diff --git a/examples/simple/foo.cpp b/examples/simple/foo.cpp new file mode 100644 index 0000000..b9d3132 --- /dev/null +++ b/examples/simple/foo.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + std::cout << "foo\n"; + return 0; +} diff --git a/examples/static/CMakeLists.txt b/examples/static/CMakeLists.txt new file mode 100644 index 0000000..8a6acb8 --- /dev/null +++ b/examples/static/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.1) + +project(example_static) + +include(../../common.cmake) + +add_library(bar bar.cpp) +target_include_directories(bar PUBLIC .) + +add_executable(foo foo.cpp) +target_link_libraries(foo PRIVATE bar) + +install(TARGETS foo bar RUNTIME DESTINATION bin ARCHIVE DESTINATION lib) +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + install(FILES "$" DESTINATION bin OPTIONAL) +endif() diff --git a/examples/static/bar.cpp b/examples/static/bar.cpp new file mode 100644 index 0000000..37aa9b5 --- /dev/null +++ b/examples/static/bar.cpp @@ -0,0 +1,7 @@ +#include "bar.hpp" + +#include + +void bar() { + std::cout << "bar\n"; +} diff --git a/examples/static/bar.hpp b/examples/static/bar.hpp new file mode 100644 index 0000000..a3ea4c1 --- /dev/null +++ b/examples/static/bar.hpp @@ -0,0 +1,3 @@ +#pragma once + +void bar(); diff --git a/examples/static/foo.cpp b/examples/static/foo.cpp new file mode 100644 index 0000000..c6355a2 --- /dev/null +++ b/examples/static/foo.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + bar(); + return 0; +} -- cgit v1.2.3