From 6a52473afb5e21cf43ab71f82b5230f05c97bd75 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Wed, 2 May 2018 10:48:50 +0200 Subject: [PATCH] Adding improvements to ROOT --- examples/root-dict/CMakeLists.txt | 25 +++++++++++++++-------- examples/root-dict/README.md | 4 +++- examples/root-simple-3.11/CMakeLists.txt | 20 +++++++++--------- examples/root-simple/CMakeLists.txt | 26 +++++++++++++----------- examples/root-usefile/CMakeLists.txt | 1 - 5 files changed, 43 insertions(+), 33 deletions(-) diff --git a/examples/root-dict/CMakeLists.txt b/examples/root-dict/CMakeLists.txt index 031be0e..4613105 100644 --- a/examples/root-dict/CMakeLists.txt +++ b/examples/root-dict/CMakeLists.txt @@ -1,29 +1,36 @@ ## [main] -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.4) project(RootDictExample LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_PLATFORM_INDEPENDENT_CODE ON) + +find_package(Threads) + find_package(ROOT CONFIG REQUIRED) include("${ROOT_DIR}/modules/RootNewMacros.cmake") -message(STATUS "Found ROOT: ${ROOT_VERSION} at ${ROOT_DIR}") - -separate_arguments(ROOT_CXX_FLAGS) - +# We will set the flags ourselves set_target_properties(ROOT::Core PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${ROOT_INCLUDE_DIRS}" - INTERFACE_COMPILE_OPTIONS "${ROOT_CXX_FLAGS}" - ) + INTERFACE_INCLUDE_DIRECTORIES "${ROOT_INCLUDE_DIRS}") include_directories(ROOT_BUG) root_generate_dictionary(G__DictExample DictExample.h LINKDEF DictLinkDef.h) add_library(DictExample SHARED DictExample.cxx DictExample.h G__DictExample.cxx) -target_link_libraries(DictExample PUBLIC ROOT::Core) +target_link_libraries(DictExample PUBLIC ROOT::Core Threads::Threads) ## [main] +message(STATUS "Found ROOT: ${ROOT_VERSION} at ${ROOT_DIR}") +message(STATUS "Original flags: ${ROOT_CXX_FLAGS}") +message(STATUS "Original definitions: ${ROOT_DEFINITIONS}") +message(STATUS "Original exe flags: ${ROOT_EXE_LINKER_FLAGS}") + enable_testing() add_test(NAME RootDictExample WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" diff --git a/examples/root-dict/README.md b/examples/root-dict/README.md index 008ec28..ab745c9 100644 --- a/examples/root-dict/README.md +++ b/examples/root-dict/README.md @@ -1,6 +1,8 @@ # Dictionary Example -This is an example of building a module that includes a dictionary in CMake. +This is an example of building a module that includes a dictionary in CMake. Instead of using the +ROOT suggested flags, we will manually add threading via `find_package`, which is the only +important flag in the list on most systems. #### examples/root-dict/CMakeLists.txt [import:'main', lang:'cmake'](CMakeLists.txt) diff --git a/examples/root-simple-3.11/CMakeLists.txt b/examples/root-simple-3.11/CMakeLists.txt index 4b64e25..cdb3244 100644 --- a/examples/root-simple-3.11/CMakeLists.txt +++ b/examples/root-simple-3.11/CMakeLists.txt @@ -5,23 +5,23 @@ cmake_minimum_required(VERSION 3.11) project(RootSimpleExample311 LANGUAGES CXX) find_package(ROOT CONFIG REQUIRED) -message(STATUS "Found ROOT: ${ROOT_VERSION} at ${ROOT_DIR}") - -separate_arguments(ROOT_CXX_FLAGS) -separate_arguments(ROOT_DEFINITIONS) -message(STATUS "ROOT_DEFINITIONS ${ROOT_DEFINITIONS}") - -# This is required on if there is more than one flag (like on macOS) -# and this also fixes a bug in the linker flags -string(REPLACE "-L " "-L" ROOT_EXE_LINKER_FLAGS "${ROOT_EXE_LINKER_FLAGS}") -separate_arguments(ROOT_EXE_LINKER_FLAGS) ## [modern_fix] target_include_directories(ROOT::Core INTERFACE "${ROOT_INCLUDE_DIRS}") add_library(ROOT::Flags_CXX IMPORTED INTERFACE) + +separate_arguments(ROOT_CXX_FLAGS) target_compile_options(ROOT::Flags_CXX INTERFACE ${ROOT_CXX_FLAGS}) + +separate_arguments(ROOT_DEFINITIONS) target_compile_definitions(ROOT::Flags_CXX INTERFACE ${ROOT_DEFINITIONS}) + +# This fixes a bug in the linker flags +string(REPLACE "-L " "-L" ROOT_EXE_LINKER_FLAGS "${ROOT_EXE_LINKER_FLAGS}") +separate_arguments(ROOT_EXE_LINKER_FLAGS) +# Stuck into using old property method due to separate -L and -l arguments +# (A full path to -l is better!) set_property(TARGET ROOT::Flags_CXX PROPERTY INTERFACE_LINK_LIBRARIES ${ROOT_EXE_LINKER_FLAGS}) ## [modern_fix] diff --git a/examples/root-simple/CMakeLists.txt b/examples/root-simple/CMakeLists.txt index 308ca61..fc90276 100644 --- a/examples/root-simple/CMakeLists.txt +++ b/examples/root-simple/CMakeLists.txt @@ -8,8 +8,6 @@ project(RootSimpleExample LANGUAGES CXX) find_package(ROOT CONFIG REQUIRED) ## [find_package] -message(STATUS "Found ROOT: ${ROOT_VERSION} at ${ROOT_DIR}") - # ROOT targets are missing includes and flags ## [setup_includes] set_property(TARGET ROOT::Core PROPERTY @@ -17,20 +15,24 @@ set_property(TARGET ROOT::Core PROPERTY ## [setup_includes] ## [setup_flags] +add_library(ROOT::Flags_CXX IMPORTED INTERFACE) + # Fix for ROOT_CXX_FLAGS not actually being a CMake list separate_arguments(ROOT_CXX_FLAGS) -separate_arguments(ROOT_DEFINITIONS) - -# This is required on if there is more than one flag (like on macOS) -# and this also fixes a bug in the linker flags -string(REPLACE "-L " "-L" ROOT_EXE_LINKER_FLAGS "${ROOT_EXE_LINKER_FLAGS}") -separate_arguments(ROOT_EXE_LINKER_FLAGS) - -add_library(ROOT::Flags_CXX IMPORTED INTERFACE) set_property(TARGET ROOT::Flags_CXX APPEND PROPERTY INTERFACE_COMPILE_OPTIONS ${ROOT_CXX_FLAGS}) -set_property(TARGET ROOT::Flags_CXX APPEND PROPERTY - INTERFACE_COMPILE_DEFINITIONS ${ROOT_DEFINITIONS}) + +# Add definitions +separate_arguments(ROOT_DEFINITIONS) +foreach(_flag ${ROOT_EXE_LINKER_FLAG_LIST}) + # Remove -D or /D if present + string(REGEX REPLACE [=[^[-//]D]=] "" _flag ${_flag}) + set_property(TARGET ROOT::Flags APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${_flag}) +endforeach() + +# This also fixes a bug in the linker flags +string(REPLACE "-L " "-L" ROOT_EXE_LINKER_FLAGS "${ROOT_EXE_LINKER_FLAGS}") +separate_arguments(ROOT_EXE_LINKER_FLAGS) set_property(TARGET ROOT::Flags_CXX APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${ROOT_EXE_LINKER_FLAGS}) ## [setup_flags] diff --git a/examples/root-usefile/CMakeLists.txt b/examples/root-usefile/CMakeLists.txt index 2df4014..df68839 100644 --- a/examples/root-usefile/CMakeLists.txt +++ b/examples/root-usefile/CMakeLists.txt @@ -5,7 +5,6 @@ cmake_minimum_required(VERSION 3.1) project(RootUseFileExample LANGUAGES CXX) find_package(ROOT CONFIG REQUIRED) -message(STATUS "Found ROOT: ${ROOT_VERSION} at ${ROOT_DIR}") include("${ROOT_USE_FILE}")