Skip to content

Commit

Permalink
More progress on cross compile and freatures
Browse files Browse the repository at this point in the history
  • Loading branch information
Kvixen committed Aug 9, 2018
1 parent af3bb6f commit 97f6688
Show file tree
Hide file tree
Showing 17 changed files with 424 additions and 194 deletions.
55 changes: 54 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Expand Down Expand Up @@ -619,3 +619,56 @@ Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.

END OF TERMS AND CONDITIONS

How to Apply These Terms to Your New Programs

If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".

You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.

The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
1 change: 1 addition & 0 deletions Simulix.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
"""
Simulix generates an FMU from a simulink model source code.
Expand Down
2 changes: 0 additions & 2 deletions compile-tools/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion compile-tools/toolchains/Ubuntu-darwin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set(CMAKE_SYSTEM_NAME Darwin)
set(PREFIX x86_64-apple-darwin15)
set(CMAKE_C_COMPILER ${PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${PREFIX}-g++)
set(CMAKE_FIND_ROOT_PATH /usr/${PREFIX})

set(DISABLE_WARNINGS 1)

Expand Down
1 change: 0 additions & 1 deletion compile-tools/toolchains/Ubuntu-mingw32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ set(PREFIX i686-w64-mingw32)
set(CMAKE_C_COMPILER ${PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${PREFIX}-g++)
set(CMAKE_RC_COMPILER ${PREFIX}-windres)
set(CMAKE_FIND_ROOT_PATH /usr/${PREFIX})

set(DISABLE_WARNINGS 1)

Expand Down
1 change: 0 additions & 1 deletion compile-tools/toolchains/Ubuntu-mingw64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ set(PREFIX x86_64-w64-mingw32)
set(CMAKE_C_COMPILER ${PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${PREFIX}-g++)
set(CMAKE_RC_COMPILER ${PREFIX}-windres)
set(CMAKE_FIND_ROOT_PATH /usr/${PREFIX})

set(DISABLE_WARNINGS 1)

Expand Down
1 change: 0 additions & 1 deletion compile-tools/toolchains/template-toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set(CMAKE_SYSTEM_NAME )
set(PREFIX )
set(CMAKE_C_COMPILER ${PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${PREFIX}-g++)
set(CMAKE_FIND_ROOT_PATH /usr/${PREFIX})

set(DISABLE_WARNINGS 1)

Expand Down
19 changes: 16 additions & 3 deletions content-builder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
"""
Simulix generates an FMU from a simulink model source code.
Expand All @@ -21,9 +22,12 @@
import json
import uuid
import argparse
from os import getcwd, path
from os import getcwd, path, environ
from pprint import pprint
from xml.dom import minidom
import re

SOURCE_REXEG = re.compile(r"^.+\\(\w+.c)$")

def read_json_file(src):
with open((src),'r') as json_file:
Expand Down Expand Up @@ -60,12 +64,21 @@ def xmlgen(data):
name = data["Model"]

fmiMD = {"fmiVersion":"2.0", "modelName":name, "guid":data["GUID"], "numberOfEventIndicators":"0"}
CoSimulation_dict = {"providesDirectionalDerivative":"false", "modelIdentifier":name, "canHandleVariableCommunicationStepSize":"true"}
co_simulation_dict = {"providesDirectionalDerivative":"false", "modelIdentifier":name, "canHandleVariableCommunicationStepSize":"true"}
category_dictlist = [{"name":"logAll", "description":"-"}, {"name":"logError", "description":"-"}, {"name":"logFmiCall", "description":"-"}, {"name":"logEvent", "description":"-"}]
step_size_dict = {"stepSize":step_size}

root = ET.Element("fmiModelDescription", fmiMD)
ET.SubElement(root,"CoSimulation",CoSimulation_dict)


source_files_subelement = ET.SubElement(ET.SubElement(root,"CoSimulation",co_simulation_dict), "SourceFiles")
# $ENV{SIMX_SOURCE_LIST} is set in unpack.py
source_list = environ['SIMX_SOURCES_LIST'].split(';')
for source in source_list:
match = SOURCE_REXEG.match(source)
if match:
ET.SubElement(source_files_subelement, "File").set("name", match.group(1))


LogCategories = ET.SubElement(root,"LogCategories")
for i in range(len(category_dictlist)):
Expand Down
16 changes: 15 additions & 1 deletion includes/capi_utils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Simulix generates an FMU from a simulink model source code.
Simulix generates an FMU from a simulink model source code.
Copyright (C) 2018 Scania CV AB and Simulix contributors
This program is free software: you can redistribute it and/or modify
Expand All @@ -16,6 +17,19 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
As a special exception, you may create a larger work that contains
some or all of the template files included in Simulix and distribute
that work under terms of your choice, so long as that work isn't itself
a FMU compiler using the template files.
This exception was added in version 1.0 of Simulix.
This special exception applies to files containing this special exception text.
The terms of the exception exists inside the text.
*/
#ifndef _CAPI_UTILS_H_
# define _CAPI_UTILS_H_
Expand Down
20 changes: 20 additions & 0 deletions includes/cjson_license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors

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.

105 changes: 67 additions & 38 deletions templates/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
cmake_minimum_required(VERSION 3.3) # 3.3 is the first version with IN_LIST
project({modelName} C CXX)
add_definitions(-DFMI_COSIMULATION)

set(MODEL_NAME {modelName})
set(PYTHON_PATH {path})
project({modelName} C CXX)
set(PROJECT_DIR ${{{modelName}_SOURCE_DIR}})
add_definitions(-DFMI_COSIMULATION)
get_directory_property(PC_DEFINITIONS COMPILE_DEFINITIONS)
set(PYTHON_COMMAND python)
set(BINARY_PREFIX $ENV{{BINARY_PREFIX}})

if (NOT ${{BINARY_PREFIX}})
if(UNIX)
if(APPLE)
# Support for APPLE? (DARWIN)
# set(BINARY_PREFIX "darwin")
else()
set(BINARY_PREFIX "linux")
endif()
elseif(WIN32)
set(BINARY_PREFIX "win")
endif()
endif()


set(BUILD_PATH CACHE STRING "Path to build")
if (UNIX)
set(PYTHON_COMMAND python3)
endif(UNIX)

# FindMatlab has a hardcoded list of all Matlab versions
# Because of older installs om CMake (i.e 3.3)
Expand All @@ -27,31 +45,9 @@ include(FindMatlab)
file(GLOB C_SOURCE_FILES ${{PROJECT_DIR}}/${{MODEL_NAME}}/sources/*.c)
file(GLOB CPP_SOURCE_FILES ${{PROJECT_DIR}}/${{MODEL_NAME}}/sources/*.cpp)

add_library(
${{CMAKE_PROJECT_NAME}}
SHARED
${{C_SOURCE_FILES}}
${{CPP_SOURCE_FILES}}
)

set_target_properties(
${{CMAKE_PROJECT_NAME}}
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${{BUILD_PATH}}"
PREFIX ""
)

# SIMULIX things
get_directory_property(PC_DEFINITIONS COMPILE_DEFINITIONS)
if(PC_DEFINITIONS MATCHES "^SIMULIX" OR PC_DEFINITIONS MATCHES ";SIMULIX")

message(STATUS "HELLO WORLD OF SIMULIX")

if ("${{PROJECT_DIR}}/${{MODEL_NAME}}/sources/fmuTemplate.c" IN_LIST C_SOURCE_FILES)
set(EXIST_FMU_TEMPLATE TRUE)
else()
set(EXIST_FMU_TEMPLATE FALSE)
endif()

if (WIN32)

target_link_libraries(
Expand All @@ -61,23 +57,56 @@ if(PC_DEFINITIONS MATCHES "^SIMULIX" OR PC_DEFINITIONS MATCHES ";SIMULIX")

endif()

if(NOT ${{EXIST_FMU_TEMPLATE}})
# This shouldn't happen unless someone deleted the fmuTemplate and fmi2<name> files after running Simulix.
# As we have changed fmuTemplate.c to match our main.c file we need to supply our file or it wont work.
# It's a very unnecessary procedure because, as mentioned above, it wont happen if the user knows what they are doing
list(APPEND C_SOURCE_FILES ${{PYTHON_PATH}}/libraryincludes/fmuTemplate.c)
file(GLOB FMUSDK_HEADERS ${{PYTHON_PATH}}/libraryincludes/*.h)


if($ENV{{SIMX_EXE}})

add_executable(
main
${{PROJECT_DIR}}/exemain.c
${{PROJECT_DIR}}/includes/cJSON.c
${{PROJECT_DIR}}/includes/capi_utils.c
${{C_SOURCE_FILES}}
${{CPP_SOURCE_FILES}}
)

target_include_directories(
main
${{PROJECT_DIR}}/includes
)

add_custom_command(
TARGET ${{CMAKE_PROJECT_NAME}}
POST_BUILD
COMMAND ${{CMAKE_COMMAND}} -E copy ${{PYTHON_PATH}}/libraryincludes/fmuTemplate.c ${{PROJECT_DIR}}/${{MODEL_NAME}}/sources/
COMMAND ${{CMAKE_COMMAND}} -E copy ${{FMUSDK_HEADERS}} ${{PROJECT_DIR}}/${{MODEL_NAME}}/sources/
OUTPUT ${{PROJECT_DIR}}/dllmain.c
DEPENDS main
COMMAND echo "Executing main executable"
COMMAND ./main
COMMAND echo "JSON to XML with Python"
COMMAND ${{PYTHON_COMMAND}} ${{PYTHON_SOURCE_DIR}}/content-builder.py -o ${{PROJECT_DIR}}/${{MODEL_NAME}}/sources/
)

set(EXIST_FMU_TEMPLATE TRUE)
list(APPEND C_SOURCE_FILES "${{PROJECT_DIR}}/${{MODEL_NAME}}/sources/dllmain.c")
endif()
endif()

add_library(
${{CMAKE_PROJECT_NAME}}
SHARED
${{C_SOURCE_FILES}}
${{CPP_SOURCE_FILES}}
)

set_target_properties(
${{CMAKE_PROJECT_NAME}}
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${{BUILD_PATH}}"
PREFIX ""
)

if(CMAKE_C_FLAGS MATCHES "^-m32" OR CMAKE_C_FLAGS MATCHES " -m32")
set(BINARY_PREFIX "${{BINARY_PREFIX}}32")
else()
set(BINARY_PREFIX "${{BINARY_PREFIX}}64")
endif()



Expand Down
Loading

0 comments on commit 97f6688

Please sign in to comment.