Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export the ezc3d target. #116

Merged
merged 3 commits into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,55 @@ set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "_debug")
set(EZC3D_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

# Create the configuration header file associated with the asked options
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/ezc3dConfig.h.in ${EZC3D_BINARY_DIR}/include/ezc3dConfig.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/ezc3dConfig.h.in
${EZC3D_BINARY_DIR}/include/ezc3dConfig.h)

# Add headers
target_include_directories(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${EZC3D_BINARY_DIR}/include
)
# Include directories when building the library:
target_include_directories(${PROJECT_NAME} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/include"
"${EZC3D_BINARY_DIR}/include"
)
# Include directories when other targets in this project use this library:
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${EZC3D_BINARY_DIR}/include>
)

# Install target
if(WIN32)
set(${PROJECT_NAME}_LIB_FOLDER Lib)
set(${PROJECT_NAME}_BIN_FOLDER bin)
set(${PROJECT_NAME}_INCLUDE_FOLDER include/${PROJECT_NAME})
else()
set(${PROJECT_NAME}_LIB_FOLDER ${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME})
set(${PROJECT_NAME}_BIN_FOLDER ${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME})
set(${PROJECT_NAME}_INCLUDE_FOLDER ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME})
set(${PROJECT_NAME}_LIB_FOLDER lib/${PROJECT_NAME})
set(${PROJECT_NAME}_BIN_FOLDER lib/${PROJECT_NAME})
set(${PROJECT_NAME}_INCLUDE_FOLDER include/${PROJECT_NAME})
Comment on lines +69 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RPath is no longer set properly for the Python interface if ${CMAKE_INSTALL_PREFIX} is not present. On my computer I get
Set runtime path of "/home/pariterre/Programmation/miniconda3/envs/ezc3d-dev/lib/python3.8/site-packages/ezc3d/_ezc3d.so" to "lib/ezc3d"
which is not the right path (unless you change the LD_LIBRARY_PATH which I don't want to do).

Any suggestions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two possibilities for the RPATH for python bindings:

A. If the python bindings are expected to be used from their installed location, then you can use a relative RPATH, because you know the relative location of the ezc3d library.

B. If the python bindings are expected to be installed into your python distribution, then you need to use an absolute RPATH to the ezc3d library.

Which do you prefer? I think OpenSim has a CMake flag to toggle between A and B. We have spent a lot of time getting RPATH to work well for OpenSim, so we can refer to what OpenSim does.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer the case B since I install the python binding in the Python site-package folder.
Unless it makes it incompatible with OpenSim, lets keep it as B :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I pushed a change that fixed the RPATH to be absolute again.

endif()
install(TARGETS ${PROJECT_NAME}
install(TARGETS ${PROJECT_NAME} EXPORT ezc3dTargets
ARCHIVE DESTINATION ${${PROJECT_NAME}_LIB_FOLDER}
RUNTIME DESTINATION ${${PROJECT_NAME}_BIN_FOLDER}
LIBRARY DESTINATION ${${PROJECT_NAME}_LIB_FOLDER}
)
install(DIRECTORY include/ DESTINATION ${${PROJECT_NAME}_INCLUDE_FOLDER})
install(FILES ${EZC3D_BINARY_DIR}/include/ezc3dConfig.h DESTINATION ${${PROJECT_NAME}_INCLUDE_FOLDER})
install(DIRECTORY include/ DESTINATION ${${PROJECT_NAME}_INCLUDE_FOLDER}
# Exclude ezc3dConfig.h.in.
PATTERN "*.h.in" EXCLUDE)
# Include directories when a client uses the library from an installed ezc3d:
target_include_directories(${PROJECT_NAME} INTERFACE
$<INSTALL_INTERFACE:${${PROJECT_NAME}_INCLUDE_FOLDER}>)
install(FILES "${EZC3D_BINARY_DIR}/include/ezc3dConfig.h"
DESTINATION "${${PROJECT_NAME}_INCLUDE_FOLDER}")

# Prepare share
include(CMakePackageConfigHelpers)
configure_package_config_file(
share/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${PROJECT_NAME}_LIB_FOLDER/cmake
INSTALL_DESTINATION ${${PROJECT_NAME}_LIB_FOLDER}/cmake
PATH_VARS
CMAKE_INSTALL_PREFIX
)
install(EXPORT ezc3dTargets DESTINATION ${${PROJECT_NAME}_LIB_FOLDER}/cmake)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION ${${PROJECT_NAME}_LIB_FOLDER}/cmake
Expand Down
2 changes: 1 addition & 1 deletion binding/ezc3d.i
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace std {
}
}

// Includes all neceressary files from the API
// Includes all necessary files from the API
%include "ezc3dConfig.h"
%include "ezc3d.h"
%include "Matrix.h"
Expand Down
4 changes: 2 additions & 2 deletions binding/matlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ foreach(SUFFIXES Read Write)
# Add project
add_library(${PROJECT_NAME}_${SUFFIXES} SHARED ${CPP_FILE_${SUFFIXES}} ${CMAKE_CURRENT_SOURCE_DIR}/Matlabdef.def)

target_link_libraries(${PROJECT_NAME}_${SUFFIXES} ezc3d)

# Reset the name of the output
if(WIN32)
SET_TARGET_PROPERTIES(${PROJECT_NAME}_${SUFFIXES} PROPERTIES OUTPUT_NAME ${MASTER_PROJECT_NAME}${SUFFIXES})
Expand All @@ -25,8 +27,6 @@ foreach(SUFFIXES Read Write)
# Add headers
target_include_directories(${PROJECT_NAME}_${SUFFIXES} PUBLIC
${Matlab_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CUREENT_SOURCE_DIR}/../../include
${EZC3D_BINARY_DIR}/include
)

Expand Down
8 changes: 6 additions & 2 deletions binding/matlab/ezc3dWrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ void mexFunction(
} else if (type == ezc3d::DATA_TYPE::FLOAT) {
std::vector<float> data;
parseParam(mxGetDoubles(valueField), dimension, data);
newParam.set(data, dimension);
newParam.set(
std::vector<double>(data.begin(), data.end()),
dimension);
Comment on lines +374 to +376
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx! I did not update the Matlab interface yet with the new changes :)

} else if (type == ezc3d::DATA_TYPE::CHAR) {
std::vector<std::string> data;
parseParam(valueField, dimension, data);
Expand All @@ -386,7 +388,9 @@ void mexFunction(
if (!valueField || mxIsDouble(valueField)) {
std::vector<float> data;
parseParam(mxGetDoubles(valueField), dimension, data);
newParam.set(data, dimension);
newParam.set(
std::vector<double>(data.begin(), data.end()),
dimension);
} else if (mxIsCell(valueField)) {
std::vector<std::string> data;
parseParam(valueField, dimension, data);
Expand Down
13 changes: 4 additions & 9 deletions binding/python3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ if(WIN32)
endif()
# For some reasons, target_include_directories later in the file sometime fails
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../../include
${EZC3D_BINARY_DIR}/include
)

Expand All @@ -25,19 +24,15 @@ SWIG_ADD_LIBRARY(${PROJECT_NAME} TYPE MODULE LANGUAGE python SOURCES ${I_SOURCE_
swig_link_libraries(${PROJECT_NAME} ${PROJECT_NAME} ${PYTHON_LIBRARIES} ${NUMPY_LIBRARIES})

# Add headers
target_include_directories(_${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../include
${EZC3D_BINARY_DIR}/include
)
set_target_properties(_${PROJECT_NAME} PROPERTIES SWIG_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/../../include)

if(APPLE)
SET_TARGET_PROPERTIES(_${PROJECT_NAME} PROPERTIES SUFFIX ".so" INSTALL_RPATH ${${PROJECT_NAME}_BIN_FOLDER})
set_target_properties(_${PROJECT_NAME} PROPERTIES SUFFIX ".so")
set_property(TARGET _${PROJECT_NAME} APPEND PROPERTY LINK_FLAGS "-flat_namespace -undefined suppress")
else()
SET_TARGET_PROPERTIES(_${PROJECT_NAME} PROPERTIES INSTALL_RPATH ${${PROJECT_NAME}_BIN_FOLDER})
endif()
SET_TARGET_PROPERTIES(_${PROJECT_NAME} PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
set_target_properties(_${PROJECT_NAME} PROPERTIES
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${${PROJECT_NAME}_BIN_FOLDER}")
set_target_properties(_${PROJECT_NAME} PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)

# Install to the proper directories
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.py
Expand Down
2 changes: 1 addition & 1 deletion include/Vector3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// \date March 25th, 2020
///

#include <Matrix.h>
#include "Matrix.h"

///
/// \brief 3D data
Expand Down
14 changes: 4 additions & 10 deletions share/ezc3dConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ set(ezc3d_VERSION @PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSI

@PACKAGE_INIT@

set_and_check(ezc3d_INCLUDE_DIR "@ezc3d_INCLUDE_FOLDER@")
set_and_check(ezc3d_LIBRARY_DIR "@ezc3d_LIB_FOLDER@")
set_and_check(ezc3d_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/@ezc3d_INCLUDE_FOLDER@")
set_and_check(ezc3d_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/@ezc3d_LIB_FOLDER@")

find_library (ezc3d_LIBRARY NAMES ezc3d ezc3d_debug PATHS ${ezc3d_LIBRARY_DIR})
set(ezc3d_LIBRARY ezc3d)

# handle the QUIETLY and REQUIRED arguments and set ezc3d_FOUND to TRUE if
# all listed variables are TRUE
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (ezc3d DEFAULT_MSG
ezc3d_INCLUDE_DIR
ezc3d_LIBRARY
)
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

check_required_components(ezc3d)