Skip to content

Commit 24a9480

Browse files
authored
Improve handling of linked libraries to generated CPP code. (#11143)
- This will only affect omc compiled with the CMake build system. - Handle things like boost libraries a bit better. This is intended to fix only Linux and Windows with OMDev builds. Compiling generated CPP code with MSVC has many issues and there was no attempt to consider it in these changes. It can come later. - Try documenting some of the variables.
1 parent 84b589b commit 24a9480

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

OMCompiler/SimulationRuntime/cpp/Core/CMakeLists.txt

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,52 @@
11

2-
macro(target_public_headers TARGET)
3-
set_target_properties(${TARGET} PROPERTIES PUBLIC_HEADER "${ARGN}")
4-
endmacro()
52

3+
#####################################################################################################
4+
# Configure and generate the files 'ModelicaLibraryConfig_gcc.inc' and 'ModelicaConfig_gcc.inc'
5+
# These files tell the CPP code generator what name to use and where to find the necessary
6+
# libraries for the generated simulation code. This does not cover all variables that are used
7+
# or set by the old CPP-runtime build system. However, these seem to be enough to build things
8+
# on Linux and Windows with OMDev.
9+
10+
# SCOREP_INCLUDE_ is added to the compilation command-line of the generated code (in the Makefiles).
11+
# It is not clear why this one is chosen among the many others to be explicitly added to the generated
12+
# compilation code. It needs to be set to a valid directory resembling path.
613
set(SCOREP_INCLUDE_ ".")
14+
15+
# The boost libraries and headers are expected to be in the system directories.
16+
# For MSVC this needs to be adjusted. However, it is not clear which approach we are
17+
# taking for MSVC yet. So leave it like this until we decide.
718
set(Boost_INCLUDE_ ".")
19+
# This is supposwed to signify the directory where the boost libraries can be found (for -L ...)
820
set(Boost_LIBS_ ".")
21+
# The actual boost libraries needed to be linked.
22+
set(Boost_LIBRARIES_ "-lboost_program_options -lboost_filesystem")
23+
24+
# Lapack libs are also expected to be in the system directories.
925
set(LAPACK_LIBS_ ".")
10-
set(SYSTEM_CFLAGS ${SYSTEM_CFLAGS} "-DOMC_BUILD -fPIC -DUSE_THREAD")
1126
if(UNIX)
1227
set(LAPACK_LIBRARIES_ "-llapack -lblas")
13-
else()
14-
set(LAPACK_LIBRARIES_ "")
28+
set(LINUX_LIB_DL "-ldl")
1529
endif()
1630

31+
# The thread library flag (can be something like -lpthreads for example). Let CMake decide the value.
32+
set(CPPTHREADS_LIBRARY_FLAG ${CMAKE_THREAD_LIBS_INIT})
33+
34+
# Some common flags for the generated simulation code. It is not clear why OMC_BUILD is defined
35+
# by the old system. It is always defined for some reason. USE_THREAD means use the C++ standard
36+
# library's thread library (instead of something like boost threads).
37+
set(SYSTEM_CFLAGS ${SYSTEM_CFLAGS} "-DOMC_BUILD -DUSE_THREAD -fPIC")
38+
39+
# Configure the files.
1740
configure_file(Modelica/ModelicaLibraryConfig_gcc.inc.in ${CMAKE_CURRENT_BINARY_DIR}/ModelicaLibraryConfig_gcc.inc)
1841
configure_file(Modelica/ModelicaConfig_gcc.inc.in ${CMAKE_CURRENT_BINARY_DIR}/ModelicaConfig_gcc.inc)
1942

43+
# Install them during installtion. They end up in the appropriate include directory. Right now that is 'include/cpp'.
2044
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/ModelicaLibraryConfig_gcc.inc
2145
${CMAKE_CURRENT_BINARY_DIR}/ModelicaConfig_gcc.inc
2246
TYPE INCLUDE)
2347

2448

2549

26-
2750
#####################################################################################################
2851
# OMCppDataExchange
2952
set(OMC_SIMRT_CPP_CORE_DATAEXCHANGE_SOURCES DataExchange/SimData.cpp

0 commit comments

Comments
 (0)