1
0
mirror of synced 2024-12-22 12:40:00 +01:00

More examples

This commit is contained in:
Henry Fredrick Schreiner 2018-03-28 22:48:45 +02:00
parent ebfe7865b8
commit 0b5a8e4c89
4 changed files with 29 additions and 33 deletions

View File

@ -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:

View File

@ -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 )

View File

@ -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)

View File

@ -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)