]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - cmake/CMakeALICE.cmake
PAR: added example in CMakeLists.txt
[u/mrichter/AliRoot.git] / cmake / CMakeALICE.cmake
index 4ca1ae1d4facac7da850027d7872e03abbd62f66..c8f0e24a08b8e28c089f42f3c3e03fafa9513e7f 100644 (file)
@@ -24,6 +24,8 @@
 # @LDNAME LinkDef file name, ex: LinkDef.h
 # @DHDRS  Dictionary headers
 # @DINCDIR Include folders that need to be passed to cint/cling
+# @EXTRADEFINITIONS - optional, extra compile flags specific to library
+#       - used as ${ARGV4}
 macro(generate_dictionary DNAME LDNAME DHDRS DINCDIRS)
 
     # Creating the INCLUDE path for cint/cling
@@ -31,24 +33,21 @@ macro(generate_dictionary DNAME LDNAME DHDRS DINCDIRS)
         set(INCLUDE_PATH -I${dir} ${INCLUDE_PATH})
     endforeach()
     
-    # Generate the dictionary
-#    message(STATUS "Generating dictionary ${DNAME} for ${LDNAME}")
-    
-#    message(STATUS "${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.cxx")
-#    message(STATUS "${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.h")
-#    message(STATUS "bbb${INCLUDE_PATH}bbb")
-#    message(STATUS "${DHDRS} ${LDNAME}")
-#    message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}")
+    # Get the list of definitions from the directory to be sent to CINT
+    get_directory_property(tmpdirdefs COMPILE_DEFINITIONS)
+    foreach(dirdef ${tmpdirdefs})
+        set(GLOBALDEFINITIONS -D${dirdef} ${GLOBALDEFINITIONS})
+    endforeach()
     
-    # Get the definitions from the directory to be sent to CINT
-    get_directory_property(tmpdirdefs DEFINITIONS)
-    string(REPLACE " " ";" tmpdirdefs "${tmpdirdefs}")
+    # Custom definitions specific to library
+    # Received as the forth optional argument
+    separate_arguments(EXTRADEFINITIONS UNIX_COMMAND "${ARGV4}")
 
     if (ROOT_VERSION_MAJOR LESS 6)
     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.cxx ${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.h
                        COMMAND LD_LIBRARY_PATH=${ROOT_LIBDIR}:$ENV{LD_LIBRARY_PATH} ${ROOT_CINT}
                        ARGS -f ${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.cxx -c -p 
-                       ${tmpdirdefs} ${INCLUDE_PATH} 
+                       ${GLOBALDEFINITIONS} ${EXTRADEFINITIONS} ${INCLUDE_PATH} 
                        ${DHDRS} ${LDNAME}
                        DEPENDS ${DHDRS} ${LDNAME} ${ROOT_CINT}
                        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
@@ -60,7 +59,7 @@ macro(generate_dictionary DNAME LDNAME DHDRS DINCDIRS)
                        ARGS
                          -f ${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.cxx
                          -rmf ${CMAKE_CURRENT_BINARY_DIR}/lib${DNAME}.rootmap -rml lib${DNAME}
-                         ${tmpdirdefs} ${INCLUDE_PATH} ${DHDRS} ${LDNAME}
+                         ${GLOBALDEFINITIONS} ${EXTRADEFINITIONS}  ${INCLUDE_PATH} ${DHDRS} ${LDNAME}
                        DEPENDS
                          ${DHDRS} ${LDNAME} ${ROOT_CINT}
                        WORKING_DIRECTORY
@@ -238,3 +237,91 @@ macro(createDArpm DETECTOR ALGORITHM)
     # install RPM into $CMAKE_INSTALL_PREFIX/darpms
     install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/da-${_ALGORITHM}-rpm/RPMS/ DESTINATION darpms PATTERN "\\.rpm")
 endmacro()
+
+
+# Prepend prefix to every element in the list. Note: this function modifies the input variable: this
+# does not work for macros in CMake, only for functions. Also note that it does NOT automatically
+# add a / between prefix and list item as it does not assume that we are dealing with directories
+function(prepend_prefix INLIST PREFIX)
+    foreach(_ITEM ${${INLIST}})
+        list(APPEND _OUTLIST ${PREFIX}${_ITEM})
+    endforeach()
+    set(${INLIST} ${_OUTLIST} PARENT_SCOPE)
+endfunction()
+
+
+# This function is a drop-in replacement for the following CMake command:
+#
+#   install(FILES ... DESTINATION ... [OTHER_ARGS])
+#
+# The above command takes every single file and puts it in the destination directory, but relative
+# paths are not taken into consideration, i.e. files a/b/c/file.h and boo.h will be both installed
+# in dest.
+#
+# By replacing install() with install_relative(), boo.h will end in dest, and a/b/c/file.h will end
+# in dest/a/b/c/file.h, i.e. relative paths are taken into account.
+#
+# If an absolute path was specified for an input file, a fatal error will be raised: only relative
+# paths can be specified.
+#
+# Since it is a drop-in command, its syntax is identical to install():
+#
+#   install_relative(FILES ... DESTINATION ... [OTHER_ARGS])
+#
+# where OTHER_ARGS is passed as-is to the underlying install() command
+function(install_relative)
+
+    set(_EXPECT_FILE TRUE)
+    set(_EXPECT_DEST FALSE)
+    set(_EXPECT_REST FALSE)
+
+    foreach(_ARG ${ARGN})
+
+        if(_EXPECT_FILE)
+
+            if(${_ARG} STREQUAL "FILES")
+                set(_EXPECT_FILE FALSE)
+            else()
+                message(FATAL_ERROR "You may only use install_relative() in place of install(FILES ...)")
+            endif()
+
+        elseif(_EXPECT_REST)
+            # Remaining arguments
+            list(APPEND _REST ${_ARG})
+        elseif(_EXPECT_DEST)
+            # Destination prefix
+            set(_DEST ${_ARG})
+            set(_EXPECT_DEST FALSE)
+            set(_EXPECT_REST TRUE)
+        elseif(_ARG STREQUAL "DESTINATION")
+            # From now on, copy the arguments ditto to the install() command
+            set(_EXPECT_DEST TRUE)
+        else()
+            # Append files to install
+            list(APPEND _FILES ${_ARG})
+        endif()
+
+    endforeach()
+
+    # Print out our results (debug)
+    #message(STATUS "[install_relative] FILES: ${_FILES}")
+    #message(STATUS "[install_relative] DEST: ${_DEST}")
+    #message(STATUS "[install_relative] REST: ${_REST}")
+
+    # Prepare a distinct install command for each file, depending on its path
+    foreach(_FILE ${_FILES})
+
+        get_filename_component(_FILEPREFIX ${_FILE} DIRECTORY)
+        #message(STATUS "[install_relative] ${_FILE} --> ${_FILEPREFIX}")
+
+        string(SUBSTRING ${_FILE} 0 1 _FILE_FIRST)
+        if(${_FILE_FIRST} STREQUAL "/")
+            # An absolute path was found: not supported, error
+            message(FATAL_ERROR "Absolute paths are not supported by install_relative(): ${_FILE}")
+        endif()
+
+        install(FILES ${_FILE} DESTINATION ${_DEST}/${_FILEPREFIX} ${_REST})
+
+    endforeach()
+
+endfunction()