Skip to content

Commit e43197e

Browse files
authored
Fixes for Windows build with new MSYS2 (#9683)
* Fixes for Windows build with new MSYS2 - Minor changes to CMake and make files - Should be possible to build with old an new msys using CMake. * OMEdit: Added include directory of binutils to INCLUDEPATH.
1 parent 3047cde commit e43197e

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

OMCompiler/Compiler/runtime/systemimpl.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ extern "C" {
5252
#include <stdio.h>
5353
#include <stdlib.h>
5454
#include <string.h>
55-
#if defined(__MINGW32__)
56-
#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L /* for ctime_r in time.h */
57-
#endif
5855
#include <time.h>
5956
#include <math.h>
6057

@@ -3005,7 +3002,7 @@ char* SystemImpl__ctime(double time)
30053002
{
30063003
char buf[64] = {0}; /* needs to be >=26 char */
30073004
time_t t = (time_t) time;
3008-
#if defined(_MSC_VER)
3005+
#if defined(__MINGW32__) || defined(_MSC_VER)
30093006
errno_t e = ctime_s(buf, 64, t);
30103007
assert(e == 0 && "ctime_s returned an error");
30113008
return omc_alloc_interface.malloc_strdup(buf);

OMEdit/OMEditGUI/OMEditGUI.win.config.pri

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ CONFIG(release, debug|release) { # release
4848
# win32 vs. win64
4949
contains(QT_ARCH, i386) { # 32-bit
5050
LIBS += -L$$(OMDEV)/tools/msys/mingw32/lib/binutils -L$$(OMDEV)/tools/msys/mingw32/bin
51+
INCLUDEPATH += $$(OMDEV)/tools/msys/mingw32/include/binutils
5152
} else { # 64-bit
5253
LIBS += -L$$(OMDEV)/tools/msys/mingw64/lib/binutils -L$$(OMDEV)/tools/msys/mingw64/bin
54+
INCLUDEPATH += $$(OMDEV)/tools/msys/mingw64/include/binutils
5355
}
5456
LIBS += -limagehlp -lbfd -lintl -liberty -llibosg.dll -llibosgViewer.dll -llibOpenThreads.dll -llibosgDB.dll -llibosgGA.dll
5557
} else { # debug

OMEdit/OMEditLIB/CrashReport/backtrace.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#define GCC_VERSION (__GNUC__ * 10000 \
2020
+ __GNUC_MINOR__ * 100 \
21-
+ __GNUC_PATCHLEVEL__)
21+
+ __GNUC_PATCHLEVEL__)
2222

2323
#if defined(_WIN32)
2424
#ifdef __cplusplus
@@ -30,10 +30,8 @@ extern "C" {
3030
#include <imagehlp.h>
3131
#if defined(__MINGW32__) && ((GCC_VERSION > 40900) || defined(__clang__))
3232
#define PACKAGE OMEdit
33-
#include <binutils/bfd.h>
34-
#else
35-
#include <bfd.h>
3633
#endif
34+
#include <bfd.h>
3735
#include <psapi.h>
3836
#include <stdlib.h>
3937
#include <stdio.h>

OMEdit/OMEditLIB/OMEditLIB.pro

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ CONFIG(release, debug|release) { # release
7575
QMAKE_LFLAGS_RELEASE =
7676
}
7777

78+
# On older msys the include directory for binutils is in binutils
79+
# On recent (November 2022) MSYS2 this is no longer needed.
80+
contains(QT_ARCH, i386) { # 32-bit
81+
INCLUDEPATH += $$(OMDEV)/tools/msys/mingw32/include/binutils
82+
} else { # 64-bit
83+
INCLUDEPATH += $$(OMDEV)/tools/msys/mingw64/include/binutils
84+
}
85+
7886
OPENMODELICAHOME = $$(OMBUILDDIR)
7987
host_short =
8088

cmake/modules/Findbinutils.cmake

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,29 @@ if(binutils_FOUND)
1010
endif()
1111

1212
find_library(LIBBFD_LIBRARY
13-
NAMES libbfd.a
14-
PATH_SUFFIXES binutils)
13+
NAMES libbfd.a
14+
PATH_SUFFIXES binutils)
1515

1616
find_library(LIBIBERTY_LIBRARY
17-
NAMES libiberty.a
18-
PATH_SUFFIXES binutils)
19-
17+
NAMES libiberty.a
18+
PATH_SUFFIXES binutils)
19+
20+
if(MINGW)
21+
find_path(BINUTILS_INCLUDE_DIR
22+
bfd.h
23+
PATHS include
24+
PATH_SUFFIXES binutils)
25+
endif()
2026

2127
include (FindPackageHandleStandardArgs)
2228

2329

2430
# handle the QUIETLY and REQUIRED arguments and set binutils_FOUND to TRUE if all listed variables are TRUE
2531
find_package_handle_standard_args(binutils
26-
REQUIRED_VARS LIBBFD_LIBRARY LIBIBERTY_LIBRARY
32+
REQUIRED_VARS LIBBFD_LIBRARY LIBIBERTY_LIBRARY BINUTILS_INCLUDE_DIR
2733
HANDLE_COMPONENTS)
2834

29-
mark_as_advanced(LIBBFD_LIBRARY LIBIBERTY_LIBRARY)
35+
mark_as_advanced(LIBBFD_LIBRARY LIBIBERTY_LIBRARY BINUTILS_INCLUDE_DIR)
3036

3137
if(binutils_FOUND)
3238

@@ -37,6 +43,7 @@ if(binutils_FOUND)
3743

3844
add_library(binutils::bfd STATIC IMPORTED)
3945
set_target_properties(binutils::bfd PROPERTIES IMPORTED_LOCATION ${LIBBFD_LIBRARY})
46+
set_target_properties(binutils::bfd PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${BINUTILS_INCLUDE_DIR})
4047

4148
target_link_libraries(binutils::bfd INTERFACE binutils::iberty)
4249
target_link_libraries(binutils::bfd INTERFACE ${Intl_LIBRARIES})

0 commit comments

Comments
 (0)