Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Redefining __BASE_FILE__ with qmake

Redefining __BASE_FILE__ with qmake

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
4 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Marco NilssonM Offline
    Marco NilssonM Offline
    Marco Nilsson
    wrote on last edited by Marco Nilsson
    #1

    I use __BASE_FILE__ to show the logging file in my debug output. The problem is that it includes the relative directory from where qmake invokes the makefile. In my case the output will be something like src/MyFile.cpp. I know it's possible to redefine the file macros to only show the file basename, but I cannot figure out how to get qmake to a define which involves the current file being processed (QMAKE_FILE_IN_BASE). Is that possible or is there any other way to solve this?

    A 1 Reply Last reply
    0
    • Marco NilssonM Marco Nilsson

      I use __BASE_FILE__ to show the logging file in my debug output. The problem is that it includes the relative directory from where qmake invokes the makefile. In my case the output will be something like src/MyFile.cpp. I know it's possible to redefine the file macros to only show the file basename, but I cannot figure out how to get qmake to a define which involves the current file being processed (QMAKE_FILE_IN_BASE). Is that possible or is there any other way to solve this?

      A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      @Marco-Nilsson I use __FILE__. You won't get pathing with that. It's plenty to work with for debugging. Here is an excerpt from my logger (available at https://github.com/ambershark-mike/sharklog/blob/master/lib/sharklog/location.h_):

      /*! 
        The following macro and defines section is used to define
        different location information in different compilers, like
        msvc, mingw, gcc, and clang.
        */
      #if !defined(SHARKLOG_LOCATION)
          #if defined(_MSC_VER)
              #if _MSC_VER >= 1300
                  #define __SHARKLOG_FUNC__ __FUNCSIG__
              #endif
          #else
              #if defined(__GNUC__)
                  #define __SHARKLOG_FUNC__ __PRETTY_FUNCTION__
              #endif
          #endif
      
          #if !defined(__SHARKLOG_FUNC__)
              #define __SHARKLOG_FUNC__ ""
          #endif
      
      	//! This macro is used to generate location information for the logger, see \ref Location
          #define SHARKLOG_LOCATION sharklog::Location(__FILE__, __SHARKLOG_FUNC__, __LINE__)
      #endif
      

      That block handles all location tracking for logged lines on all the platforms I support. MSVC, mingw, g++, clang, etc.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      1
      • A Offline
        A Offline
        ambershark
        wrote on last edited by
        #3

        Oops I totally lied... I just tested it and it does do the full path. :( I could have swore it just did the actual file name.

        Anyway here is a post on a way to do it:
        https://stackoverflow.com/questions/8487986/file-macro-shows-full-path

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        Marco NilssonM 1 Reply Last reply
        0
        • A ambershark

          Oops I totally lied... I just tested it and it does do the full path. :( I could have swore it just did the actual file name.

          Anyway here is a post on a way to do it:
          https://stackoverflow.com/questions/8487986/file-macro-shows-full-path

          Marco NilssonM Offline
          Marco NilssonM Offline
          Marco Nilsson
          wrote on last edited by Marco Nilsson
          #4

          @ambershark said in Redefining __BASE_FILE__ with qmake:

          Oops I totally lied... I just tested it and it does do the full path. :( I could have swore it just did the actual file name.

          Anyway here is a post on a way to do it:
          https://stackoverflow.com/questions/8487986/file-macro-shows-full-path

          I've tried using the macro with strrchr/__builtin_strrchr but my gcc (4.4.7) does not modify the strings at compile time. It could be due to the very archaic gcc version but it's the best you've got on AVR32.

          It could be done if I could either find a way to get qmake to define the source file, or if I can get it to make inside the subfolder.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved