diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 0000000..3e97d97 --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,14 @@ +Testing +CMakeFiles +build* +G__* +*.pcm +*.root +*.rootmap +*.dylib +*.so +Makefile +cmake_install.cmake +CMakeCache.txt +MyExample +CTestTestfile.cmake diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..c2d9e28 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.11) + +project(ModernCMakeExamples) + +enable_testing() + +add_subdirectory(root-simple) +add_subdirectory(root-simple-3.11) +add_subdirectory(root-dict) diff --git a/examples/root-example-dict/CMakeLists.txt b/examples/root-dict/CMakeLists.txt similarity index 51% rename from examples/root-example-dict/CMakeLists.txt rename to examples/root-dict/CMakeLists.txt index 3383d37..1c41f18 100644 --- a/examples/root-example-dict/CMakeLists.txt +++ b/examples/root-dict/CMakeLists.txt @@ -2,7 +2,7 @@ ## [main] cmake_minimum_required(VERSION 3.1) -project(RootExampleDict LANGUAGES CXX) +project(RootDictExample LANGUAGES CXX) find_package(ROOT CONFIG REQUIRED) include("${ROOT_DIR}/modules/RootNewMacros.cmake") @@ -17,11 +17,14 @@ set_target_properties(ROOT::Core PROPERTIES ) include_directories(ROOT_BUG) -root_generate_dictionary(G__MyExample MyExample.h LINKDEF SimpleLinkDef.h) +root_generate_dictionary(G__DictExample DictExample.h LINKDEF DictLinkDef.h) -add_library(MyExample SHARED MyExample.cxx MyExample.h G__MyExample.cxx) -target_link_libraries(MyExample PUBLIC ROOT::Core) +add_library(DictExample SHARED DictExample.cxx DictExample.h G__DictExample.cxx) +target_link_libraries(DictExample PUBLIC ROOT::Core) ## [main] -#enable_testing() -#add_test(NAME MyExample COMMAND ) + +enable_testing() +add_test(NAME RootDictExample + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + COMMAND "${ROOT_root_CMD}" -b -l -q "${CMAKE_CURRENT_SOURCE_DIR}/CheckLoad.C") diff --git a/examples/root-example-dict/CheckLoad.C b/examples/root-dict/CheckLoad.C similarity index 87% rename from examples/root-example-dict/CheckLoad.C rename to examples/root-dict/CheckLoad.C index ce20810..f26482d 100644 --- a/examples/root-example-dict/CheckLoad.C +++ b/examples/root-dict/CheckLoad.C @@ -1,5 +1,5 @@ { -gSystem->Load("libMyExample"); +gSystem->Load("libDictExample"); Simple s; cout << s.GetX() << endl; TFile *_file = TFile::Open("tmp.root", "RECREATE"); diff --git a/examples/root-example-dict/MyExample.cxx b/examples/root-dict/DictExample.cxx similarity index 71% rename from examples/root-example-dict/MyExample.cxx rename to examples/root-dict/DictExample.cxx index 628515d..2145dc6 100644 --- a/examples/root-example-dict/MyExample.cxx +++ b/examples/root-dict/DictExample.cxx @@ -1,4 +1,4 @@ -#include "MyExample.h" +#include "DictExample.h" Double_t Simple::GetX() const {return x;} diff --git a/examples/root-example-dict/MyExample.h b/examples/root-dict/DictExample.h similarity index 100% rename from examples/root-example-dict/MyExample.h rename to examples/root-dict/DictExample.h diff --git a/examples/root-example-dict/SimpleLinkDef.h b/examples/root-dict/DictLinkDef.h similarity index 100% rename from examples/root-example-dict/SimpleLinkDef.h rename to examples/root-dict/DictLinkDef.h diff --git a/examples/root-simple-3.11/CMakeLists.txt b/examples/root-simple-3.11/CMakeLists.txt new file mode 100644 index 0000000..da3f181 --- /dev/null +++ b/examples/root-simple-3.11/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.11) + +project(RootSimpleExample311 LANGUAGES CXX) + +find_package(ROOT CONFIG REQUIRED) +message(STATUS "Found ROOT: ${ROOT_VERSION} at ${ROOT_DIR}") + +string(REPLACE " " ";" ROOT_CXX_FLAG_LIST "${ROOT_CXX_FLAGS}") + +## [modern_fix] +target_include_directories(ROOT::Core INTERFACE "${ROOT_INCLUDE_DIRS}") +target_compile_options(ROOT::Core INTERFACE "${ROOT_CXX_FLAG_LIST}") +## [modern_fix] + +add_executable(RootSimpleExample311 SimpleExample.cxx) +target_link_libraries(RootSimpleExample311 PUBLIC ROOT::Physics) + +enable_testing() +add_test(NAME RootSimpleExample311 COMMAND RootSimpleExample311) diff --git a/examples/root-example/MyExample.cxx b/examples/root-simple-3.11/SimpleExample.cxx similarity index 100% rename from examples/root-example/MyExample.cxx rename to examples/root-simple-3.11/SimpleExample.cxx diff --git a/examples/root-example/CMakeLists.txt b/examples/root-simple/CMakeLists.txt similarity index 80% rename from examples/root-example/CMakeLists.txt rename to examples/root-simple/CMakeLists.txt index 28fa0e7..c85e32a 100644 --- a/examples/root-example/CMakeLists.txt +++ b/examples/root-simple/CMakeLists.txt @@ -22,11 +22,11 @@ set_property(TARGET ROOT::Core APPEND PROPERTY ## [setup_properties] ## [add_and_link] -add_executable(MyExample MyExample.cxx) -target_link_libraries(MyExample PUBLIC ROOT::Physics) +add_executable(RootSimpleExample SimpleExample.cxx) +target_link_libraries(RootSimpleExample PUBLIC ROOT::Physics) ## [add_and_link] ## [main] enable_testing() -add_test(NAME RootSimpleExample COMMAND MyExample) +add_test(NAME RootSimpleExample COMMAND RootSimpleExample) diff --git a/examples/root-simple/SimpleExample.cxx b/examples/root-simple/SimpleExample.cxx new file mode 100644 index 0000000..82fe026 --- /dev/null +++ b/examples/root-simple/SimpleExample.cxx @@ -0,0 +1,7 @@ + +#include +int main() { + TLorentzVector v(1,2,3,4); + v.Print(); + return 0; +}