Skip to content

Commit

Permalink
Configure cross compilation of Cpp runtime (#3760)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke committed Mar 18, 2016
1 parent e741ddf commit d48d574
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 77 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -87,8 +87,7 @@ SimulationRuntime/java_interface/src/org/openmodelica/corba/parser/OMCorbaDefini
SimulationRuntime/java_interface/src/org/openmodelica/corba/parser/OMCorbaDefinitionsParser.java
SimulationRuntime/cpp/Makefile
SimulationRuntime/cpp/Makefile.env
SimulationRuntime/cpp/Build/
SimulationRuntime/cpp/Build_static/
SimulationRuntime/cpp/Build_*/
SimulationRuntime/cpp/Debug/
SimulationRuntime/cpp/.cproject
SimulationRuntime/cpp/confdefs.h
Expand Down
134 changes: 87 additions & 47 deletions SimulationRuntime/cpp/CMakeLists.txt
Expand Up @@ -27,12 +27,37 @@
# if profiling of the simulation runtime should be enabled -DRUNTIME_PROFILING=ON [default: OFF]
# if the equation systems of a FMU should be solved with sundials solvers -DFMU_SUNDIALS=ON [default: OFF]
# if the logger should be completely disabled or used -DUSE_LOGGER=OFF [default: ON]
# specify target platform for compilation -DPLATFORM=<dynamic, static or platform triple> [default: "dynamic"]
#
# Example: "cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo" to create statically linked libraries
#
# The used defines are stored in the SYSTEM_CFLAGS variable, which is passed to the ModelicaConfig.inc and written in the PrecompiledHeader.cmake

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)

if(NOT PLATFORM OR PLATFORM STREQUAL "dynamic")
set(BUILD_SHARED_LIBS ON)
elseif(PLATFORM STREQUAL "static")
set(BUILD_SHARED_LIBS OFF)
else()
# cross compilation of a subset of the runtime for FMI export
set(FMU_TARGET PLATFORM)
set(BUILD_SHARED_LIBS OFF)

# set cross compiler and force its use
include(CMakeForceCompiler)
set(CMAKE_C_COMPILER ${PLATFORM}-gcc)
cmake_force_c_compiler(${PLATFORM}-gcc GNU)
set(CMAKE_CXX_COMPILER ${PLATFORM}-g++)
cmake_force_cxx_compiler(${PLATFORM}-g++ GNU)

# adapt lib installation dir, like lib/${PLATFORM}/omc/cpp
execute_process(COMMAND gcc -dumpmachine OUTPUT_VARIABLE MACHINE)
string(STRIP ${MACHINE} MACHINE)
string(REPLACE ${MACHINE} ${PLATFORM} LIBINSTALLEXT ${LIBINSTALLEXT})
message(STATUS "Libs will be installed in ${LIBINSTALLEXT}")
endif()

PROJECT(CppSolverInterface)
SET(CMAKE_VERBOSE_MAKEFILE ON)
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
Expand Down Expand Up @@ -101,7 +126,9 @@ SET(DgesvName ${LIBPREFIX}Dgesv) # only static version

SET(USE_MICO OFF)
SET(REDUCE_DAE OFF)
SET(USE_SUNDIALS ON)
IF(NOT FMU_TARGET OR FMU_SUNDIALS)
SET(USE_SUNDIALS ON)
ENDIF(NOT FMU_TARGET OR FMU_SUNDIALS)
SET(OMC_BUILD ON)
SET(SIMSTER_BUILD OFF)

Expand Down Expand Up @@ -133,7 +160,11 @@ IF(NOT(USE_CPP_03))
IF(APPLE)
CHECK_CXX_COMPILER_FLAG("-std=c++11 -stdlib=libc++" COMPILER_SUPPORTS_CXX11)
ELSE(APPLE)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
IF(FMU_TARGET)
SET(COMPILER_SUPPORTS_CXX11 True)
ELSE(FMU_TARGET)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
ENDIF(FMU_TARGET)
ENDIF(APPLE)
IF(COMPILER_SUPPORTS_CXX11)
IF(APPLE)
Expand Down Expand Up @@ -384,18 +415,21 @@ IF(NOT(COMPILER_SUPPORTS_CXX11))
ELSE(Boost_THREAD_FOUND AND Boost_ATOMIC_FOUND)
MESSAGE(STATUS "Boost thread disabled")
ENDIF(Boost_THREAD_FOUND AND Boost_ATOMIC_FOUND)
ELSE()
ELSEIF(NOT FMU_TARGET)
ADD_DEFINITIONS(-DUSE_THREAD)
MESSAGE(STATUS "Boost thread disabled because of available C++11 support")
ENDIF(NOT(COMPILER_SUPPORTS_CXX11))

FIND_PACKAGE(Boost REQUIRED COMPONENTS filesystem system serialization program_options)
IF(NOT FMU_TARGET)
FIND_PACKAGE(Boost REQUIRED COMPONENTS filesystem system serialization program_options)
ELSE(NOT FMU_TARGET)
FIND_PACKAGE(Boost COMPONENTS filesystem system serialization program_options)
ENDIF(NOT FMU_TARGET)
SET(Boost_LIBRARIES_TMP ${Boost_LIBRARIES_TMP} ${Boost_LIBRARIES})
SET(Boost_LIBRARIES ${Boost_LIBRARIES_TMP})
MESSAGE(STATUS "Boost Libraries")
MESSAGE(STATUS ${Boost_LIBRARIES})


# Find Lapack and Blas
FIND_PACKAGE(BLAS)
FIND_PACKAGE(LAPACK)
Expand Down Expand Up @@ -555,48 +589,54 @@ IF(USE_DGESV)
GET_FILENAME_COMPONENT(libDgesvName ${libDgesv} NAME)
ENDIF(USE_DGESV)

add_subdirectory (Core/Modelica)
add_subdirectory (Core/Math)
add_subdirectory (SimCoreFactory/OMCFactory)
#add_subdirectory (ModelicaCompiler)

add_subdirectory (Core/Utils/Modelica)
add_subdirectory (Core/Utils/extension)
add_subdirectory (Core/DataExchange)


#add system default implemention project
add_subdirectory (Core/System)
#add solver default implemention project
add_subdirectory (Core/Solver)
add_subdirectory (Core/SimulationSettings)
add_subdirectory (Core/ModelicaExternalC)
add_subdirectory (Core/SimController)

#add Euler solver project
add_subdirectory (Solver/Euler)
add_subdirectory (Solver/RK12)


add_subdirectory (Solver/RTEuler)
add_subdirectory (Solver/Newton)
add_subdirectory (Solver/Broyden)
add_subdirectory (Solver/Hybrj)
add_subdirectory (Solver/UmfPack)
add_subdirectory (Solver/Peer)
IF(OPENMP_FOUND)
IF(SUITESPARSE_UMFPACK_FOUND)
MESSAGE(STATUS "CppDassl enabled")
add_subdirectory (Solver/CppDASSL)
ELSE(SUITESPARSE_UMFPACK_FOUND)
MESSAGE(STATUS "CppDassl disabled, because of missing UMFPACK support")
ENDIF(SUITESPARSE_UMFPACK_FOUND)
ELSE(OPENMP_FOUND)
MESSAGE(STATUS "CppDassl disabled, because of missing OpenMP support")
ENDIF(OPENMP_FOUND)
##add_subdirectory (Solver/RTRK)

add_subdirectory (FMU)
# add system default implemention project
add_subdirectory(Core/System)
# add solver default implemention project
add_subdirectory(Core/Solver)

add_subdirectory(Core/Math)
add_subdirectory(Core/Utils/Modelica)
add_subdirectory(Core/Utils/extension)
add_subdirectory(Core/ModelicaExternalC)

if(NOT FMU_TARGET)
# add projects for generating a simulator
add_subdirectory(Core/Modelica)
add_subdirectory(SimCoreFactory/OMCFactory)
add_subdirectory(Core/DataExchange)
add_subdirectory(Core/SimulationSettings)
add_subdirectory(Core/SimController)
#add_subdirectory(ModelicaCompiler)
endif(NOT FMU_TARGET)

# add Newton solver
add_subdirectory(Solver/Newton)

if(NOT FMU_TARGET)
# add more algebraic loop solvers
add_subdirectory(Solver/Broyden)
add_subdirectory(Solver/Hybrj)
add_subdirectory(Solver/UmfPack)
add_subdirectory(Solver/Peer)

# add simulation solvers
add_subdirectory(Solver/Euler)
add_subdirectory(Solver/RK12)
add_subdirectory(Solver/RTEuler)
if(OPENMP_FOUND)
if(SUITESPARSE_UMFPACK_FOUND)
message(STATUS "CppDassl enabled")
add_subdirectory (Solver/CppDASSL)
else(SUITESPARSE_UMFPACK_FOUND)
message(STATUS "CppDassl disabled, because of missing UMFPACK support")
endif(SUITESPARSE_UMFPACK_FOUND)
else(OPENMP_FOUND)
message(STATUS "CppDassl disabled, because of missing OpenMP support")
endif(OPENMP_FOUND)
##add_subdirectory(Solver/RTRK)
endif(NOT FMU_TARGET)

add_subdirectory(FMU)

if(REDUCE_DAE)
#add_subdirectory(ReduceDAE/Implementation)
Expand Down
27 changes: 14 additions & 13 deletions SimulationRuntime/cpp/Makefile.in
@@ -1,6 +1,9 @@
# Adrian Pop, adrpo@ida.liu.se, 2006-02-01
# Makefile for compilation of OMC using OMDev-mingw
# OMDev-mingw: http://www.ida.liu.se/~adrpo/omc/omdev/
# Makefile for compilation of OpenModelica Cpp runtime

# specify a list of target platforms, including dynamic, static
# and platform triples for cross compilation
#PLATFORMS=x86_64-linux-gnu i686-w64-mingw32 dynamic
PLATFORMS=static dynamic

OMBUILDDIR=
LIBINSTALLEXT=
Expand Down Expand Up @@ -31,20 +34,18 @@ CMAKE_ARGS=$(patsubst CMAKE_%, -D%, $(filter CMAKE_%, $(MAKEFLAGS)))
CMAKE_FLAGS=-DCMAKE_BUILD_TYPE=$(BUILDTYPE) $(BOOST_ROOT_COMMAND) $(BOOST_STATIC_LINKING_COMMAND) $(CPP_03_COMMAND) $(BOOST_REALPATHS_COMMAND) $(PARALLEL_OUTPUT_COMMAND) $(RUNTIME_PROFILING_COMMAND) $(SCOREP_COMMAND) $(FMU_SUNDIALS_COMMAND) $(LOGGER_COMMAND) -DCMAKE_BUILD_TYPE=$(BUILDTYPE) -DCMAKE_INSTALL_PREFIX:PATH="$(OMBUILDDIR)" -DLIBINSTALLEXT=$(LIBINSTALLEXT) -DSCOREP_HOME:STRING="$(SCOREP_HOME)" $(BUILD_DOC_COMMAND) $(CMAKE_ARGS)

runtimeCpp:
mkdir -p Build
cd ./Build && echo "change to Build" && $(CMAKE_COMMANDS) cmake -DBUILD_SHARED_LIBS:BOOL=ON $(CMAKE_FLAGS) ../
$(MAKE) -C Build VERBOSE=1
mkdir -p Build_static
cd ./Build_static && echo "change to Build_static" && $(CMAKE_COMMANDS) cmake -DBUILD_SHARED_LIBS:BOOL=OFF $(CMAKE_FLAGS) ../
$(MAKE) -C Build_static VERBOSE=1
$(foreach PLATFORM, $(PLATFORMS), \
mkdir -p Build_$(PLATFORM); \
(cd ./Build_$(PLATFORM) && echo "change to Build_$(PLATFORM)" && $(CMAKE_COMMANDS) cmake -DPLATFORM=$(PLATFORM) $(CMAKE_FLAGS) ../); \
$(MAKE) -C Build_$(PLATFORM) VERBOSE=1;)

install: runtimeCpp
(cd Build_static; $(MAKE) install)
(cd Build; $(MAKE) install)
$(foreach PLATFORM, $(PLATFORMS), \
(cd Build_$(PLATFORM); $(MAKE) install);)

clean:
rm -R -f Build_static
rm -R -f Build
$(foreach PLATFORM, $(PLATFORMS), \
rm -R -f Build_$(PLATFORM);)

Makefile: Makefile.in
cd @top_builddir@ && ./config.status
32 changes: 17 additions & 15 deletions SimulationRuntime/cpp/Makefile.omdev.mingw
Expand Up @@ -2,6 +2,11 @@
# Makefile for compilation of OMC using OMDev-mingw
# OMDev-mingw: http://www.ida.liu.se/~adrpo/omc/omdev/

# specify a list of target platforms, including dynamic, static
# and platform triples for cross compilation
#PLATFORMS=x86_64-linux-gnu i686-w64-mingw32 dynamic
PLATFORMS=static dynamic

top_builddir = $(OMBUILDDIR)/../
builddir_build=$(OMBUILDDIR)
builddir_bin=$(OMBUILDDIR)/bin
Expand Down Expand Up @@ -116,14 +121,11 @@ endif
CMAKE_FLAGS=-DCMAKE_BUILD_TYPE=$(BUILDTYPE) $(BOOST_STATIC_LINKING_COMMAND) $(BOOST_REALPATHS_COMMAND) $(RUNTIME_PROFILING_COMMAND) $(USE_SCOREP_COMMAND) $(SCOREP_HOME_COMMAND) $(FMU_SUNDIALS_COMMAND) $(PARALLEL_OUTPUT_COMMAND) $(USE_LOGGER_COMMAND)

runtimeCpp:
mkdir -p Build
cd ./Build; echo "change to Build"; \
$(CMAKE) -G "MSYS Makefiles" -DBUILD_SHARED_LIBS:BOOL=ON $(CMAKE_FLAGS) -DCMAKE_INSTALL_PREFIX:PATH="$(OMBUILDDIR)" MAKE_CXX_COMPILER=g++ ../; \
make;
mkdir -p Build_static
cd ./Build_static; echo "change to Build_static"; \
$(CMAKE) -G "MSYS Makefiles" -DBUILD_SHARED_LIBS:BOOL=OFF $(CMAKE_FLAGS) -DCMAKE_INSTALL_PREFIX:PATH="$(OMBUILDDIR)" MAKE_CXX_COMPILER=g++ ../; \
make;
$(foreach PLATFORM, $(PLATFORMS), \
mkdir -p Build_$(PLATFORM); \
(cd ./Build_$(PLATFORM); echo "change to Build_$(PLATFORM)"; \
$(CMAKE) -G "MSYS Makefiles" -DPLATFORM=$(PLATFORM) $(CMAKE_FLAGS) -DCMAKE_INSTALL_PREFIX:PATH="$(OMBUILDDIR)" MAKE_CXX_COMPILER=g++ ../; \
make);)

runtimeCPPmsvc: getMSVCversion
test -f """${VSCOMNTOOLS}/../../VC/vcvarsall.bat"""
Expand All @@ -133,7 +135,7 @@ runtimeCPPmsvc: getMSVCversion
echo call '"${VSCOMNTOOLS}\\..\\..\\VC\\vcvarsall.bat"' > Build_MSVC/build.bat

echo echo Running CMake from '%OMDEV%\\bin\\cmake\\bin\\cmake' >> Build_MSVC/build.bat
echo '%OMDEV%\\bin\\cmake\\bin\\cmake -DCMAKE_VERBOSE_MAKEFILE:Bool=ON -DBUILD_SHARED_LIBS:BOOL=ON $(CMAKE_FLAGS) -DCMAKE_INSTALL_PREFIX=./tmp ../ -G "NMake Makefiles JOM" -D"CMAKE_MAKE_PROGRAM:PATH=%OMDEV%\\tools\\jom\\jom.exe"' >> Build_MSVC/build.bat
echo '%OMDEV%\\bin\\cmake\\bin\\cmake -DCMAKE_VERBOSE_MAKEFILE:Bool=ON -DPLATFORM="dynamic" $(CMAKE_FLAGS) -DCMAKE_INSTALL_PREFIX=./tmp ../ -G "NMake Makefiles JOM" -D"CMAKE_MAKE_PROGRAM:PATH=%OMDEV%\\tools\\jom\\jom.exe"' >> Build_MSVC/build.bat

# for some reason, the environment variable 'MAKEFLAGS' was set to 'w' on my and Niklas' machine?!
echo set MAKEFLAGS="" >> Build_MSVC/build.bat
Expand All @@ -148,7 +150,7 @@ runtimeCPPmsvc: getMSVCversion
echo call '"${VSCOMNTOOLS}\\..\\..\\VC\\vcvarsall.bat"' > Build_MSVC_static/build.bat

echo echo Running CMake from '%OMDEV%\\bin\\cmake\\bin\\cmake' >> Build_MSVC_static/build.bat
echo '%OMDEV%\\bin\\cmake\\bin\\cmake -DCMAKE_VERBOSE_MAKEFILE:Bool=ON -DBUILD_SHARED_LIBS:BOOL=OFF $(CMAKE_FLAGS) -DCMAKE_INSTALL_PREFIX=./tmp ../ -G "NMake Makefiles JOM" -D"CMAKE_MAKE_PROGRAM:PATH=%OMDEV%\\tools\\jom\\jom.exe"' >> Build_MSVC_static/build.bat
echo '%OMDEV%\\bin\\cmake\\bin\\cmake -DCMAKE_VERBOSE_MAKEFILE:Bool=ON -DPLATFORM="static" $(CMAKE_FLAGS) -DCMAKE_INSTALL_PREFIX=./tmp ../ -G "NMake Makefiles JOM" -D"CMAKE_MAKE_PROGRAM:PATH=%OMDEV%\\tools\\jom\\jom.exe"' >> Build_MSVC_static/build.bat

# for some reason, the environment variable 'MAKEFLAGS' was set to 'w' on my and Niklas' machine?!
echo set MAKEFLAGS="" >> Build_MSVC_static/build.bat
Expand Down Expand Up @@ -185,11 +187,11 @@ endif


install: runtimeCpp
(cd Build_static; make install)
(cd Build; make install)
(cd Build; cp -p $(OMDEV)/lib/3rdParty/boost-1_55/lib/*.dll $(builddir_bin)/.)
$(foreach PLATFORM, $(PLATFORMS), \
(cd Build_$(PLATFORM); $(MAKE) install);)
cp -p $(OMDEV)/lib/3rdParty/boost-1_55/lib/*.dll $(builddir_bin)/.


clean:
rm -R -f Build_static
rm -R -f Build
$(foreach PLATFORM, $(PLATFORMS), \
rm -R -f Build_$(PLATFORM);)

0 comments on commit d48d574

Please sign in to comment.