Skip to content

Commit a2580f7

Browse files
cmake build support for mingw32
1 parent f2202dd commit a2580f7

File tree

9 files changed

+54
-13
lines changed

9 files changed

+54
-13
lines changed

Modelica_DeviceDrivers/Communication/UDPSocket.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ encapsulated function constructor
1010
external "C" socket = MDD_udpConstructor(port,bufferSize)
1111
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",
1212
Include = "#include \"MDDUDPSocket.h\" ",
13-
Library = "pthread",
13+
Library = {"pthread", "Ws2_32"},
1414
__iti_dll = "ITI_MDD.dll");
1515
end constructor;
1616

@@ -20,7 +20,7 @@ encapsulated function destructor
2020
external "C" MDD_udpDestructor(socket)
2121
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",
2222
Include = "#include \"MDDUDPSocket.h\" ",
23-
Library = "pthread",
23+
Library = {"pthread", "Ws2_32"},
2424
__iti_dll = "ITI_MDD.dll");
2525
end destructor;
2626

Modelica_DeviceDrivers/Communication/UDPSocket_.mo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ output String data;
88
external "C" data = MDD_udpRead(socket)
99
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",
1010
Include = "#include \"MDDUDPSocket.h\" ",
11-
Library = "pthread",
11+
Library = {"pthread", "Ws2_32"},
1212
__iti_dll = "ITI_MDD.dll");
1313
end read;
1414

@@ -22,7 +22,7 @@ encapsulated function sendTo
2222
external "C" MDD_udpSend(socket, ipAddress, port, data, dataSize)
2323
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",
2424
Include = "#include \"MDDUDPSocket.h\" ",
25-
Library = "pthread",
25+
Library = {"pthread", "Ws2_32"},
2626
__iti_dll = "ITI_MDD.dll");
2727
end sendTo;
2828

@@ -33,7 +33,7 @@ encapsulated function getReceivedBytes
3333
external "C" receivedBytes = MDD_udpGetReceivedBytes(socket)
3434
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",
3535
Include = "#include \"MDDUDPSocket.h\" ",
36-
Library = "pthread",
36+
Library = {"pthread", "Ws2_32"},
3737
__iti_dll = "ITI_MDD.dll");
3838
end getReceivedBytes;
3939
end UDPSocket_;

Modelica_DeviceDrivers/Resources/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ if (UNIX)
3535
add_subdirectory(src/DummyWinmmLibrary)
3636
# Dummy Linux User32 library for uniform treatment of GCC and MS Visual C within Modelica
3737
add_subdirectory(src/DummyUser32Library)
38+
# Dummy Linux Ws2_32 library for uniform treatment of GCC and MS Visual C within Modelica
39+
add_subdirectory(src/DummyWs2_32Library)
3840
# Are we trying to force compilation for linux32 on a native linux64 platform?
3941
if ( ($ENV{CFLAGS} MATCHES "-m32") AND ($ENV{CXXFLAGS} MATCHES "-m32") )
4042
set(M32_FLAG TRUE)

Modelica_DeviceDrivers/Resources/Include/MDDUDPSocket.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121

2222
#include "ModelicaUtilities.h"
2323

24-
#if defined(_MSC_VER) || defined(__MINGW32__)
24+
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
2525

2626
#include <windows.h>
2727
#include "../src/include/CompatibilityDefs.h"
2828

29-
#pragma comment( lib, "Ws2_32.lib" )
30-
3129
typedef struct MDDUDPSocket_s MDDUDPSocket;
3230

3331
struct MDDUDPSocket_s {
@@ -187,7 +185,7 @@ DllExport int MDD_udpGetReceivedBytes(void * p_udp) {
187185
return receivedBytes;
188186
}
189187

190-
#elif defined(__linux__) || defined(__CYGWIN__)
188+
#elif defined(__linux__)
191189

192190
#include <stdlib.h>
193191
#include <string.h> /* memset(..) */
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
message(STATUS "WRITING BUILD FILES FOR DummyWs2_32Library")
2+
#message(STATUS "${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}")
3+
4+
set(libSrcsMDDDummyWs2_32Library MDDDummyWs2_32Library.c)
5+
6+
add_library(Ws2_32 SHARED ${libSrcsMDDDummyWs2_32Library})
7+
8+
# install to directory (CMAKE_INSTALL_PREFIX) into subdirectory "lib"
9+
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
10+
install(TARGETS rt DESTINATION Library/linux64)
11+
elseif ( CMAKE_SIZEOF_VOID_P EQUAL 4 )
12+
install(TARGETS rt DESTINATION Library/linux32)
13+
else ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
14+
message(SEND_ERROR "Uups. Shouldn't be possible to get here")
15+
endif ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
16+
17+
18+
19+
20+
21+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** Dummy library for uniform treatment of Modelica external function in windows and linux.
2+
*
3+
* @file
4+
* @author Bernhard Thiele
5+
* @since 2015-04-18
6+
* @copyright Modelica License 2
7+
* For windows, various functions need to link the User32.lib library.
8+
* However, Linux neither provides nor requires this library for the implemented functions.
9+
*
10+
* - <B>The problem</B>: We need to specify in Modelica to link the User32.lib library if running on Windows, but
11+
* it is not needed for Linux (and results in a linking error if specified in the
12+
* annotation).
13+
* - <B>The workaround</B>: We provide a dummy libUser32.a library for Linux, so that linking won't result in an
14+
* error. This is not nice for several reasons and good suggestions how to solve that
15+
* differently are welcome.
16+
*/
17+
18+
static void MDD_dummy(void);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Dummy library for Linux.

Modelica_DeviceDrivers/Resources/src/ITI_ModelicaDeviceDrivers/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ else ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
1919
endif ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
2020

2121
add_library(ITI_MDD SHARED ${libSrcsITI_MDDLibrary})
22-
target_link_libraries(ITI_MDD ${MODELICA_EXTERNAL_C})
22+
target_link_libraries(ITI_MDD Winmm Ws2_32 ${MODELICA_EXTERNAL_C})
2323

2424
if ( CANL2_LIBRARY )
2525
add_library(ITI_MDDSoftingCAN SHARED ${libSrcsITI_MDDSoftingCANLibrary})

Modelica_DeviceDrivers/Resources/test/Communication/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ endif (UNIX)
1616
add_executable(test_MDDUDPSocket test_MDDUDPSocket.c ../Util/ModelicaUtilities.c)
1717
if (UNIX)
1818
target_link_libraries(test_MDDUDPSocket ${CMAKE_THREAD_LIBS_INIT})
19+
else (UNIX)
20+
# assume we are in windows
21+
target_link_libraries(test_MDDUDPSocket Ws2_32)
1922
endif (UNIX)
2023
add_test(test_MDDUDPSocket
2124
${EXECUTABLE_OUTPUT_PATH}/test_MDDUDPSocket)
@@ -30,10 +33,8 @@ add_test(test_MDDSerialPackager
3033

3134
add_executable(test_MDDSharedMemory
3235
test_MDDSharedMemory.c ../Util/ModelicaUtilities.c)
33-
if (NOT MSVC)
34-
target_link_libraries(test_MDDSharedMemory rt)
35-
endif (NOT MSVC)
3636
if (UNIX)
37+
target_link_libraries(test_MDDSharedMemory rt)
3738
target_link_libraries(test_MDDSharedMemory ${CMAKE_THREAD_LIBS_INIT})
3839
endif (UNIX)
3940
add_test(test_MDDSharedMemory

0 commit comments

Comments
 (0)