BASIS  version 1.2.3 (revision 2104)
ExecutableTargetInfo.h
Go to the documentation of this file.
00001 /**
00002  * @file  ExecutableTargetInfo.h
00003  * @brief Declaration of ExecutableTargetInfo module.
00004  *
00005  * @note The file ExecutableTargetInfo.h is automatically generated by BASIS
00006  *       from the file ExecutableTargetInfo.h.in which is part of BASIS.
00007  *
00008  * Copyright (c) 2011 University of Pennsylvania. All rights reserved.<br />
00009  * See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00010  *
00011  * Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00012  */
00013 
00014 #pragma once
00015 #ifndef _SBIA_BASIS_EXECUTABLETARGETINFO_H
00016 #define _SBIA_BASIS_EXECUTABLETARGETINFO_H
00017 
00018 
00019 #include <string>
00020 #include <map>
00021 
00022 
00023 namespace sbia
00024 {
00025 
00026 namespace basis
00027 {
00028 
00029 
00030 /**
00031  * @brief Provides information about executable build targets.
00032  *
00033  * Within source code of a BASIS project, other SBIA executables are called
00034  * only indirectly using the build target name which must be fixed and unique
00035  * within the lab. The name of the output executable file of these targets may
00036  * however vary and be finally set by BASIS, for example, depending on
00037  * whether the project is build as part of a superproject or not. Therefore,
00038  * each BASIS CMake function may adjust the output name in order to resolve
00039  * name conflicts with other targets or SBIA executables.
00040  *
00041  * The idea is that a target name is supposed to be stable and known to the
00042  * developer as soon as the target is added to a CMakeLists.txt file, while
00043  * the name of the actual executable file is not known a priori as it is set
00044  * by the BASIS CMake functions during the configure step. Thus, the developer
00045  * should not rely on a particular name of the executable file. Instead, they
00046  * can rely on the name of the corresponding build target which was chosen by
00047  * themselves when adding the target to the build configuration.
00048  *
00049  * In order to get the actual file path of the built executable file, the
00050  * function get_executable_path() is provided by the stdaux.h module.
00051  * This function uses the static singleton instance of this class in order to
00052  * map the given build target name to the name of the built and optionally
00053  * installed executable. The code which initializes the required maps is
00054  * generated automatically during the configuration of the build system.
00055  *
00056  * @note This class is not intended to be subclassed.
00057  *
00058  * @sa get_executable_path()
00059  *
00060  * @ingroup BasisCxxUtilities
00061  */
00062 class ExecutableTargetInfo
00063 {
00064     // -----------------------------------------------------------------------
00065     // typedefs
00066 private:
00067 
00068     typedef std::map <std::string, std::string> MapType;
00069     typedef MapType::const_iterator             MapIterator;
00070 
00071     // -----------------------------------------------------------------------
00072     // construction / destruction
00073 private:
00074 
00075     /**
00076      * @brief Constructor.
00077      *
00078      * Initializes the data members. The initialization code is in particular
00079      * generated by BASIS during the configuration of the build system.
00080      */
00081     ExecutableTargetInfo();
00082 
00083     /// @brief Destructor.
00084     ~ExecutableTargetInfo();
00085 
00086     // -----------------------------------------------------------------------
00087     // public interface
00088 public:
00089 
00090     /**
00091      * @brief Get static instance of this module.
00092      *
00093      * @attention This method is not thread-safe!
00094      *
00095      * @return Static instance of this class.
00096      */
00097     static const ExecutableTargetInfo& instance();
00098 
00099     /**
00100      * @brief Get UID of build target.
00101      *
00102      * In order to be able to distinguish build targets with identical name
00103      * but which are built as part of different BASIS projects, the UID of
00104      * a build target is composed of the build target name as given as
00105      * argument to the basis_add_* CMake functions and a namespace identifier
00106      * (i.e., the project name in lowercase letters). If the specified build
00107      * target name is neither known by this module nor a build target UID yet,
00108      * this method prepends the namespace identifier corresponding to the
00109      * project this module was built from, assuming that the caller refers
00110      * to another target within the same project.
00111      *
00112      * @param [in] target Name/UID of build target.
00113      *
00114      * @returns UID of build target.
00115      */
00116     std::string get_target_uid(const std::string& target) const;
00117 
00118     /**
00119      * @brief Determine whether a given build target is known.
00120      *
00121      * @param [in] target Name/UID of build target.
00122      *
00123      * @returns Whether the given build target is known by this module.
00124      */
00125     bool is_known_target(const std::string& target) const;
00126 
00127     /**
00128      * @brief Get name of executable file without path.
00129      *
00130      * @param [in] target Name/UID of build target.
00131      *
00132      * @return Name of built executable file without path.
00133      */
00134     std::string get_executable_name(const std::string& target) const;
00135 
00136     /**
00137      * @brief Get absolute path of output directory of executable in build tree.
00138      *
00139      * @param [in] target Name/UID of build target.
00140      *
00141      * @return Absolute path of build tree directory where built executable is
00142      *         located or an empty string if build target is not known.
00143      */
00144     std::string get_build_directory(const std::string& target) const;
00145 
00146     /**
00147      * @brief Get absolute path of directory where built executable is installed.
00148      *
00149      * @param [in] target Name/UID of build target.
00150      *
00151      * @return Absolute path of executable's installation directory or
00152      *         an empty string if build target is not known.
00153      */
00154     std::string get_installation_directory(const std::string& target) const;
00155 
00156     // -----------------------------------------------------------------------
00157     // unsupported methods
00158 private:
00159 
00160     /**
00161      * @brief Copy constructor.
00162      *
00163      * @note Intentionally not implemented.
00164      */
00165     ExecutableTargetInfo(const ExecutableTargetInfo&);
00166 
00167     /**
00168      * @brief Assignment operator.
00169      *
00170      * @note Intentionally not implemented.
00171      */
00172     void operator=(const ExecutableTargetInfo&);
00173 
00174     // -----------------------------------------------------------------------
00175     // members
00176 private:
00177 
00178     /// Maps build target names to executable file names.
00179     MapType _exec_names;
00180     /// Maps build target names to output directories in build tree.
00181     MapType _build_dirs;
00182     /// Maps build target names to installation directories relative to
00183     /// installation prefix as returned by GetInstallationPrefix().
00184     MapType _install_dirs;
00185 
00186 }; // class ExecutableTargetInfo
00187 
00188 
00189 } // namespace basis
00190 
00191 } // namespace sbia
00192 
00193 
00194 #endif // _SBIA_BASIS_EXECUTABLETARGETINFO_H
00195