From 0b5a8e4c89810d9a60bf01243a7b54c9dd107871 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Wed, 28 Mar 2018 22:48:45 +0200 Subject: [PATCH] More examples --- .gitlab-ci.yml | 8 ------- examples/root-example-dict/CMakeLists.txt | 3 +++ examples/root-example/CMakeLists.txt | 24 +++++++++++++++----- specifics/ROOT.md | 27 +++++++---------------- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5cf688f..4d157e9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,14 +13,6 @@ before_script: #- gitbook fetch pre # fetch latest pre-release version #- gitbook fetch 2.6.7 # fetch specific version -test: - stage: test - script: - - gitbook build . public # build to public path - only: - - branches # this job will affect only the 'master' branch - except: - - master # the 'pages' job will deploy and build your site to the 'public' path pages: diff --git a/examples/root-example-dict/CMakeLists.txt b/examples/root-example-dict/CMakeLists.txt index 6024d72..3383d37 100644 --- a/examples/root-example-dict/CMakeLists.txt +++ b/examples/root-example-dict/CMakeLists.txt @@ -1,3 +1,5 @@ + +## [main] cmake_minimum_required(VERSION 3.1) project(RootExampleDict LANGUAGES CXX) @@ -20,5 +22,6 @@ root_generate_dictionary(G__MyExample MyExample.h LINKDEF SimpleLinkDef.h) add_library(MyExample SHARED MyExample.cxx MyExample.h G__MyExample.cxx) target_link_libraries(MyExample PUBLIC ROOT::Core) +## [main] #enable_testing() #add_test(NAME MyExample COMMAND ) diff --git a/examples/root-example/CMakeLists.txt b/examples/root-example/CMakeLists.txt index 4c28309..28fa0e7 100644 --- a/examples/root-example/CMakeLists.txt +++ b/examples/root-example/CMakeLists.txt @@ -1,20 +1,32 @@ + +## [main] cmake_minimum_required(VERSION 3.1) -project(RootExample LANGUAGES CXX) +project(RootSimpleExample LANGUAGES CXX) +## [find_package] find_package(ROOT CONFIG REQUIRED) +## [find_package] message(STATUS "Found ROOT: ${ROOT_VERSION} at ${ROOT_DIR}") +# ROOT targets are missing includes and flags +## [setup_properties] +# Fix for ROOT_CXX_FLAGS not actually being a CMake list string(REPLACE " " ";" ROOT_CXX_FLAG_LIST "${ROOT_CXX_FLAGS}") -set_target_properties(ROOT::Core PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${ROOT_INCLUDE_DIRS}" - INTERFACE_COMPILE_OPTIONS "${ROOT_CXX_FLAG_LIST}" - ) +set_property(TARGET ROOT::Core PROPERTY + INTERFACE_INCLUDE_DIRECTORIES "${ROOT_INCLUDE_DIRS}") +set_property(TARGET ROOT::Core APPEND PROPERTY + INTERFACE_COMPILE_OPTIONS ${ROOT_CXX_FLAG_LIST}) +## [setup_properties] +## [add_and_link] add_executable(MyExample MyExample.cxx) target_link_libraries(MyExample PUBLIC ROOT::Physics) +## [add_and_link] + +## [main] enable_testing() -add_test(NAME MyExample COMMAND MyExample) +add_test(NAME RootSimpleExample COMMAND MyExample) diff --git a/specifics/ROOT.md b/specifics/ROOT.md index 4dca6ac..3ee9ad0 100644 --- a/specifics/ROOT.md +++ b/specifics/ROOT.md @@ -7,9 +7,7 @@ ROOT is a C++ Toolkit for High Energy Physics. It is huge. There are really a lo ROOT supports config file discovery, so you can just do: -```cmake -find_package(ROOT CONFIG) -``` +[import:'find_package', lang:'cmake'](../examples/root-example/CMakeLists.txt) to attempt to find ROOT. If you don't have your paths set up, you can pass `-DROOT_DIR=$ROOTSYS/cmake` to find ROOT. (But, really, you should source `thisroot.sh`) @@ -21,16 +19,7 @@ ROOT provides a utility to set up a ROOT project, which you can activate using ` ROOT does not correctly set up it's imported targets. To fix this error, you'll need something like: -```cmake -find_package(ROOT CONFIG REQUIRED) - -string(REPLACE " " ";" ROOT_CXX_FLAG_LIST "${ROOT_CXX_FLAGS}") - -set_target_properties(ROOT::Core PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${ROOT_INCLUDE_DIRS}" - INTERFACE_COMPILE_OPTIONS "${ROOT_CXX_FLAG_LIST}" - ) -``` +[import:'setup_properties', lang:'cmake'](../examples/root-example/CMakeLists.txt) In CMake 3.11, you can replace that last function call with: @@ -43,10 +32,7 @@ All the ROOT targets will require `ROOT::Core`, so this will be enough regardles To link, just pick the libraries you want to use: -```cmake -add_executable(MyExample MyExample.cxx) -target_link_libraries(MyExample PUBLIC ROOT::Physics) -``` +[import:'add_and_link', lang:'cmake'](../examples/root-example/CMakeLists.txt) ## Dictionary generation @@ -72,9 +58,12 @@ To generate a file: root_generate_dictionary(G__MyExample MyExample.h LINKDEF SimpleLinkDef.h) ``` -Then include G__MyExample.cxx in your sources when you make the library. +Then include `G__MyExample.cxx` in your sources when you make the library. ## Example: Minimal #### examples/root-example/CMakeLists.txt -[include](../examples/root-example/CMakeLists.txt) +[import:'main', lang:'cmake'](../examples/root-example/CMakeLists.txt) + +## Example: Dictionary +[import:'main', lang:'cmake', title:"CMakeLists.txt"](../examples/root-example-dict/CMakeLists.txt)