Commit 6ccbee52 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

CMake: Add Dependencies to Target

(cherry picked from commit 200c9596)
parent baeef8ca
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -3,6 +3,18 @@
SET_AND_CHECK(ALLPIX_INCLUDE_DIR "@PACKAGE_ALLPIX_INCLUDE_DIR@")
SET_AND_CHECK(ALLPIX_LIBRARY_DIR "@PACKAGE_ALLPIX_LIBRARY_DIR@")

# Force same CXX standard for downstream project
SET(CMAKE_CXX_STANDARD @CMAKE_CXX_STANDARD@)
SET(CMAKE_CXX_STANDARD_REQUIRED @CMAKE_CXX_STANDARD_REQUIRED@)
SET(CMAKE_CXX_EXTENSIONS @CMAKE_CXX_EXTENSIONS@)

# Require dependencies for inclusion in downstream project:
INCLUDE(CMakeFindDependencyMacro)
FIND_DEPENDENCY(Threads)
FIND_DEPENDENCY(Boost 1.64.0 COMPONENTS random)
FIND_DEPENDENCY(ROOT COMPONENTS Geom Core GenVector Hist RIO NO_MODULE)

# Add targets and configure for external module generation
INCLUDE("${CMAKE_CURRENT_LIST_DIR}/AllpixConfigTargets.cmake")

SET(ALLPIX_MODULE_EXTERNAL TRUE)
+3 −3
Original line number Diff line number Diff line
@@ -65,14 +65,14 @@ A minimal CMake setup for compiling and linking external modules to the core and
\begin{minted}[frame=single,framesep=3pt,breaklines=true,tabsize=2,linenos]{cmake}
CMAKE_MINIMUM_REQUIRED(VERSION 3.4.3 FATAL_ERROR)

FIND_PACKAGE(ROOT REQUIRED)
FIND_PACKAGE(Allpix REQUIRED)
FIND_PACKAGE(Allpix 2.0 REQUIRED)

ALLPIX_DETECTOR_MODULE(MODULE_NAME)
ALLPIX_MODULE_SOURCES(${MODULE_NAME} MySimulationModule.cpp)
\end{minted}

It might be necessary to set the \parameter{CMAKE_CXX_STANDARD} according to the settings used to build the framework.
All dependencies of the framework such as ROOT or Boost.Random are automatically added as CMake targets and can be used by the module.
The required \parameter{CMAKE_CXX_STANDARD} is automatically inferred from the settings used to build the framework.
Additional libraries can be linked to the module using the standard CMake command
\begin{minted}[frame=single,framesep=3pt,breaklines=true,tabsize=2,linenos]{cmake}
TARGET_LINK_LIBRARIES(${MODULE_NAME} MyExternalLibrary)
+0 −1
Original line number Diff line number Diff line
@@ -81,5 +81,4 @@ INSTALL(
    DESTINATION include
    PATTERN "*.hpp"
    PATTERN "*.h"
    PATTERN "objects.h" EXCLUDE
    PATTERN "Linkdef.h" EXCLUDE)