Skip to content

Commit

Permalink
Feature/proxy-fmu (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren authored Aug 18, 2021
1 parent 93cdfe6 commit d23a7b4
Show file tree
Hide file tree
Showing 33 changed files with 745 additions and 1,084 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^[<"]cosim[/.]'
Priority: 20
- Regex: '^[<"](boost|event2|fmilib|gsl|nlohmann|xercesc|zip)[/.]'
- Regex: '^[<"](boost|event2|fmilib|gsl|nlohmann|proxyfmu|xercesc|zip)[/.]'
Priority: 30
- Regex: '^"'
Priority: 10
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci-conan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build_type: [Debug, Release]
compiler_version: [7, 8, 9]
compiler_libcxx: [libstdc++11]
option_fmuproxy: ['fmuproxy=True', 'fmuproxy=False']
option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False']

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
SHORT_REFNAME="${REFNAME:0:40}"
CHANNEL="testing-${SHORT_REFNAME//\//_}"
fi
conan create -s build_type=${{ matrix.build_type }} -s compiler.version=${{ matrix.compiler_version }} -s compiler.libcxx=${{ matrix.compiler_libcxx }} -o ${{ matrix.option_fmuproxy }} -b missing . osp/${CHANNEL}
conan create -s build_type=${{ matrix.build_type }} -s compiler.version=${{ matrix.compiler_version }} -s compiler.libcxx=${{ matrix.compiler_libcxx }} -o ${{ matrix.option_proxyfmu }} -b missing . osp/${CHANNEL}
conan upload --all -c -r osp '*'
EOF
chmod 0755 /tmp/osp-builder-docker/entrypoint.sh
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
os: [windows-2016]
build_type: [Debug, Release]
compiler_version: [15]
option_fmuproxy: ['fmuproxy=True', 'fmuproxy=False']
option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False']

steps:
- uses: actions/checkout@v2
Expand All @@ -95,6 +95,6 @@ jobs:
SHORT_REFNAME="${REFNAME:0:40}"
CHANNEL="testing-${SHORT_REFNAME//\//_}"
fi
conan create -s build_type=${{ matrix.build_type }} -s compiler.version=${{ matrix.compiler_version }} -o ${{ matrix.option_fmuproxy }} -b missing . osp/${CHANNEL}
conan create -s build_type=${{ matrix.build_type }} -s compiler.version=${{ matrix.compiler_version }} -o ${{ matrix.option_proxyfmu }} -b missing . osp/${CHANNEL}
- name: Conan upload
run: conan upload --all -c -r osp '*'
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ option(LIBCOSIM_BUILD_APIDOC "Build API documentation (requires Doxygen)" ON)
option(LIBCOSIM_BUILD_PRIVATE_APIDOC "Build private API documentation (only used if LIBCOSIM_BUILD_APIDOC=ON)" OFF)
option(LIBCOSIM_STANDALONE_INSTALLATION "Whether to build for a standalone installation (Linux only; sets a relative RPATH)" OFF)
option(LIBCOSIM_USING_CONAN "Whether Conan is used for package management" OFF)
option(LIBCOSIM_WITH_FMUPROXY "Whether or not to build with fmuproxy integration" OFF)
option(LIBCOSIM_TEST_FMUPROXY "Whether or not to run fmuproxy tests (only if LIBCOSIM_BUILD_TESTS=ON and LIBCOSIM_WITH_FMUPROXY=ON)" ON)
option(LIBCOSIM_WITH_PROXYFMU "Whether or not to build with proxy-fmu integration" OFF)

# ==============================================================================
# Global internal configuration
Expand Down Expand Up @@ -115,8 +114,8 @@ find_package(FMILibrary REQUIRED)
find_package(LIBZIP REQUIRED)
find_package(YAML_CPP REQUIRED)
find_package(XercesC REQUIRED)
if(LIBCOSIM_WITH_FMUPROXY)
find_package(THRIFT 0.13.0 REQUIRED)
if(LIBCOSIM_WITH_PROXYFMU)
find_package(PROXYFMU CONFIG REQUIRED)
endif()

# ==============================================================================
Expand Down Expand Up @@ -148,7 +147,7 @@ if(LIBCOSIM_BUILD_APIDOC)
set(DOXYGEN_JAVADOC_AUTOBRIEF "YES")
set(DOXYGEN_QT_AUTOBRIEF "YES")
set(DOXYGEN_MULTILINE_CPP_IS_BRIEF "YES")
set(DOXYGEN_EXCLUDE_PATTERNS "*.cpp" "*.c" "*/fmuproxy/*service*")
set(DOXYGEN_EXCLUDE_PATTERNS "*.cpp" "*.c")
set(doxygenInputs "${CMAKE_SOURCE_DIR}/docs" "${CMAKE_SOURCE_DIR}/include")
if(LIBCOSIM_BUILD_PRIVATE_APIDOC)
list(APPEND doxygenInputs
Expand Down Expand Up @@ -209,7 +208,6 @@ install(FILES
"${CMAKE_SOURCE_DIR}/cmake/FindFMILibrary.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindLIBZIP.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindMS_GSL.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindTHRIFT.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindYAML_CPP.cmake"
DESTINATION
"${LIBCOSIM_CMAKE_INSTALL_DIR}"
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,10 @@ Then, acquire dependencies with Conan:
`--settings compiler.libcxx=libstdc++11` to this command; see Step 1 for more
information.)

#### FMU-Proxy
To include FMU-Proxy support, run conan install with the additional option:
#### proxyfmu
To include proxyfmu support, run conan install with the additional option:
```bash
-o fmuproxy=True
```
Note that it currently must be built in Release mode e.g.
```bash
conan install .. -s build_type=Release --build=missing -o fmuproxy=True
-o proxyfmu=True
```

Now, we can run CMake to generate the build system. (If you have not installed
Expand Down
43 changes: 23 additions & 20 deletions cmake/FindFMILibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
# FMILibrary_LIBRARY - Path to static library.
# FMILibrary_SHARED_LIBRARY - Path to shared/import library.
#
cmake_minimum_required (VERSION 2.8.11)

# Find static library, and use its path prefix to provide a HINTS option to the
# other find_*() commands.
Expand Down Expand Up @@ -97,31 +96,35 @@ unset (_FMILibrary_hints)

# Create the IMPORTED targets.
if (FMILibrary_LIBRARY)
add_library ("fmilib::static" STATIC IMPORTED)
set_target_properties ("fmilib::static" PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LINK_INTERFACE_LIBRARIES "${CMAKE_DL_LIBS}"
IMPORTED_LOCATION "${FMILibrary_LIBRARY}"
INTERFACE_COMPILE_DEFINITIONS "FMILibrary_STATIC_LIB_ONLY"
INTERFACE_INCLUDE_DIRECTORIES "${FMILibrary_INCLUDE_DIRS}")
if (NOT TARGET fmilib::static)
add_library ("fmilib::static" STATIC IMPORTED)
set_target_properties ("fmilib::static" PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LINK_INTERFACE_LIBRARIES "${CMAKE_DL_LIBS}"
IMPORTED_LOCATION "${FMILibrary_LIBRARY}"
INTERFACE_COMPILE_DEFINITIONS "FMILibrary_STATIC_LIB_ONLY"
INTERFACE_INCLUDE_DIRECTORIES "${FMILibrary_INCLUDE_DIRS}")
endif()
endif ()

if (FMILibrary_SHARED_LIBRARY)
add_library ("fmilib::shared" SHARED IMPORTED)
set_target_properties ("fmilib::shared" PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
INTERFACE_INCLUDE_DIRECTORIES "${FMILibrary_INCLUDE_DIRS}")
if (WIN32)
if (NOT TARGET fmilib::shared)
add_library ("fmilib::shared" SHARED IMPORTED)
set_target_properties ("fmilib::shared" PROPERTIES
IMPORTED_IMPLIB "${FMILibrary_SHARED_LIBRARY}")
if (FMILibrary_DLL)
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
INTERFACE_INCLUDE_DIRECTORIES "${FMILibrary_INCLUDE_DIRS}")
if (WIN32)
set_target_properties ("fmilib::shared" PROPERTIES
IMPORTED_LOCATION "${FMILibrary_DLL}")
IMPORTED_IMPLIB "${FMILibrary_SHARED_LIBRARY}")
if (FMILibrary_DLL)
set_target_properties ("fmilib::shared" PROPERTIES
IMPORTED_LOCATION "${FMILibrary_DLL}")
endif ()
else () # not WIN32
set_target_properties ("fmilib::shared" PROPERTIES
IMPORTED_LOCATION "${FMILibrary_SHARED_LIBRARY}")
endif ()
else () # not WIN32
set_target_properties ("fmilib::shared" PROPERTIES
IMPORTED_LOCATION "${FMILibrary_SHARED_LIBRARY}")
endif ()
endif()
endif ()

# Set the FMILibrary_LIBRARIES variable.
Expand Down
39 changes: 0 additions & 39 deletions cmake/FindTHRIFT.cmake

This file was deleted.

4 changes: 2 additions & 2 deletions cmake/project-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ find_dependency(LIBZIP REQUIRED)
find_dependency(YAML_CPP REQUIRED)
find_dependency(XercesC REQUIRED)

if(@LIBCOSIM_WITH_FMUPROXY@)
find_dependency(THRIFT REQUIRED)
if(@LIBCOSIM_WITH_PROXYFMU@)
find_dependency(PROXYFMU CONFIG REQUIRED)
endif()

list(REMOVE_AT CMAKE_MODULE_PATH -1)
19 changes: 10 additions & 9 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class LibcosimConan(ConanFile):
"xz_utils/5.2.5"
)

options = {"fmuproxy": [True, False]}
options = {"proxyfmu": [True, False]}
default_options = (
"fmuproxy=False",
"proxyfmu=False",
"boost:shared=True",
"fmilibrary:shared=True",
"libzip:shared=True",
Expand All @@ -43,23 +43,24 @@ def is_tests_enabled(self):
def set_version(self):
self.version = tools.load(path.join(self.recipe_folder, "version.txt")).strip()

def requirements(self):
if self.options.proxyfmu:
self.requires("proxyfmu/0.2.2@osp/testing")

def imports(self):
binDir = os.path.join("output", str(self.settings.build_type).lower(), "bin")
self.copy("proxyfmu*", dst=binDir, src="bin", keep_path=False)
self.copy("proxyfmu*", dst="tests", src="bin", keep_path=False)
self.copy("*.dll", dst=binDir, keep_path=False)
self.copy("*.pdb", dst=binDir, keep_path=False)

def requirements(self):
if self.options.fmuproxy:
self.requires("thrift/0.13.0")

def configure_cmake(self):
cmake = CMake(self)
cmake.definitions["LIBCOSIM_USING_CONAN"] = "ON"
cmake.definitions["LIBCOSIM_BUILD_APIDOC"] = "OFF"
cmake.definitions["LIBCOSIM_BUILD_TESTS"] = self.is_tests_enabled()
if self.options.fmuproxy:
cmake.definitions["LIBCOSIM_WITH_FMUPROXY"] = "ON"
cmake.definitions["LIBCOSIM_TEST_FMUPROXY"] = "OFF" # Temporary, to be removed again in PR #633
if self.options.proxyfmu:
cmake.definitions["LIBCOSIM_WITH_PROXYFMU"] = "ON"
cmake.configure()
return cmake

Expand Down
54 changes: 11 additions & 43 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,16 @@ set(generatedSources
"cosim/lib_info.cpp"
)

if(LIBCOSIM_WITH_FMUPROXY)
if(LIBCOSIM_WITH_PROXYFMU)
list(APPEND privateHeaders
"cosim/fmuproxy/fmuproxy_client.hpp"
"cosim/fmuproxy/fmuproxy_helper.hpp"
"cosim/fmuproxy/fmuproxy_uri_sub_resolver.hpp"
"cosim/fmuproxy/remote_fmu.hpp"
"cosim/fmuproxy/remote_slave.hpp"
"cosim/fmuproxy/thrift_state.hpp"
"cosim/proxy/proxy_uri_sub_resolver.hpp"
"cosim/proxy/remote_fmu.hpp"
"cosim/proxy/remote_slave.hpp"
)
list(APPEND sources
"cosim/fmuproxy/fmuproxy_client.cpp"
"cosim/fmuproxy/fmuproxy_uri_sub_resolver.cpp"
"cosim/fmuproxy/remote_slave.cpp"
"cosim/fmuproxy/remote_fmu.cpp"
"cosim/fmuproxy/thrift_state.cpp"
"cosim/proxy/proxy_uri_sub_resolver.cpp"
"cosim/proxy/remote_fmu.cpp"
"cosim/proxy/remote_slave.cpp"
)
endif()

Expand Down Expand Up @@ -151,30 +146,6 @@ add_custom_command(
)
list(APPEND generatedFiles "${ospSystemStructureHeader}")

# Generate FMU-proxy classes from Thrift service definitions
if(LIBCOSIM_WITH_FMUPROXY)
if(NOT THRIFT_EXECUTABLE)
message(FATAL_ERROR "The thrift compiler was not found. Cannot build with FMU-Proxy support.")
endif()
set(thriftServiceDefinition "${CMAKE_CURRENT_SOURCE_DIR}/cosim/fmuproxy/service.thrift")
set(thriftGenerated
"${generatedSourcesDir}/FmuService.h"
"${generatedSourcesDir}/FmuService.cpp"
"${generatedSourcesDir}/service_types.h"
"${generatedSourcesDir}/service_types.cpp"
)
add_custom_command(
OUTPUT ${thriftGenerated}
COMMAND "${THRIFT_EXECUTABLE}"
"--gen" "cpp:no_skeleton"
"-out" "${generatedSourcesDir}"
"${thriftServiceDefinition}"
DEPENDS "${thriftServiceDefinition}"
)
add_library(fmuproxy-service OBJECT ${thriftGenerated})
set_target_properties(fmuproxy-service PROPERTIES POSITION_INDEPENDENT_CODE ON)
list(APPEND generatedFiles "$<TARGET_OBJECTS:fmuproxy-service>")
endif()

# ==============================================================================
# Target definition
Expand Down Expand Up @@ -210,13 +181,10 @@ target_link_libraries(cosim
yaml-cpp
)

if(LIBCOSIM_WITH_FMUPROXY)
target_compile_definitions(cosim PRIVATE "HAS_FMUPROXY")
target_link_libraries(cosim
PUBLIC
thrift::thrift
)
endif()
if(LIBCOSIM_WITH_PROXYFMU)
target_compile_definitions(cosim PRIVATE "HAS_PROXYFMU")
target_link_libraries(cosim PRIVATE proxyfmu::proxyfmu-client)
endif ()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(cosim INTERFACE "atomic" "stdc++fs")
Expand Down
3 changes: 0 additions & 3 deletions src/cosim/algorithm/fixed_step_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#if defined(WIN32) && !defined(NOMINMAX)
# define NOMINMAX
#endif
#include "cosim/algorithm/fixed_step_algorithm.hpp"

#include "cosim/error.hpp"
Expand Down
Loading

0 comments on commit d23a7b4

Please sign in to comment.