Skip to content

Commit

Permalink
[cmake] Add support for OMEdit.
Browse files Browse the repository at this point in the history
  - OMEdit can now be compiled using CMake.
    - It might not be as complete and as functional as the default
      build's OMEdit.

    - There are some things definitely missing but there might be more as
      well. It needs to be cheked and improved.

  - There are three new targets:
    - libGDBMIParser
    - libOMEditLib
    - OMEdit

  - Both lib targets are build as static libs for now.
  • Loading branch information
mahge committed Dec 3, 2021
1 parent 11078b7 commit 21450d7
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Expand Up @@ -123,8 +123,10 @@ omc_add_subdirectory(OMParser EXCLUDE_FROM_ALL)
omc_add_subdirectory(OMPlot EXCLUDE_FROM_ALL)
omc_add_subdirectory(OMShell EXCLUDE_FROM_ALL)
omc_add_subdirectory(OMNotebook EXCLUDE_FROM_ALL)
# omc_add_subdirectory(libraries)

include(omsimulator.cmake)
omc_add_subdirectory(OMEdit EXCLUDE_FROM_ALL)
# omc_add_subdirectory(libraries)


## Report some status info.
Expand Down
14 changes: 10 additions & 4 deletions OMCompiler/Compiler/CMakeLists.txt
Expand Up @@ -190,6 +190,16 @@ add_library(OpenModelicaCompiler SHARED ${OMC_C_SOURCE_FILES} .cmake/omc_entry_p

target_compile_definitions(OpenModelicaCompiler PRIVATE ADD_METARECORD_DEFINITIONS=)

# There is a lonely omc_file.h in Util/. It belongs in runtime/. Remove this when it is moved.
target_include_directories(OpenModelicaCompiler PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Util)

# This should not be needed ideally. However linking libs sometimes need to include the generated headers.
# Right now this only happens for OMEdit. OMEdit includes Script/OpenModelicaScriptingAPIQt.h
# which in turn wants to include OpenModelicaScriptingAPI.h. This header is generated from
# translation of OpenModelicaScriptingAPI.mo. So this interface include dir is needed.
# We can maybe copy these headers to some specific location after generation and avoid this.
target_include_directories(OpenModelicaCompiler INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/c_files)

# OMC will overflow the stack (at least on Windows old OMDev) on very deep recursive calls.
# E.g., try translating the CodegenCpp* tpl files to mo files with
# an omc not compiled without large stack size. The tpl parser is quite recursive and will
Expand All @@ -202,10 +212,6 @@ target_compile_definitions(OpenModelicaCompiler PRIVATE ADD_METARECORD_DEFINITIO
add_dependencies(OpenModelicaCompiler DEPENDENCY_UPDATE)


# There is a lonely omc_file.h in Util/. It belongs in runtime/. Remove this when it is moved.
target_include_directories(OpenModelicaCompiler PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Util)


target_link_libraries(OpenModelicaCompiler PUBLIC omc::parser)
target_link_libraries(OpenModelicaCompiler PUBLIC omc::compiler::backendruntime)
target_link_libraries(OpenModelicaCompiler PUBLIC omc::compiler::runtime)
Expand Down
25 changes: 25 additions & 0 deletions OMEdit/CMakeLists.txt
@@ -0,0 +1,25 @@
cmake_minimum_required (VERSION 3.14)

project(OMEdit)

## Set the C++ standard to use.
set(CMAKE_CXX_STANDARD 14)
set(CXX_STANDARD_REQUIRED ON)
## Make sure we do not start relying on extensions down the road.
set(CMAKE_CXX_EXTENSIONS OFF)


find_package(Qt5 COMPONENTS Widgets PrintSupport WebKitWidgets Xml XmlPatterns OpenGL Network REQUIRED)
find_package(OpenSceneGraph COMPONENTS osgViewer osgDB osgGA REQUIRED)

# Configure omedit_config.h. This will be generated in the build directory
configure_file(omedit_config.h.in omedit_config.h)
## Add a config library for OMEdit. They will provide access to common config headres such as
## config.h. So by linking to this library you get the include directories.
add_library(omedit_config INTERFACE)
add_library(omedit::config ALIAS omedit_config)
target_include_directories(omedit_config INTERFACE ${CMAKE_CURRENT_BINARY_DIR})

omc_add_subdirectory(OMEditLIB)
omc_add_subdirectory(OMEditGUI)

7 changes: 7 additions & 0 deletions OMEdit/OMEditGUI/CMakeLists.txt
@@ -0,0 +1,7 @@


add_executable(OMEdit main.cpp rc_omedit.rc)

target_link_libraries(OMEdit PRIVATE OMEditLib)

install(TARGETS OMEdit)
291 changes: 291 additions & 0 deletions OMEdit/OMEditLIB/CMakeLists.txt
@@ -0,0 +1,291 @@
# file(GLOB_RECURSE OMEDITLIB_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)

# file(GLOB_RECURSE OMEDITLIB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
# set(OMEDITLIB_SOURCES resource_omedit.qrc ${OMEDITLIB_SOURCES})

omc_add_subdirectory(Debugger/Parser)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(OMEDITLIB_SOURCES Util/Helper.cpp
Util/Utilities.cpp
Util/StringHandler.cpp
Util/OutputPlainTextEdit.cpp
MainWindow.cpp
OMC/OMCProxy.cpp
Modeling/MessagesWidget.cpp
Modeling/ItemDelegate.cpp
Modeling/LibraryTreeWidget.cpp
Modeling/Commands.cpp
Modeling/CoOrdinateSystem.cpp
Modeling/ModelWidgetContainer.cpp
Modeling/ModelicaClassDialog.cpp
Modeling/FunctionArgumentDialog.cpp
Modeling/InstallLibraryDialog.cpp
Search/SearchWidget.cpp
Options/OptionsDialog.cpp
Editors/BaseEditor.cpp
Editors/ModelicaEditor.cpp
Editors/TransformationsEditor.cpp
Editors/TextEditor.cpp
Editors/CEditor.cpp
Editors/CompositeModelEditor.cpp
Editors/OMSimulatorEditor.cpp
Editors/MetaModelicaEditor.cpp
Editors/HTMLEditor.cpp
Plotting/PlotWindowContainer.cpp
Element/Element.cpp
Annotations/ShapeAnnotation.cpp
Element/CornerItem.cpp
Annotations/LineAnnotation.cpp
Annotations/PolygonAnnotation.cpp
Annotations/RectangleAnnotation.cpp
Annotations/EllipseAnnotation.cpp
Annotations/TextAnnotation.cpp
Annotations/BitmapAnnotation.cpp
Annotations/DynamicAnnotation.cpp
Annotations/BooleanAnnotation.cpp
Annotations/ColorAnnotation.cpp
Annotations/ExtentAnnotation.cpp
Annotations/PointAnnotation.cpp
Annotations/RealAnnotation.cpp
Annotations/StringAnnotation.cpp
Element/ElementProperties.cpp
Element/Transformation.cpp
Modeling/DocumentationWidget.cpp
Simulation/TranslationFlagsWidget.cpp
Simulation/SimulationDialog.cpp
Simulation/SimulationOutputWidget.cpp
Simulation/SimulationOutputHandler.cpp
Simulation/OpcUaClient.cpp
Simulation/ArchivedSimulationsWidget.cpp
TLM/FetchInterfaceDataDialog.cpp
TLM/FetchInterfaceDataThread.cpp
TLM/TLMCoSimulationDialog.cpp
TLM/TLMCoSimulationOutputWidget.cpp
TLM/TLMCoSimulationThread.cpp
FMI/ImportFMUDialog.cpp
FMI/ImportFMUModelDescriptionDialog.cpp
Plotting/VariablesWidget.cpp
Plotting/DiagramWindow.cpp
Options/NotificationsDialog.cpp
Annotations/ShapePropertiesDialog.cpp
TransformationalDebugger/OMDumpXML.cpp
TransformationalDebugger/diff_match_patch.cpp
TransformationalDebugger/TransformationsWidget.cpp
Debugger/GDB/CommandFactory.cpp
Debugger/GDB/GDBAdapter.cpp
Debugger/StackFrames/StackFramesWidget.cpp
Debugger/Locals/LocalsWidget.cpp
Debugger/Locals/ModelicaValue.cpp
Debugger/Breakpoints/BreakpointMarker.cpp
Debugger/Breakpoints/BreakpointsWidget.cpp
Debugger/Breakpoints/BreakpointDialog.cpp
Debugger/DebuggerConfigurationsDialog.cpp
Debugger/Attach/AttachToProcessDialog.cpp
Debugger/Attach/ProcessListModel.cpp
CrashReport/backtrace.c
CrashReport/GDBBacktrace.cpp
CrashReport/CrashReportDialog.cpp
Git/GitCommands.cpp
Git/CommitChangesDialog.cpp
Git/RevertCommitsDialog.cpp
Git/CleanDialog.cpp
OMEditApplication.cpp
Traceability/TraceabilityGraphViewWidget.cpp
Traceability/TraceabilityInformationURI.cpp
OMS/OMSProxy.cpp
OMS/ModelDialog.cpp
OMS/BusDialog.cpp
OMS/ElementPropertiesDialog.cpp
OMS/SystemSimulationInformationDialog.cpp
OMS/OMSSimulationDialog.cpp
OMS/OMSSimulationOutputWidget.cpp
Animation/TimeManager.cpp
Util/ResourceCache.cpp
Util/NetworkAccessManager.cpp
FlatModelica/Expression.cpp
FlatModelica/ExpressionFuncs.cpp
Animation/OpenGLWidget.cpp
Animation/AbstractAnimationWindow.cpp
Animation/ViewerWidget.cpp
Animation/AnimationWindow.cpp
Animation/ThreeDViewer.cpp
Animation/ExtraShapes.cpp
Animation/Visualizer.cpp
Animation/VisualizerMAT.cpp
Animation/VisualizerCSV.cpp
Animation/VisualizerFMU.cpp
Animation/FMUSettingsDialog.cpp
Animation/FMUWrapper.cpp
Animation/Shapes.cpp
resource_omedit.qrc)


set(OMEDITLIB_HEADERS Util/Helper.h
Util/Utilities.h
Util/StringHandler.h
Util/OutputPlainTextEdit.h
MainWindow.h
OMC/OMCProxy.h
Modeling/MessagesWidget.h
Modeling/ItemDelegate.h
Modeling/LibraryTreeWidget.h
Modeling/Commands.h
Modeling/CoOrdinateSystem.h
Modeling/ModelWidgetContainer.h
Modeling/ModelicaClassDialog.h
Modeling/FunctionArgumentDialog.h
Modeling/InstallLibraryDialog.h
Search/SearchWidget.h
Options/OptionsDialog.h
Editors/BaseEditor.h
Editors/ModelicaEditor.h
Editors/TransformationsEditor.h
Editors/TextEditor.h
Editors/CEditor.h
Editors/CompositeModelEditor.h
Editors/OMSimulatorEditor.h
Editors/MetaModelicaEditor.h
Editors/HTMLEditor.h
Plotting/PlotWindowContainer.h
Element/Element.h
Annotations/ShapeAnnotation.h
Element/CornerItem.h
Annotations/LineAnnotation.h
Annotations/PolygonAnnotation.h
Annotations/RectangleAnnotation.h
Annotations/EllipseAnnotation.h
Annotations/TextAnnotation.h
Annotations/BitmapAnnotation.h
Annotations/DynamicAnnotation.h
Annotations/BooleanAnnotation.h
Annotations/ColorAnnotation.h
Annotations/ExtentAnnotation.h
Annotations/PointAnnotation.h
Annotations/RealAnnotation.h
Annotations/StringAnnotation.h
Element/ElementProperties.h
Element/Transformation.h
Modeling/DocumentationWidget.h
Simulation/SimulationOptions.h
Simulation/TranslationFlagsWidget.h
Simulation/SimulationDialog.h
Simulation/SimulationOutputWidget.h
Simulation/SimulationOutputHandler.h
Simulation/OpcUaClient.h
Simulation/ArchivedSimulationsWidget.h
TLM/FetchInterfaceDataDialog.h
TLM/FetchInterfaceDataThread.h
TLM/TLMCoSimulationOptions.h
TLM/TLMCoSimulationDialog.h
TLM/TLMCoSimulationOutputWidget.h
TLM/TLMCoSimulationThread.h
FMI/ImportFMUDialog.h
FMI/ImportFMUModelDescriptionDialog.h
Plotting/VariablesWidget.h
Plotting/DiagramWindow.h
Options/NotificationsDialog.h
Annotations/ShapePropertiesDialog.h
TransformationalDebugger/OMDumpXML.cpp
TransformationalDebugger/diff_match_patch.h
TransformationalDebugger/TransformationsWidget.h
Debugger/GDB/CommandFactory.h
Debugger/GDB/GDBAdapter.h
Debugger/StackFrames/StackFramesWidget.h
Debugger/Locals/LocalsWidget.h
Debugger/Locals/ModelicaValue.h
Debugger/Breakpoints/BreakpointMarker.h
Debugger/Breakpoints/BreakpointsWidget.h
Debugger/Breakpoints/BreakpointDialog.h
Debugger/DebuggerConfigurationsDialog.h
Debugger/Attach/AttachToProcessDialog.h
Debugger/Attach/ProcessListModel.h
CrashReport/backtrace.h
CrashReport/GDBBacktrace.h
CrashReport/CrashReportDialog.h
Git/GitCommands.h
Git/CommitChangesDialog.h
Git/RevertCommitsDialog.h
Git/CleanDialog.h
OMEditApplication.h
Traceability/TraceabilityGraphViewWidget.h
Traceability/TraceabilityInformationURI.h
OMS/OMSProxy.h
OMS/ModelDialog.h
OMS/BusDialog.h
OMS/ElementPropertiesDialog.h
OMS/SystemSimulationInformationDialog.h
OMS/OMSSimulationDialog.h
OMS/OMSSimulationOutputWidget.h
Animation/TimeManager.h
Interfaces/InformationInterface.h
Interfaces/ModelInterface.h
Util/ResourceCache.h
Util/NetworkAccessManager.h
FlatModelica/Expression.h
FlatModelica/ExpressionFuncs.h
Animation/OpenGLWidget.h
Animation/AbstractAnimationWindow.h
Animation/ViewerWidget.h
Animation/AnimationWindow.h
Animation/ThreeDViewer.h
Animation/AnimationUtil.h
Animation/ExtraShapes.h
Animation/Visualizer.h
Animation/VisualizerMAT.h
Animation/VisualizerCSV.h
Animation/VisualizerFMU.h
Animation/FMUSettingsDialog.h
Animation/FMUWrapper.h
Animation/Shapes.h
Animation/rapidxml.hpp)


# Add the OpenModelica generated files to sources
set(OMEDITLIB_HEADERS ${OMEDITLIB_HEADERS} ${OMCompiler_SOURCE_DIR}/Compiler/Script/OpenModelicaScriptingAPIQt.h)
set(OMEDITLIB_SOURCES ${OMEDITLIB_SOURCES} ${OMCompiler_SOURCE_DIR}/Compiler/Script/OpenModelicaScriptingAPIQt.cpp)
# Even though these are outputs of CMake custom commands, cmake fails to automatically recognize them as generated.
# My guess is that the directory difference is confusing it. So maunally mark them as generated.
set_source_files_properties(${OMCompiler_SOURCE_DIR}/Compiler/Script/OpenModelicaScriptingAPIQt.cpp GENERATED)
set_source_files_properties(${OMCompiler_SOURCE_DIR}/Compiler/Script/OpenModelicaScriptingAPIQt.h GENERATED)

add_library(OMEditLib STATIC ${OMEDITLIB_SOURCES} ${OMEDITLIB_HEADERS})

target_include_directories(OMEditLib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(OMEditLib PUBLIC omedit::config)
target_link_libraries(OMEditLib PUBLIC libOMSimulator)
target_link_libraries(OMEditLib PUBLIC omedit::debugger::parser)
target_link_libraries(OMEditLib PUBLIC Qt5::Xml)
target_link_libraries(OMEditLib PUBLIC Qt5::Widgets)
target_link_libraries(OMEditLib PUBLIC Qt5::PrintSupport)
target_link_libraries(OMEditLib PUBLIC Qt5::WebKitWidgets)
target_link_libraries(OMEditLib PUBLIC Qt5::OpenGL)
target_link_libraries(OMEditLib PUBLIC Qt5::Network)
target_link_libraries(OMEditLib PUBLIC Qt5::XmlPatterns)
target_link_libraries(OMEditLib PUBLIC omc::3rd::opcua)
target_link_libraries(OMEditLib PUBLIC OMPlotLib)
target_link_libraries(OMEditLib PUBLIC OpenModelicaCompiler)
target_link_libraries(OMEditLib PUBLIC ${OPENSCENEGRAPH_LIBRARIES})


# OMEditLib needs OpenModelicaScriptingAPI.h which is generated in the build dir.
# So we have the build dir as include through linking libOpenModelicaCompiler
# There is also an OMSimulator.h generated in that dir from OMSimulator.mo
# We also have an OMSimulator.h from OMSimulatorLib which we actually want to use.
# Except we are using libOMSimulator as an imported lib now.
# Headers from imported libs are treated as system libs and are added at the end of the include command line.
# Which means the OMSimulator.h from OMSimulator.mo will be picked up first regardless of the order we specify for linking.
# So for now we disable SYSTEM marking of imported libs for OMEditLib here.
set_target_properties(OMEditLib PROPERTIES
NO_SYSTEM_FROM_IMPORTED ON)

target_include_directories(OMEditLib PRIVATE ${OMCompiler_SOURCE_DIR}/Compiler/Script)

target_link_options(OMEditLib PRIVATE -Wl,--no-undefined)

install(TARGETS OMEditLib)

0 comments on commit 21450d7

Please sign in to comment.