Skip to content

Commit

Permalink
Improvements for MSVC build. (#10521)
Browse files Browse the repository at this point in the history
  - Use our 3rdParty/regex library (omcregex) if we are using MSVC.

  - Disable ModelicaExternalC and ParModelica libraries if we are using MSVC.

  - Build `libOpenModelicaRuntimeC` as a static library if MSVC. It has some
    dll exporting conflicts with `libOpenModelicaCompiler`.

  - Export all symbols from `OMPlotLib.dll`
  • Loading branch information
mahge committed Apr 10, 2023
1 parent c0a709f commit 0807f0f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/3rdParty
16 changes: 14 additions & 2 deletions OMCompiler/SimulationRuntime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ if(OM_OMC_ENABLE_CPP_RUNTIME)
endif()

# ModelicaExternalC
omc_add_subdirectory(ModelicaExternalC)
# Disable ModelicaExternalC for MSVC since right now we are building static
# and shared versions of the library with the *same name*. This works on linux
# and MinGW because lib.a and lib.so. MSVC, however, wants to build an import
# lib (.lib) for DLLs. This conflicts with the static library (also .lib).
if(NOT MSVC)
omc_add_subdirectory(ModelicaExternalC)
endif()

# omc_add_subdirectory(opc)
omc_add_subdirectory(ParModelica)

# ParModelica
# Disable for MSVC. There are some issues with Boost which need to be fixed.
if(NOT MSVC)
omc_add_subdirectory(ParModelica)
endif()

#ADD_SUBDIRECTORY(cpp)
#ADD_SUBDIRECTORY(interactive)

10 changes: 9 additions & 1 deletion OMCompiler/SimulationRuntime/c/cmake_3.14.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ file(GLOB_RECURSE OMC_SIMRT_OPTIMIZATION_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/opt

# ######################################################################################################################
# Library: OpenModelicaRuntimeC
add_library(OpenModelicaRuntimeC SHARED)
# For the moment, we build OpenModelicaRuntimeC as a static library with MSVC.
# It has some dll exporting issues in it that need to be resolved.
if(MSVC)
add_library(OpenModelicaRuntimeC STATIC)
else()
add_library(OpenModelicaRuntimeC SHARED)
endif()

add_library(omc::simrt::runtime ALIAS OpenModelicaRuntimeC)

target_sources(OpenModelicaRuntimeC PRIVATE ${OMC_SIMRT_GC_SOURCES} ${OMC_SIMRT_UTIL_SOURCES} ${OMC_SIMRT_META_SOURCES})
Expand All @@ -51,6 +58,7 @@ if(MINGW)
target_link_libraries(OpenModelicaRuntimeC PUBLIC regex)
target_link_options(OpenModelicaRuntimeC PRIVATE -Wl,--export-all-symbols)
elseif(MSVC)
target_link_libraries(OpenModelicaRuntimeC PUBLIC omc::3rd::regex)
set_target_properties(OpenModelicaRuntimeC PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS true)
endif()

Expand Down
4 changes: 4 additions & 0 deletions OMPlot/OMPlot/OMPlotGUI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ set(OMPLOTLIB_HEADERS OMPlot.h
add_library(OMPlotLib SHARED ${OMPLOTLIB_SOURCES} ${OMPLOTLIB_HEADERS})
target_compile_definitions(OMPlotLib PRIVATE OMPLOTLIB_MOC_INCLUDE)

if(MSVC)
set_target_properties(OMPlotLib PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS true)
endif()

target_include_directories(OMPlotLib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(OMPlotLib PUBLIC Qt5::Widgets)
Expand Down

0 comments on commit 0807f0f

Please sign in to comment.