Skip to content

Commit

Permalink
added cmake function to create precompiled header for cpp runtime for…
Browse files Browse the repository at this point in the history
… gcc

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20323 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Apr 30, 2014
1 parent 6b3ea47 commit e4b991a
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -1308,10 +1308,10 @@ LINK=<%makefileParams.linker%>
EXEEXT=<%makefileParams.exeext%>
DLLEXT=<%makefileParams.dllext%>
CFLAGS_BASED_ON_INIT_FILE=<%extraCflags%>
CFLAGS=$(CFLAGS_BASED_ON_INIT_FILE) -I"<%makefileParams.omhome%>/include/omc/cpp/Core" -I"<%makefileParams.omhome%>/include/omc/cpp/" -I. <%makefileParams.includes%> -I"$(BOOST_INCLUDE)" <%makefileParams.includes ; separator=" "%> <%makefileParams.cflags%> <%match sopt case SOME(s as SIMULATION_SETTINGS(__)) then s.cflags %>
CFLAGS=$(CFLAGS_BASED_ON_INIT_FILE) -Winvalid-pch $(SIM_OR_DYNLOAD_OPT_LEVEL) -I"<%makefileParams.omhome%>/include/omc/cpp/Core" -I"<%makefileParams.omhome%>/include/omc/cpp/" -I. <%makefileParams.includes%> -I"$(BOOST_INCLUDE)" <%makefileParams.includes ; separator=" "%> <%match sopt case SOME(s as SIMULATION_SETTINGS(__)) then s.cflags %>
LDSYTEMFLAGS=-L"<%makefileParams.omhome%>/lib/omc/cpp" -L"$(BOOST_LIBS)"
LDMAINFLAGS=-L"<%makefileParams.omhome%>/lib/omc/cpp" <%simulationMainDLLib(simCode)%> -L"<%makefileParams.omhome%>/bin" -lOMCppOMCFactory -L"$(BOOST_LIBS)" $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB) $(BOOST_PROGRAM_OPTIONS_LIB)
CPPFLAGS = $(CFLAGS) -DOMC_BUILD -DBOOST_SYSTEM_NO_DEPRICATED
CPPFLAGS = $(CFLAGS) -DOMC_BUILD -DPMC_USE_SUNDIALS
SYSTEMFILE=OMCpp<%fileNamePrefix%><% if acceptMetaModelicaGrammar() then ".conv"%>.cpp
FUNCTIONFILE=OMCpp<%fileNamePrefix%>Functions.cpp
INITFILE=OMCpp<%fileNamePrefix%>Initialize.cpp
Expand Down
11 changes: 10 additions & 1 deletion SimulationRuntime/cpp/CMakeLists.txt
@@ -1,6 +1,9 @@
cmake_minimum_required (VERSION 2.6)

project(CppSolverInterface)
include(${CMAKE_SOURCE_DIR}/PreCompiledHeader.cmake)
#set(CMAKE_VERBOSE_MAKEFILE ON)


option(ANALYZATION_MODE "ANALYZATION_MODE" OFF)

Expand Down Expand Up @@ -177,6 +180,10 @@ message(STATUS "Boost dirs '${Boost_LIBRARY_DIRS}', '${Boost_INCLUDE_DIR}'")
include_directories ("Include")
include_directories ("Include/Core")
include_directories ("Include/SimCoreFactory")




add_subdirectory (Core/Math)

add_subdirectory (Core/Utils/Modelica)
Expand All @@ -199,6 +206,8 @@ add_subdirectory (Solver/Newton)
add_subdirectory (Solver/Hybrj)




if(REDUCE_DAE)
add_subdirectory(ReduceDAE/Implementation)
endif()
Expand Down Expand Up @@ -312,7 +321,7 @@ ENDFOREACH(HEADER)
ENDMACRO(INSTALL_HEADERS_WITH_DIRECTORY)



add_precompiled_header(${ModelicaName} Include/Core/Modelica.h )

install (FILES "${PROJECT_BINARY_DIR}/LibrariesConfig.h" DESTINATION include/omc/cpp)

Expand Down
104 changes: 104 additions & 0 deletions SimulationRuntime/cpp/PrecompiledHeader.cmake
@@ -0,0 +1,104 @@
# Macro for setting up precompiled headers. Usage:
#
# add_precompiled_header(target header.h [FORCEINCLUDE])
#
# MSVC: A source file with the same name as the header must exist and
# be included in the target (E.g. header.cpp).
#
# MSVC: Add FORCEINCLUDE to automatically include the precompiled
# header file from every source file.
#
# GCC: The precompiled header is always automatically included from
# every header file.
#
# Copyright (C) 2009-2013 Lars Christensen <larsch@belunktum.dk>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the ‘Software’), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

MACRO(ADD_PRECOMPILED_HEADER _targetName _input )
GET_FILENAME_COMPONENT(_inputWe ${_input} NAME_WE)
SET(pch_source ${_inputWe}.cpp)
FOREACH(arg ${ARGN})
IF(arg STREQUAL FORCEINCLUDE)
SET(FORCEINCLUDE ON)
ELSE(arg STREQUAL FORCEINCLUDE)
SET(FORCEINCLUDE OFF)
ENDIF(arg STREQUAL FORCEINCLUDE)
ENDFOREACH(arg)

IF(MSVC)
#GET_TARGET_PROPERTY(sources ${_targetName} SOURCES)
#SET(_sourceFound FALSE)
#FOREACH(_source ${sources})
#SET(PCH_COMPILE_FLAGS "")
#IF(_source MATCHES \\.\(cc|cxx|cpp\)$)
#GET_FILENAME_COMPONENT(_sourceWe ${_source} NAME_WE)
#IF(_sourceWe STREQUAL ${_inputWe})
#SET(PCH_COMPILE_FLAGS "${PCH_COMPILE_FLAGS} /Yc${_input}")
#SET(_sourceFound TRUE)
#ELSE(_sourceWe STREQUAL ${_inputWe})
#SET(PCH_COMPILE_FLAGS "${PCH_COMPILE_FLAGS} /Yu${_input}")
#IF(FORCEINCLUDE)
#SET(PCH_COMPILE_FLAGS "${PCH_COMPILE_FLAGS} /FI${_input}")
#ENDIF(FORCEINCLUDE)
#ENDIF(_sourceWe STREQUAL ${_inputWe})
#SET_SOURCE_FILES_PROPERTIES(${_source} PROPERTIES COMPILE_FLAGS "${PCH_COMPILE_FLAGS}")
#ENDIF(_source MATCHES \\.\(cc|cxx|cpp\)$)
#ENDFOREACH()
#IF(NOT _sourceFound)
#MESSAGE(FATAL_ERROR "A source file for ${_input} was not found. Required for MSVC builds.")
#ENDIF(NOT _sourceFound)
ENDIF(MSVC)

IF(CMAKE_COMPILER_IS_GNUCXX)
GET_FILENAME_COMPONENT(_name ${_input} NAME)
SET(_source "${CMAKE_CURRENT_SOURCE_DIR}/${_input}")
SET(_outdir "${CMAKE_CURRENT_BINARY_DIR}/${_name}.gch")
MAKE_DIRECTORY(${_outdir})
#SET(_output "${_outdir}/.c++")
SET(_output "${_outdir}/${_name}.gch")
STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name)
SET(_compiler_FLAGS ${${_flags_var_name}})
#remove compiler flag for optimization becaus Modelics system is compiled without optimization
string(REGEX REPLACE "O[1-9]" "O0" _compiler_FLAGS ${_compiler_FLAGS} )
GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES)
FOREACH(item ${_directory_flags})
LIST(APPEND _compiler_FLAGS "-I${item}")
ENDFOREACH(item)

GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
LIST(APPEND _compiler_FLAGS ${_directory_flags})



SEPARATE_ARGUMENTS(_compiler_FLAGS)
message(STATUS "${CMAKE_CXX_COMPILER} -DPCHCOMPILE ${_compiler_FLAGS} -x c++-header -o {_output} ${_source}")
ADD_CUSTOM_COMMAND(
OUTPUT ${_output}
COMMAND ${CMAKE_CXX_COMPILER} ${_compiler_FLAGS} -x c++-header -o ${_output} ${_source}
DEPENDS ${_source} )
ADD_CUSTOM_TARGET(${_targetName}_gch DEPENDS ${_output})
ADD_DEPENDENCIES(${_targetName} ${_targetName}_gch)
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES COMPILE_FLAGS "-include ${_name} -Winvalid-pch")
install (FILES "${_output}" DESTINATION include/omc/cpp)
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
ENDMACRO()

0 comments on commit e4b991a

Please sign in to comment.