PAR: prototype of common PARfiles generation
authordberzano <dario.berzano@cern.ch>
Mon, 26 Jan 2015 10:20:38 +0000 (11:20 +0100)
committerdberzano <dario.berzano@cern.ch>
Thu, 29 Jan 2015 11:57:51 +0000 (12:57 +0100)
CMakeLists.txt
cmake/GenParFile.cmake [new file with mode: 0644]
cmake/PARfiles/BUILD.sh.in [new file with mode: 0644]
cmake/PARfiles/Makefile.in [new file with mode: 0644]
cmake/PARfiles/SETUP.C.in [new file with mode: 0644]

index bf9e2c1..06ac222 100644 (file)
@@ -55,6 +55,9 @@ include(CheckGitVersion)
 #       - GCC_MAJOR.GCC_MINOR.GCC_PATCH
 include(CheckCompiler)
 
+# Utility to generate PARfiles
+include(cmake/GenParFile.cmake)
+
 # Shared library suffix
 if (NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
   set(CMAKE_SHARED_LIBRARY_SUFFIX .so)
diff --git a/cmake/GenParFile.cmake b/cmake/GenParFile.cmake
new file mode 100644 (file)
index 0000000..97e5433
--- /dev/null
@@ -0,0 +1,50 @@
+macro(add_parfile PARMODULE PARSOURCES PARHEADERS PARLINKDEF)
+
+  message(STATUS "PARfile generation: ${PARMODULE}")
+  message(STATUS "--> Module: ${PARMODULE}")
+  message(STATUS "--> Sources: ${PARSOURCES}")
+
+  # Export variable
+  set(PARMODULE "${PARMODULE}")
+
+  foreach(LOOPVAR ${PARSOURCES})
+    message(STATUS "----> ${LOOPVAR}")
+  endforeach()
+
+  # PARfile output directory (the one we will tar)
+  set(PARDIR ${CMAKE_CURRENT_BINARY_DIR}/PARfiles/${PARMODULE})
+
+  # Create base directory for this module's PARfile: this is the directory we will tar
+  # This works as "mkdir -p" (i.e. it's recursive and creates parents)
+  file(MAKE_DIRECTORY ${PARDIR}/PROOF-INF)
+
+  # Create Makefile
+  configure_file(
+      ${PROJECT_SOURCE_DIR}/cmake/PARfiles/Makefile.in
+      ${PARDIR}/Makefile
+      @ONLY
+  )
+
+  # Create BUILD.sh
+  configure_file(
+      ${PROJECT_SOURCE_DIR}/cmake/PARfiles/BUILD.sh.in
+      ${PARDIR}/PROOF-INF/BUILD.sh
+      @ONLY
+  )
+  execute_process(COMMAND chmod a+x ${PARDIR}/PROOF-INF/BUILD.sh)
+
+  # Create SETUP.C
+  configure_file(
+      ${PROJECT_SOURCE_DIR}/cmake/PARfiles/SETUP.C.in
+      ${PARDIR}/PROOF-INF/SETUP.C
+      @ONLY
+  )
+
+  # Target for creating PARfile (would stop after the first failed COMMAND)
+  add_custom_target("${PARMODULE}.par"
+    COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && cp ${PARSOURCES} ${PARHEADERS} ${PARLINKDEF} ${PARDIR}/
+    COMMAND cmake -E copy ${ROOT_ETCDIR}/Makefile.arch ${PARDIR}/
+    COMMAND tar -C ${PARDIR}/.. -czf ${PARDIR}/../${PARMODULE}.par ${PARMODULE}/
+  )
+
+endmacro()
diff --git a/cmake/PARfiles/BUILD.sh.in b/cmake/PARfiles/BUILD.sh.in
new file mode 100644 (file)
index 0000000..666656a
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+make
diff --git a/cmake/PARfiles/Makefile.in b/cmake/PARfiles/Makefile.in
new file mode 100644 (file)
index 0000000..e806e6e
--- /dev/null
@@ -0,0 +1,37 @@
+# Makefile for @PARMODULE@ -- automatically generated
+
+# From ROOT
+include Makefile.arch
+
+# Name of this module
+PAR_MODULE := @PARMODULE@
+
+# Get C++ flags from AliRoot's CMake, not ROOT -- append AliRoot/AliPhysics includes
+PAR_INCLUDES = -I. -I$(ALICE_ROOT)/include -I$(ALICE_PHYSICS)/include -I$(ROOTSYS)/include
+PAR_CXXFLAGS = @CMAKE_CXX_FLAGS@ $(PAR_INCLUDES)
+
+# Get linker flags from AliRoot's CMake, not ROOT
+PAR_SOFLAGS = @CMAKE_SHARED_LINKER_FLAGS@
+
+SRCS = $(wildcard *.cxx)
+HDRS = $(SRCS:.cxx=.h)
+DHDR = @PARMODULE@LinkDef.h
+
+SRCS += G__@PARMODULE@.cxx
+OBJS = $(SRCS:.cxx=.o)
+
+# Compile sources into objects
+%.o: %.cxx %.h
+       @CMAKE_CXX_COMPILER@ $(PAR_CXXFLAGS) -c $< -o $@
+
+# Generate library from objects
+lib@PARMODULE@.so: $(OBJS)
+       @CMAKE_LINKER@ $(PAR_SOFLAGS) $^ -o $@ $(EXPLLINKLIBS)
+
+# Generate dictionary
+G__@PARMODULE@.cxx G__@PARMODULE@.h: $(HDRS) $(DHDR)
+       rootcint -f $@ -c $(PAR_INCLUDES) $^
+
+# Delete all
+clean:
+       rm -f $(OBJS) *.so G__@PARMODULE@.*
diff --git a/cmake/PARfiles/SETUP.C.in b/cmake/PARfiles/SETUP.C.in
new file mode 100644 (file)
index 0000000..90e2c1e
--- /dev/null
@@ -0,0 +1,3 @@
+Int_t SETUP() {
+  Printf("Hello world!");
+}