Skip to content

correct define to use on Windows only code #7446

Closed

Description

@dimitre

I've seen in different places of OF a define called TARGET_WIN32
like
#if defined(TARGET_WIN32)

is this true for all windows platform, including 64 bits?
should we use it or instead OF_TARGET_WINDOWS or something similar?
or maybe even better, have

OF_PLATFORM_WINDOWS
OF_PLATFORM_MACOS
OF_PLATFORM_LINUX

to define pieces of code that will run in all targets of the same platform?
thoughts?

Activity

  1. artificiel commented on Mar 30, 2023

    @artificiel
    Contributor

    to answer the first "direct" question: TARGET_WIN32 is defined in ofConstant.h if #ifdef _WIN32 , and here it stipulates that _WIN32 includes 64 bits.

    that being said there is a bit of chaos in ofConstants.h it seems the logic of the definitions is not consistent... there is an effort like your OF_PLATFORM_* idea around TARGET_OF_*, but windows is immediately skipping the rule with TARGET_WIN32. also there is TARGET_OF_IPHONE and TARGET_OF_IOS (Core seems to use only TARGET_OF_IOS but there are some addons that use TARGET_OF_IPHONE).

    so to answer the second question it seems the logical thing is to support the effort done in ofConstant to normalize TARGET_OF_*, but maybe fix windows to TARGET_OF_WIN32 (or TARGET_OF_WINDOWS as you suggest it is more inclusive and probably "modern") and make sure all the #ifdefs use the same pattern (while keeping the old TARGET_WIN32 for perennial addon compatibility).

    #if defined( __WIN32__ ) || defined( _WIN32 )
    #define TARGET_WIN32
    #if defined(_MSC_VER)
    #define TARGET_WINVS
    #endif
    #if defined(__MINGW32__) || defined(__MINGW64__)
    #define TARGET_MINGW
    #endif
    #elif defined( __APPLE_CC__)
    #define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
    #include <TargetConditionals.h>
    #if (TARGET_OS_IPHONE || TARGET_OS_IOS || TARGET_OS_SIMULATOR || TARGET_IPHONE_SIMULATOR) && !TARGET_OS_TV && !TARGET_OS_WATCH
    #define TARGET_OF_IPHONE
    #define TARGET_OF_IOS
    #define TARGET_OPENGLES
    #include <unistd.h>
    #elif TARGET_OS_TV
    #define TARGET_OF_IOS
    #define TARGET_OF_TVOS
    #define TARGET_OPENGLES
    #include <unistd.h>
    #elif TARGET_OS_WATCH
    #define TARGET_OF_IOS
    #define TARGET_OF_WATCHOS
    #define TARGET_OPENGLES
    #include <unistd.h>
    #else
    #define TARGET_OSX
    #endif
    #elif defined (__ANDROID__)
    #define TARGET_ANDROID
    #define TARGET_OPENGLES
    #elif defined(__ARMEL__)
    #define TARGET_LINUX
    #define TARGET_OPENGLES
    #define TARGET_LINUX_ARM
    #elif defined(__EMSCRIPTEN__)
    #define TARGET_EMSCRIPTEN
    #define TARGET_OPENGLES
    #define TARGET_PROGRAMMABLE_GL
    #define TARGET_IMPLEMENTS_URL_LOADER
    #else
    #define TARGET_LINUX
    #endif

  2. locked and limited conversation to collaborators on Mar 30, 2023
  3. converted this issue into a discussion #7450 on Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions