Skip to content

Commit

Permalink
Merge pull request #20 from diegoferigo/fix/changeTargetNames
Browse files Browse the repository at this point in the history
Renamed CMake components
  • Loading branch information
diegoferigo authored Jan 20, 2019
2 parents fcf5a5e + 52c92b6 commit f8a363e
Show file tree
Hide file tree
Showing 21 changed files with 73 additions and 71 deletions.
22 changes: 14 additions & 8 deletions cmake/ExtraPackageConfigVars.cmake.in
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
set(NAME "BlockFactory")

foreach(comp (BlockFactoryCore BlockFactoryCoder BlockFactoryMex))
if(${${comp}_FOUND})
foreach(comp (Core Simulink SimulinkCoder))
if(${${NAME}${comp}_FOUND})
string(CONCAT FOUND_COMPONENTS_LIST ${FOUND_COMPONENTS_LIST} " ${comp}")
endif()
endforeach()

# Here comp is only Core, Simulink, SimulinkCoder.
# The call to find_dependency sets the variable BlockFactoryCore_FOUND.
foreach(comp ${${NAME}_FIND_COMPONENTS})
# Match the component status with the find_dependency exit variable
set(${NAME}_${comp}_FOUND ${${comp}_FOUND})
set(${NAME}_${comp}_FOUND ${${NAME}${comp}_FOUND})
endforeach()

# Set BlockFactory_FOUND to true and then check if there are required
# components that are missing
set(${NAME}_FOUND TRUE)
check_required_components(${NAME})

if(${NAME}_FOUND)
message(STATUS "Found BlockFactory ${${NAME}_FIND_VERSION} (Components:${FOUND_COMPONENTS_LIST})")
if(${${NAME}_FOUND})
message(STATUS "Found BlockFactory ${${NAME}_VERSION} (Components:${FOUND_COMPONENTS_LIST})")
endif()

# Print useful info about the outcome
if(NOT ${NAME}_FIND_QUIETLY)
foreach(comp ${${NAME}_FIND_COMPONENTS})
# If a component is not found, tell the user its name
if((NOT ${NAME}_FIND_REQUIRED_${comp}) AND (NOT ${comp}_FOUND))
if((NOT ${NAME}_FIND_REQUIRED_${comp}) AND (NOT ${NAME}${comp}_FOUND))
# status if it is OPTIONAL_COMPONENT
message(STATUS "BlockFactory: OPTIONAL component ${comp} NOT found")
elseif(NOT ${comp}_FOUND)
elseif(NOT ${NAME}${comp}_FOUND)
# warning if it is REQUIRED
message(WARNING "BlockFactory: REQUIRED component ${comp} NOT found")
# Note: find_package will exit with a fatal error but without telling
# what is missing
# what is missing
endif()
endforeach()
endif()
Expand Down
5 changes: 2 additions & 3 deletions cmake/TargetFromGeneratedCode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ endif()
# FIND DEPENDENCIES FOR BUILDING THE AUTOGENERATED CODE
# =====================================================

find_package(BlockFactory COMPONENTS
BlockFactoryCore BlockFactoryCoder REQUIRED)
find_package(BlockFactory COMPONENTS Core SimulinkCoder REQUIRED)

# ==============================================
# FIND THE defines.txt FILE AND LOAD ITS CONTENT
Expand Down Expand Up @@ -90,6 +89,6 @@ add_library(${SIMULINK_MODELNAME} STATIC
target_link_libraries(${SIMULINK_MODELNAME} PUBLIC
SimulinkCoder
${SIMULINK_MODELNAME}_data
BlockFactory::Coder)
BlockFactory::SimulinkCoder)

endmacro()
2 changes: 1 addition & 1 deletion doc/mkdocs/data/autogenerate_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ The capability of autogenerating C++ code from a Simulink model is provided by S

- [`AutogenerationExample.mdl`](https://github.com/robotology/blockfactory/tree/master/example/matlab/AutogenerationExample.mdl) A Simulink model with the right configuration of Simulink Coder
- [`example/matlab/AutogenerationExample_grt_rtw`](https://github.com/robotology/blockfactory/tree/master/example/matlab/AutogenerationExample_grt_rtw) The folder containing the autogenerated sources
- ['example/matlab/CMakeLists.txt'](https://github.com/robotology/blockfactory/blob/master/example/matlab/CMakeLists.txt) The CMake file for compiling the generated code
- [`src/main.cpp`](https://github.com/robotology/blockfactory/tree/master/example/src/main.cpp) A simple main function to execute the autogenerated code

9 changes: 5 additions & 4 deletions doc/mkdocs/data/create_new_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ endif()
# ===========
# Find the needed BlockFactory components:
# - BlockFactoryCore contains the core classes such as Block and Signal
# - BlockFactoryMex is required at runtime for loading the library from Simulink
find_package(BlockFactory 1 REQUIRED COMPONENTS BlockFactoryCore BlockFactoryMex)
# - "Core" contains the core classes such as Block and Signal
# - "Simulink" is required at runtime for loading the library from Simulink
find_package(BlockFactory
REQUIRED COMPONENTS Core
OPTIONAL_COMPONENTS Simulink)
# Create the plugin library. This must be a SHARED library.
add_library(ExampleToolbox SHARED
Expand All @@ -196,7 +198,6 @@ target_link_libraries(ExampleToolbox PRIVATE
# Setup the include directories
target_include_directories(ExampleToolbox PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
```

!!! note
Expand Down
6 changes: 3 additions & 3 deletions doc/mkdocs/data/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

BlockFactory provides three components, listed here below with their dependendencies. If a component dependency is not found, the component is not built.

| | `Core` | `Coder` | `Mex` |
| ---------------- | ------ | ------- | ---------------------- |
| **Dependencies** | ~ | ~ | - Matlab<br>- Simulink |
| | `Core` | `SimulinkCoder` | `Simulink` |
| ---------------- | ------ | --------------- | ---------------------- |
| **Dependencies** | ~ | ~ | - Matlab<br>- Simulink |

!!! note
Simulink Coder is not a build dependency of the `Coder` component. Of course, you must have it if you want to generate C++ code from a Simulink Model.
Expand Down
8 changes: 4 additions & 4 deletions doc/release/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

### `Core`

### `Mex`
### `Simulink`

### `Coder`
### `SimulinkCoder`

## Bug Fixes

### `Core`

### `Mex`
### `Simulink`

### `Coder`
### `SimulinkCoder`

## Contributors

Expand Down
8 changes: 4 additions & 4 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ endif()
# ===========

# Find the needed BlockFactory components:
# - BlockFactoryCore contains the core classes such as Block and Signal
# - BlockFactoryMex is required at runtime for loading the library from Simulink
# - "Core" contains the core classes such as Block and Signal
# - "Simulink" is required at runtime for loading the library from Simulink
find_package(BlockFactory
REQUIRED COMPONENTS BlockFactoryCore
OPTIONAL_COMPONENTS BlockFactoryMex)
REQUIRED COMPONENTS Core
OPTIONAL_COMPONENTS Simulink)

# Create the plugin library. This must be a SHARED library.
add_library(ExampleToolbox SHARED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <BlockFactory/Core/Parameter.h>
#include <BlockFactory/Core/Parameters.h>
#include <BlockFactory/Core/FactorySingleton.h>
#include <BlockFactory/Coder/CoderBlockInformation.h>
#include <BlockFactory/SimulinkCoder/CoderBlockInformation.h>
#include "rtwtypes.h"
#include "rtw_continuous.h"
#include "rtw_solver.h"
Expand Down
6 changes: 1 addition & 5 deletions example/matlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# This software may be modified and distributed under the terms of the
# GNU Lesser General Public License v2.1 or any later version.

find_package(BlockFactory COMPONENTS
BlockFactoryCoder REQUIRED)
find_package(BlockFactory COMPONENTS SimulinkCoder REQUIRED)

include(TargetFromGeneratedCode)

Expand All @@ -13,6 +12,3 @@ set(SIMULINK_MODEL_NAME "AutogenerationExample")
target_from_generated_code(
MODELNAME ${SIMULINK_MODEL_NAME}
SOURCE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/${SIMULINK_MODEL_NAME}_grt_rtw)

#add_executable(${SIMULINK_MODEL_NAME}-main ${CMAKE_SOURCE_DIR}/src/driver.cpp)
#target_link_libraries(${SIMULINK_MODEL_NAME}-main ${SIMULINK_MODEL_NAME})
2 changes: 1 addition & 1 deletion matlab/BlockFactory.tlc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
%<LibAddToCommonIncludes("<BlockFactory/Core/Parameter.h>")>
%<LibAddToCommonIncludes("<BlockFactory/Core/Parameters.h>")>
%<LibAddToCommonIncludes("<BlockFactory/Core/FactorySingleton.h>")>
%<LibAddToCommonIncludes("<BlockFactory/Coder/CoderBlockInformation.h>")>
%<LibAddToCommonIncludes("<BlockFactory/SimulinkCoder/CoderBlockInformation.h>")>

%endfunction

Expand Down
8 changes: 4 additions & 4 deletions sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# GNU Lesser General Public License v2.1 or any later version.

add_subdirectory(Core)
add_subdirectory(Coder)
add_subdirectory(SimulinkCoder)

if(USES_MATLAB)
add_subdirectory(Mex)
add_subdirectory(Simulink)
endif()

# ========================
Expand All @@ -16,9 +16,9 @@ endif()
# Dummy target
add_library(BlockFactory INTERFACE)

set(BLOCKFACTORY_DEPENDENCIES BlockFactoryCore BlockFactoryCoder)
set(BLOCKFACTORY_DEPENDENCIES BlockFactoryCore BlockFactorySimulinkCoder)
if (USES_MATLAB)
list(APPEND BLOCKFACTORY_DEPENDENCIES BlockFactoryMex)
list(APPEND BLOCKFACTORY_DEPENDENCIES BlockFactorySimulink)
endif()

install(
Expand Down
26 changes: 13 additions & 13 deletions sources/Mex/CMakeLists.txt → sources/Simulink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

add_library(SimulinkBlockInformationPrivate STATIC
src/SimulinkBlockInformationImpl.cpp
include/BlockFactory/Mex/Private/SimulinkBlockInformationImpl.h)
include/BlockFactory/Simulink/Private/SimulinkBlockInformationImpl.h)

target_link_libraries(SimulinkBlockInformationPrivate
PUBLIC
Expand All @@ -24,40 +24,40 @@ target_include_directories(SimulinkBlockInformationPrivate PRIVATE

# Compile S-Function
matlab_add_mex(
NAME Mex
NAME Simulink
OUTPUT_NAME BlockFactory
SRC src/SimulinkBlockInformation.cpp
include/BlockFactory/Mex/SimulinkBlockInformation.h
include/BlockFactory/Simulink/SimulinkBlockInformation.h
src/BlockFactory.cpp
LINK_TO BlockFactory::Core shlibpp::shlibpp SimulinkBlockInformationPrivate)
add_library(BlockFactory::Mex ALIAS Mex)
add_library(BlockFactory::Simulink ALIAS Simulink)

# Needed to access Simulink C APIs
target_compile_definitions(Mex PRIVATE "MATLAB_MEX_FILE")
target_compile_warnings(Mex
target_compile_definitions(Simulink PRIVATE "MATLAB_MEX_FILE")
target_compile_warnings(Simulink
WARNINGS_AS_ERRORS ${TREAT_WARNINGS_AS_ERRORS}
DEPENDS ENABLE_WARNINGS)

# Fix https://github.com/robotology/blockfactory/issues/13
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(Mex PRIVATE -Wno-format-overflow)
target_compile_options(Simulink PRIVATE -Wno-format-overflow)
endif()

target_include_directories(Mex PUBLIC
target_include_directories(Simulink PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
${Matlab_ROOT_DIR}/simulink/include)

# Install S-Function
install(
TARGETS Mex SimulinkBlockInformationPrivate
EXPORT BlockFactoryMexExport
TARGETS Simulink SimulinkBlockInformationPrivate
EXPORT BlockFactorySimulinkExport
DESTINATION mex)

install_basic_package_files(BlockFactoryMex
install_basic_package_files(BlockFactorySimulink
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
EXPORT BlockFactoryMexExport
FIRST_TARGET Mex
EXPORT BlockFactorySimulinkExport
FIRST_TARGET Simulink
DEPENDENCIES BlockFactoryCore mxpp shlibpp
NAMESPACE BlockFactory::
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "BlockFactory/Core/Log.h"
#include "BlockFactory/Core/Parameter.h"
#include "BlockFactory/Core/Parameters.h"
#include "BlockFactory/Mex/SimulinkBlockInformation.h"
#include "BlockFactory/Simulink/SimulinkBlockInformation.h"

#include <matrix.h>
#include <simstruc.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* GNU Lesser General Public License v2.1 or any later version.
*/

#include "BlockFactory/Mex/SimulinkBlockInformation.h"
#include "BlockFactory/Simulink/SimulinkBlockInformation.h"
#include "BlockFactory/Core/Log.h"
#include "BlockFactory/Core/Parameter.h"
#include "BlockFactory/Core/Parameters.h"
#include "BlockFactory/Core/Signal.h"
#include "BlockFactory/Mex/Private/SimulinkBlockInformationImpl.h"
#include "BlockFactory/Simulink/Private/SimulinkBlockInformationImpl.h"

#include <memory>
#include <ostream>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* GNU Lesser General Public License v2.1 or any later version.
*/

#include "BlockFactory/Mex/Private/SimulinkBlockInformationImpl.h"
#include "BlockFactory/Simulink/Private/SimulinkBlockInformationImpl.h"
#include "BlockFactory/Core/Log.h"
#include "BlockFactory/Core/Parameter.h"
#include "BlockFactory/Core/Signal.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
# GNU Lesser General Public License v2.1 or any later version.

set(CODER_HDR
include/BlockFactory/Coder/CoderBlockInformation.h
include/BlockFactory/Coder/GeneratedCodeWrapper.h)
include/BlockFactory/SimulinkCoder/CoderBlockInformation.h
include/BlockFactory/SimulinkCoder/GeneratedCodeWrapper.h)

set(CODER_SRC
src/CoderBlockInformation.cpp)

add_library(Coder ${CODER_HDR} ${CODER_SRC})
add_library(BlockFactory::Coder ALIAS Coder)
add_library(SimulinkCoder ${CODER_HDR} ${CODER_SRC})
add_library(BlockFactory::SimulinkCoder ALIAS SimulinkCoder)

set_target_properties(Coder PROPERTIES
set_target_properties(SimulinkCoder PROPERTIES
VERSION ${PROJECT_VERSION}
PUBLIC_HEADER "${CODER_HDR}"
OUTPUT_NAME "BlockFactoryCoder")
OUTPUT_NAME "BlockFactorySimulinkCoder")

target_link_libraries(Coder PUBLIC BlockFactory::Core)
target_include_directories(Coder PUBLIC
target_link_libraries(SimulinkCoder PUBLIC BlockFactory::Core)
target_include_directories(SimulinkCoder PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

target_compile_warnings(Coder
target_compile_warnings(SimulinkCoder
WARNINGS_AS_ERRORS ${TREAT_WARNINGS_AS_ERRORS}
DEPENDS ENABLE_WARNINGS)

Expand All @@ -34,21 +34,21 @@ install(
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/BlockFactory/cmake")

install(
TARGETS Coder
EXPORT BlockFactoryCoderExport
TARGETS SimulinkCoder
EXPORT BlockFactorySimulinkCoderExport
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/BlockFactory/Coder)
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/BlockFactory/SimulinkCoder)

set(EXTRA_CONTENT
"list(APPEND CMAKE_MODULE_PATH @CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_DATAROOTDIR@/BlockFactory/cmake)")

install_basic_package_files(BlockFactoryCoder
install_basic_package_files(BlockFactorySimulinkCoder
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
EXPORT BlockFactoryCoderExport
FIRST_TARGET Coder
EXPORT BlockFactorySimulinkCoderExport
FIRST_TARGET SimulinkCoder
DEPENDENCIES BlockFactoryCore
NAMESPACE BlockFactory::
NO_CHECK_REQUIRED_COMPONENTS_MACRO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* GNU Lesser General Public License v2.1 or any later version.
*/

#include "BlockFactory/Coder/CoderBlockInformation.h"
#include "BlockFactory/SimulinkCoder/CoderBlockInformation.h"
#include "BlockFactory/Core/Log.h"
#include "BlockFactory/Core/Parameter.h"
#include "BlockFactory/Core/Parameters.h"
Expand Down

0 comments on commit f8a363e

Please sign in to comment.