# ICEDUST_CONFIGURE_OUTPUT # ------------------------ # # Macro to set up the target properties for install step # It accomplishes following tasks: # > configure output directories for install step (for libraries, apps, etc) # > copy over provided directories and their content # > copy over specific provided files # > copy over previously created root-dictionaries # > Set up RPATH for applications and libraries # # # Usage # ^^^^^ # #---ICEDUST_CONFIGURE_OUTPUT( # TARGETS target1 [target2 ...] # [DEPENDENCIES dep1 [dep2 ...]] # [FILES file1 [file2 ...]] # [DIRECTORIES dir1 [dir2 ...]] # [OPTIONS -opt1 [-opt2 ...]]) # # TARGETS specifies all target which shall be configured # # DEPENDENCIES list of applications/libraries/... the TARGETS are dependent on. # Based on this the RPATH of all TARGETS is configured # # FILES will be copied over to build-/install-directory (PRESERVE directory structure!) # # DIRECTORIES will be copied over to build-/install-directory # # OPTIONS (not supported yet, as there is (no?) usecase as for now) # # # manager COMET Software Group # author andreas.jansen@tu-dresden.de function(ICEDUST_CONFIGURE_OUTPUT) CMAKE_PARSE_ARGUMENTS(ARG "" "" "TARGETS;DEPENDENCIES;FILES;DIRECTORIES;OPTIONS" ${ARGN}) # --- Check if OPTIONS start with a dash ------------------ # currently no options available... if (ARG_OPTIONS) foreach(ARG_O ${ARG_OPTIONS}) if (NOT ARG_O MATCHES "^-") message(FATAL_ERROR "Undefined option: ${ARG_OPTIONS}") endif() endforeach() endif(ARG_OPTIONS) # --- Warn if we have unused arguments ------------------ if(ARG_UNPARSED_ARGUMENTS) message(WARNING "Unknown / Unparsed Arguments: ${ARG_UNPARSED_ARGUMENTS}") endif() # --- Set up RPATH list for INSTALL_RPATH property set(RPATH ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/lib) foreach(ARG_D ${ARG_DEPENDENCIES}) list(APPEND RPATH ${CMAKE_INSTALL_PREFIX}/${ARG_D}/lib) endforeach() # --- Actual functionality of the macro starts here: # -------------------------------------------------- set_target_properties( ${ARG_TARGETS} PROPERTIES # Standard-Output-Directories for make: ../build_directory/packageXYZ/ ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin # set RPATH to correctly link after invokation of "make install" INSTALL_RPATH "${RPATH}" ) # Standard-Output-Directories for "make install" # "CMAKE_INSTALL_PREFIX" is prepended to all directories! install(TARGETS ${ARG_TARGETS} RUNTIME DESTINATION ${PROJECT_NAME}/bin LIBRARY DESTINATION ${PROJECT_NAME}/lib ARCHIVE DESTINATION ${PROJECT_NAME}/lib ) # Copy ROOT-Dictionary files (whole "dict" directoy) if(ICEDUST_COPY_DICT) if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/dict) install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dict DESTINATION ${PROJECT_NAME}) else() message(STATUS "No ROOT dictionaries to copy over for ${PROJECT_NAME}, skipping.") endif() endif() # Copy FILES to build- / install-directory (PRESERVE directory structure!) foreach(ARG_F ${ARG_FILES}) # Copy special files into ${CMAKE_CURRENT_BINARY_DIR} (PRESERVE directory structure!) get_filename_component(FILE_NAMEONLY ${ARG_F} NAME) get_filename_component(FILE_DIRONLY ${ARG_F} DIRECTORY) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_F} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${FILE_DIRONLY} USE_SOURCE_PERMISSIONS) # Copy special files into install-directory (PRESERVE directory structure!) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ARG_F} DESTINATION ${PROJECT_NAME}/${FILE_DIRONLY}) endforeach() # Copy DIRECTORIES foreach(ARG_D ${ARG_DIRECTORIES}) get_filename_component(STRIPED_DIRNAME ${ARG_D} DIRECTORY) # Copy directory to "${CMAKE_CURRENT_BINARY_DIR}" file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_D} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${STRIPED_DIRNAME} USE_SOURCE_PERMISSIONS) # Copy directory to install-directory install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_D} DESTINATION ${PROJECT_NAME}/${STRIPED_DIRNAME} USE_SOURCE_PERMISSIONS) endforeach() # Create symlinks for our executables foreach(ARG_T ${ARG_TARGETS}) get_target_property(TARGET_TYPE ${ARG_T} TYPE) # Throws warning if target does not exist! if (TARGET_TYPE STREQUAL "EXECUTABLE" AND (NOT DEFINED ICEDUST_CREATE_SYMLINKS OR ICEDUST_CREATE_SYMLINKS)) # Symlinks for build process file(MAKE_DIRECTORY ${SYMLINK_BUILD_OUTPUT_FOLDER}) set(FILEPATH_BUILD "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/bin/${ARG_T}") set(SYMPATH_BUILD "${SYMLINK_BUILD_OUTPUT_FOLDER}/${ARG_T}") execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${FILEPATH_BUILD} ${SYMPATH_BUILD}) # Symlinks for install process file(MAKE_DIRECTORY ${SYMLINK_INSTALL_OUTPUT_FOLDER}) set(FILEPATH_INSTALL "${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/bin/${ARG_T}") set(SYMPATH_INSTALL "${SYMLINK_INSTALL_OUTPUT_FOLDER}/${ARG_T}") install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${FILEPATH_INSTALL} ${SYMPATH_INSTALL})") install(CODE "message(STATUS \"Created symlink: ${FILEPATH_INSTALL} -> ${SYMPATH_INSTALL}\")") endif () endforeach() endfunction()