Skip to content

Commit

Permalink
Improve compatibility with other Compilers like MinGW (#8387)
Browse files Browse the repository at this point in the history
* Make preprocessor conditions depend on os

The __GNU__ flag is used in situations where an OS
dependent flag should be used instead because the
changes in the source files are not compiler
dependent

Signed-off-by: Marius Meyer <[email protected]>

* Fix upper case in include

Signed-off-by: Marius Meyer <[email protected]>

* Fix libxrt_core windows link dependencies

Signed-off-by: Marius Meyer <[email protected]>

* Fix xbutil2 windows link dependencies

Signed-off-by: Marius Meyer <[email protected]>

* Fix xclbinutil windows link dependencies

Signed-off-by: Marius Meyer <[email protected]>

* Only define types if GCC is not used

Signed-off-by: Marius Meyer <[email protected]>

* Remove DLL exports and imports from header-defined methods

Signed-off-by: Marius Meyer <[email protected]>

---------

Signed-off-by: Marius Meyer <[email protected]>
Co-authored-by: Marius Meyer <[email protected]>
  • Loading branch information
Mellich and Marius Meyer authored Sep 4, 2024
1 parent ea90b89 commit 2c97fe5
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/runtime_src/core/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# define XRT_CORE_COMMON_EXPORT __declspec(dllimport)
# endif
#endif
#ifdef __GNUC__
#ifdef __linux__
# ifdef XRT_CORE_COMMON_SOURCE
# define XRT_CORE_COMMON_EXPORT __attribute__ ((visibility("default")))
# else
Expand All @@ -39,7 +39,7 @@
# define XRT_CORE_COMMON_EXPORT
#endif

#ifdef __GNUC__
#ifdef __linux__
# define XRT_CORE_UNUSED __attribute__((unused))
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/common/config_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ is_true(const std::string& str)
static std::string
get_self_path()
{
#ifdef __GNUC__
#ifdef __linux__
char buf[PATH_MAX] = {0};
auto len = ::readlink("/proc/self/exe", buf, PATH_MAX);
return std::string(buf, (len>0) ? len : 0);
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/common/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef _WIN32
#include <unistd.h>
#else
#include <Shlobj.h>
#include <shlobj.h>
#endif

namespace xrt_core {
Expand Down
2 changes: 2 additions & 0 deletions src/runtime_src/core/include/windows/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

#include <stdint.h>

#ifndef __GNU__
typedef int64_t ssize_t;
typedef int pid_t;
#endif

#endif
2 changes: 1 addition & 1 deletion src/runtime_src/core/include/xrt/detail/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# define XRT_API_EXPORT __declspec(dllimport)
# endif
#endif
#ifdef __GNUC__
#ifdef __linux__
# ifdef XRT_API_SOURCE
# define XRT_API_EXPORT __attribute__ ((visibility("default")))
# else
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/pcie/noop/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# define XRT_CORE_PCIE_NOOP_EXPORT __declspec(dllimport)
# endif
#endif
#ifdef __GNUC__
#ifdef __linux__
# ifdef XRT_CORE_PCIE_NOOP_SOURCE
# define XRT_CORE_PCIE_NOOP_EXPORT __attribute__ ((visibility("default")))
# else
Expand Down
7 changes: 7 additions & 0 deletions src/runtime_src/core/pcie/windows/alveo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ target_link_libraries(xrt_core
xrt_coreutil
)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(xrt_core
PRIVATE
setupapi
)
endif()

# For DLL platforms the DLL part of a shared library is treated as a
# RUNTIME target and the corresponding import library is treated as an
# ARCHIVE target. All Windows-based systems including Cygwin are DLL
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/pcie/windows/alveo/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# define XRT_CORE_PCIE_WINDOWS_EXPORT __declspec(dllimport)
# endif
#endif
#ifdef __GNUC__
#ifdef __linux__
# ifdef XRT_CORE_PCIE_WINDOWS_SOURCE
# define XRT_CORE_PCIE_WINDOWS_EXPORT __attribute__ ((visibility("default")))
# else
Expand Down
4 changes: 4 additions & 0 deletions src/runtime_src/core/tools/xbutil2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ target_link_libraries(${XBUTIL2_NAME}

if (NOT WIN32)
target_link_libraries(${XBUTIL2_NAME} PRIVATE pthread uuid dl)
else()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(${XBUTIL2_NAME} PRIVATE ws2_32)
endif()
endif()

# Package xrt sub commands json file for embedded builds
Expand Down
5 changes: 5 additions & 0 deletions src/runtime_src/tools/xclbinutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ if(NOT WIN32)
target_link_libraries(${XCLBINUTIL_NAME} PRIVATE transformcdo)
endif()

# Link required windows specific libraries with MinGW
if(WIN32 AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
target_link_libraries(${XCLBINUTIL_NAME} PRIVATE wsock32 ws2_32)
endif()

install (TARGETS ${XCLBINUTIL_NAME} RUNTIME DESTINATION ${XRT_INSTALL_UNWRAPPED_DIR})
install (PROGRAMS ${XRT_LOADER_SCRIPTS} DESTINATION ${XRT_INSTALL_BIN_DIR})

Expand Down
4 changes: 2 additions & 2 deletions src/runtime_src/xdp/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define XDP_CORE_EXPORT __declspec(dllimport)
#endif
#endif
#ifdef __GNUC__
#ifdef __linux__
#ifdef XDP_CORE_SOURCE
#define XDP_CORE_EXPORT __attribute__ ((visibility("default")))
#else
Expand All @@ -47,7 +47,7 @@
#define XDP_PLUGIN_EXPORT __declspec(dllimport)
#endif
#endif
#ifdef __GNUC__
#ifdef __linux__
#ifdef XDP_PLUGIN_SOURCE
#define XDP_PLUGIN_EXPORT __attribute__ ((visibility("default")))
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace xdp {
uint64_t devId, uint32_t monId, int32_t cuIdx);
XDP_CORE_EXPORT ~KernelEvent();

XDP_CORE_EXPORT virtual int32_t getCUId() { return cuId; }
virtual int32_t getCUId() { return cuId; }
XDP_CORE_EXPORT virtual void dump(std::ofstream& fout, uint32_t bucket) ;
};

Expand Down
6 changes: 3 additions & 3 deletions src/runtime_src/xdp/profile/database/events/native_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace xdp {
XDP_CORE_EXPORT NativeAPICall(uint64_t s_id, double ts, uint64_t name);
XDP_CORE_EXPORT ~NativeAPICall() = default;

XDP_CORE_EXPORT virtual bool isNativeHostEvent() { return true; }
virtual bool isNativeHostEvent() { return true; }

XDP_CORE_EXPORT virtual void dump(std::ofstream& fout, uint32_t bucket);
};
Expand All @@ -41,7 +41,7 @@ namespace xdp {
XDP_CORE_EXPORT NativeSyncRead(uint64_t s_id, double ts, uint64_t name);
XDP_CORE_EXPORT ~NativeSyncRead() = default;

XDP_CORE_EXPORT virtual bool isNativeRead() override { return true; }
virtual bool isNativeRead() override { return true; }

// For printing out the event in a different bucket as a different
// type of event, without having to store additional events in the database
Expand All @@ -56,7 +56,7 @@ namespace xdp {
XDP_CORE_EXPORT NativeSyncWrite(uint64_t s_id, double ts, uint64_t name);
XDP_CORE_EXPORT ~NativeSyncWrite() = default;

XDP_CORE_EXPORT virtual bool isNativeWrite() override { return true; }
virtual bool isNativeWrite() override { return true; }

// For printing out the event in a different bucket as a different
// type of event, without having to store additional events in the databaes
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/xdp/profile/database/events/vtf_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace xdp {

virtual uint64_t getDevice() { return 0 ; } // CHECK
XDP_CORE_EXPORT virtual void dump(std::ofstream& fout, uint32_t bucket) ;
XDP_CORE_EXPORT virtual void dumpSync(std::ofstream& /*fout*/, uint32_t /*bucket*/) {};
virtual void dumpSync(std::ofstream& /*fout*/, uint32_t /*bucket*/) {};
} ;

// Used so the database can sort based on timestamp order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace xdp {
inline bool isNoDMA() const { return isNoDMADevice ; }
double getMaxClockRatePLMHz();

XDP_CORE_EXPORT void setAIEGeneration(uint8_t hw_gen) { aieGeneration = hw_gen; }
void setAIEGeneration(uint8_t hw_gen) { aieGeneration = hw_gen; }
inline uint8_t getAIEGeneration() const { return aieGeneration ; }

// ****** Functions for information on the currently loaded xclbin *******
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/xocl/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# endif
#endif

#ifdef __GNUC__
#ifdef __linux__
# ifdef XRT_XOCL_SOURCE
# define XRT_XOCL_EXPORT __attribute__ ((visibility("default")))
# else
Expand Down
4 changes: 2 additions & 2 deletions src/runtime_src/xrt/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# define XRT_EXPORT __declspec(dllimport)
# endif
#endif
#ifdef __GNUC__
#ifdef __linux__
# ifdef XRT_SOURCE
# define XRT_EXPORT __attribute__ ((visibility("default")))
# else
Expand All @@ -38,7 +38,7 @@
# define XRT_EXPORT
#endif

#ifdef __GNUC__
#ifdef __linux__
# define XRT_UNUSED __attribute__((unused))
#endif

Expand Down

0 comments on commit 2c97fe5

Please sign in to comment.