diff --git a/.gitignore b/.gitignore index c6e5e5a4..44b27a28 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,4 @@ __pycache__ # Testing suite Testing -test/c3dFiles/C3dTestSuite +test/c3dFiles/* diff --git a/.travis.yml b/.travis.yml index f5363e9b..e36be4ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,16 +63,29 @@ script: cmake --build ./ --config Release; fi # Only do the coverage on Linux, but run the test anyway to get a nice output + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then + cp -r test/c3dTestFiles/ .; + elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + cd test; + elif [[ "$TRAVIS_OS_NAME" == "windows" ]]; then + cp bin/Release/*.dll ./test/Release; + cp Release/*.dll ./test/Release; + cd test\\Release; + mkdir .\\c3dTestFiles; + xcopy ..\\c3dTestFiles .\\c3dTestFiles; + fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make ezc3d_coverage; elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./runUnitTests; elif [[ "$TRAVIS_OS_NAME" == "windows" ]]; then - cp bin/Release/*.dll .; - cp Release/*.dll .; - cp Release/*.exe .; ./runUnitTests.exe; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + cd ..; + elif [[ "$TRAVIS_OS_NAME" == "windows" ]]; then + cd ../..; + fi - ctest - if [[ "$TRAVIS_OS_NAME" != "windows" ]]; then cmake ${CMAKE_OPTIONS} -DCMAKE_INSTALL_PREFIX=$HOME/miniconda/ -DCMAKE_CXX_FLAGS=${CXX_FLAGS} -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF -DBUILD_DOC=OFF -DBUILD_EXAMPLE=OFF -DBINDER_PYTHON3=ON ..; diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c8a8d89..706273f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "_debug") # Add headers target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) -# Installation +# Install target if(WIN32) set(${PROJECT_NAME}_LIB_FOLDER Lib) set(${PROJECT_NAME}_BIN_FOLDER bin) @@ -43,139 +43,39 @@ install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${${PROJECT_NAME}_LIB_FOLDER} ) install(DIRECTORY include DESTINATION ${${PROJECT_NAME}_INCLUDE_FOLDER}) - -# Add binding subdirectory + +# uninstall target +if(NOT TARGET uninstall) + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + + add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) +endif() + +# Binders add_subdirectory(binding) -# Add the example if asked +# Examples if(NOT WIN32) - set(BUILD_EXAMPLE TRUE CACHE BOOL "Build a C++ example") + option(BUILD_EXAMPLE "Build a C++ example" ON) if (BUILD_EXAMPLE) add_subdirectory(example) endif() endif(NOT WIN32) - -################################ -# Documentation -################################ - -# first we can indicate the documentation build as an option and set it to ON by default +# Doc option(BUILD_DOC "Build documentation" OFF) - if (BUILD_DOC) - # check if Doxygen is installed - find_package(Doxygen) - if (DOXYGEN_FOUND) - # set input and output files - set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in) - set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) - - # request to configure the file - configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) - - # note the option ALL which allows to build the docs together with the application - add_custom_target( doc_doxygen ALL - COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Generating API documentation with Doxygen" - VERBATIM ) - else (DOXYGEN_FOUND) - message("Doxygen need to be installed to generate the doxygen documentation") - endif (DOXYGEN_FOUND) + add_subdirectory(docs) endif (BUILD_DOC) - -################################ # Testing -################################ - -# Options. Turn on with 'cmake -DBUILD_TESTS=ON'. option(BUILD_TESTS "Build all tests." OFF) # Makes boolean 'test' available. - if (BUILD_TESTS) - # Download gtest if necessary - set(RELATIVE_PATH_TO_GTEST external/gtest) - find_path(GTEST_INCLUDE_DIR gtest.h HINTS ${CMAKE_CURRENT_SOURCE_DIR}/${RELATIVE_PATH_TO_GTEST}/googletest/include/gtest) - - if((NOT GTEST_INCLUDE_DIR) OR (NOT EXISTS ${GTEST_INCLUDE_DIR})) - # we couldn't find the header files for gtest or they don't exist - message("Unable to find gtest") - - # we have a submodule setup for gtest, assume it is under external/gtest - # now we need to clone this submodule - execute_process(COMMAND git submodule update --init -- external/gtest - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - - find_path(GTEST_INCLUDE_DIR gtest.h HINTS ${CMAKE_CURRENT_SOURCE_DIR}/${RELATIVE_PATH_TO_GTEST}/googletest/include/gtest) - endif() - - # Prevent overriding the parent project's compiler/linker - # settings on Windows - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - - # Add googletest directly to our build. This defines - # the gtest and gtest_main targets. - set(BUILD_GMOCK OFF) - set(INSTALL_GTEST OFF) - add_subdirectory(${RELATIVE_PATH_TO_GTEST} - ${CMAKE_BINARY_DIR}/gtest - EXCLUDE_FROM_ALL) - - ############## - # Unit Tests - ############## - enable_testing() - - file(GLOB TEST_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/test/*.cpp) - add_executable(runUnitTests ${TEST_SRC_FILES}) - - # Standard linking to gtest stuff. - target_link_libraries(runUnitTests gtest_main) - - # Extra linking for the project. - target_link_libraries(runUnitTests ${PROJECT_NAME}) - - # This is so you can do 'make test' to see all your tests run, instead of - # manually running the executable runUnitTests to see those specific tests. - add_test(UnitTests runUnitTests) - - if (CMAKE_BUILD_TYPE STREQUAL "Coverage") - set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.travis/cmake) - - include(CodeCoverage) - setup_target_for_coverage(${PROJECT_NAME}_coverage runUnitTests coverage) - - SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") - SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") - endif() #CMAKE_BUILD_TYPE STREQUAL "Coverage" - - # Download and copy c3d test files from test test suite of c3d.org and add them to the local test files - IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/c3dFiles/C3dTestSuite) - set(TEST_FILES_TO_DOWNLOAD Sample01.zip Sample02.zip) - foreach(FILE ${TEST_FILES_TO_DOWNLOAD}) - file( - DOWNLOAD https://www.c3d.org/data/${FILE} - ${CMAKE_CURRENT_SOURCE_DIR}/test/c3dFiles/C3dTestSuite/${FILE} - TIMEOUT 60 # seconds - TLS_VERIFY ON - ) - get_filename_component(FOLDER_NAME ${FILE} NAME_WE) - file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test/c3dFiles/C3dTestSuite/${FOLDER_NAME}) - execute_process( - COMMAND ${CMAKE_COMMAND} -E tar -xf ../${FILE} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test/c3dFiles/C3dTestSuite/${FOLDER_NAME}/ - ) - file(GLOB C3D_TEST_FILES ${CMAKE_CURRENT_SOURCE_DIR}/test/c3dFiles/C3dTestSuite/${FOLDER_NAME}/*.c3d) - file(COPY ${C3D_TEST_FILES} - DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/c3dTestFiles/) - endforeach() - endif() - - # Copy also some local c3d test files - file(GLOB C3D_TEST_FILES ${CMAKE_CURRENT_SOURCE_DIR}/test/c3dFiles/*.c3d) - file(COPY ${C3D_TEST_FILES} - DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/c3dTestFiles/) + add_subdirectory(test) endif() diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in new file mode 100644 index 00000000..26b84397 --- /dev/null +++ b/cmake_uninstall.cmake.in @@ -0,0 +1,22 @@ +if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") +endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") + +file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +foreach(file ${files}) + message(STATUS "Uninstalling $ENV{DESTDIR}${file}") + if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + exec_program( + "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") + endif(NOT "${rm_retval}" STREQUAL 0) + else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File $ENV{DESTDIR}${file} does not exist.") + endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") +endforeach(file) + diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt new file mode 100644 index 00000000..ed11b774 --- /dev/null +++ b/docs/CMakeLists.txt @@ -0,0 +1,18 @@ +set(MASTER_PROJECT_NAME ${PROJECT_NAME}) +project(${MASTER_PROJECT_NAME}_docs) + +# check if Doxygen is installed +find_package(Doxygen REQUIRED) +# set input and output files +set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) +set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) + +# request to configure the file +configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) + +# note the option ALL which allows to build the docs together with the application +add_custom_target( doc_doxygen ALL + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generating API documentation with Doxygen" + VERBATIM ) diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index bf138a70..7a455ddd 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -1,7 +1,7 @@ -OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@/docs/ -INPUT += @CMAKE_CURRENT_SOURCE_DIR@/include/ -INPUT += @CMAKE_CURRENT_SOURCE_DIR@/src/ -INPUT += @CMAKE_CURRENT_SOURCE_DIR@/docs +OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@/ +INPUT += @CMAKE_SOURCE_DIR@/include/ +INPUT += @CMAKE_SOURCE_DIR@/src/ +INPUT += @CMAKE_SOURCE_DIR@/docs # Remove dll_export that confuses Doxygen ENABLE_PREPROCESSING = YES @@ -15,4 +15,4 @@ FULL_PATH_NAMES = NO SOURCE_BROWSER = YES # Add the Readme file -INPUT += @CMAKE_CURRENT_SOURCE_DIR@/README.md +INPUT += @CMAKE_SOURCE_DIR@/README.md diff --git a/src/Data.cpp b/src/Data.cpp index e19226ab..9b220da7 100644 --- a/src/Data.cpp +++ b/src/Data.cpp @@ -31,8 +31,12 @@ ezc3d::DataNS::Data::Data(ezc3d::c3d &c3d, std::fstream &file) // Read the data PROCESSOR_TYPE processorType(c3d.parameters().processorType()); - float pointScaleFactor(c3d.parameters().group("POINT").parameter("SCALE").valuesAsFloat()[0]); - std::vector analogScaleFactors(c3d.parameters().group("ANALOG").parameter("SCALE").valuesAsFloat()); + float pointScaleFactor(-1); + if (c3d.header().nb3dPoints()) + pointScaleFactor = c3d.parameters().group("POINT").parameter("SCALE").valuesAsFloat()[0]; + std::vector analogScaleFactors; + if (c3d.header().nbAnalogs()) + analogScaleFactors = c3d.parameters().group("ANALOG").parameter("SCALE").valuesAsFloat(); float analogGeneralFactor(c3d.parameters().group("ANALOG").parameter("GEN_SCALE").valuesAsFloat()[0]); std::vector analogZeroOffset(c3d.parameters().group("ANALOG").parameter("OFFSET").valuesAsInt()); for (size_t j = 0; j < c3d.header().nbFrames(); ++j){ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..b3ad1d93 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,90 @@ +set(MASTER_PROJECT_NAME ${PROJECT_NAME}) +project(${MASTER_PROJECT_NAME}_test) + +# Download gtest if necessary +set(RELATIVE_PATH_TO_GTEST external/gtest) +find_path(GTEST_INCLUDE_DIR gtest.h HINTS ${CMAKE_SOURCE_DIR}/${RELATIVE_PATH_TO_GTEST}/googletest/include/gtest) + +if((NOT GTEST_INCLUDE_DIR) OR (NOT EXISTS ${GTEST_INCLUDE_DIR})) + # we couldn't find the header files for gtest or they don't exist + message("Unable to find gtest, try to automatically download it") + + # we have a submodule setup for gtest, assume it is under external/gtest + # now we need to clone this submodule + execute_process(COMMAND git submodule update --init -- external/gtest + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + + find_path(GTEST_INCLUDE_DIR gtest.h HINTS ${CMAKE_SOURCE_DIR}/${RELATIVE_PATH_TO_GTEST}/googletest/include/gtest) +endif() + +# Prevent overriding the parent project's compiler/linker +# settings on Windows +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +# Add googletest directly to our build. This defines +# the gtest and gtest_main targets. +set(BUILD_GMOCK OFF) +set(INSTALL_GTEST OFF) +add_subdirectory(${CMAKE_SOURCE_DIR}/${RELATIVE_PATH_TO_GTEST} + ${CMAKE_BINARY_DIR}/gtest + EXCLUDE_FROM_ALL) + +############## +# Unit Tests +############## +enable_testing() +file(GLOB TEST_SRC_FILES ${CMAKE_SOURCE_DIR}/test/*.cpp) +add_executable(runUnitTests ${TEST_SRC_FILES}) +add_dependencies(runUnitTests ${MASTER_PROJECT_NAME}) + +# headers for the project +target_include_directories(runUnitTests PUBLIC + ${CMAKE_SOURCE_DIR}/include +) + +# Standard linking to gtest stuff. +target_link_libraries(runUnitTests gtest_main) + +# Extra linking for the project. +target_link_libraries(runUnitTests ${MASTER_PROJECT_NAME}) + +# This is so you can do 'make test' to see all your tests run, instead of +# manually running the executable runUnitTests to see those specific tests. +add_test(UnitTests runUnitTests) + +if (CMAKE_BUILD_TYPE STREQUAL "Coverage") + set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/.travis/cmake) + + include(CodeCoverage) + setup_target_for_coverage(${MASTER_PROJECT_NAME}_coverage runUnitTests coverage) + + SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") + SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") +endif() #CMAKE_BUILD_TYPE STREQUAL "Coverage" + +# Download and copy c3d test files from test test suite of c3d.org and add them to the local test files +set(TEST_FILES_TO_DOWNLOAD Sample01.zip Sample02.zip) +foreach(FILE ${TEST_FILES_TO_DOWNLOAD}) + get_filename_component(FOLDER_NAME ${FILE} NAME_WE) + IF(NOT EXISTS ${CMAKE_SOURCE_DIR}/test/c3dFiles/C3dTestSuite/${FILE}) + file( + DOWNLOAD https://www.c3d.org/data/${FILE} + ${CMAKE_SOURCE_DIR}/test/c3dFiles/C3dTestSuite/${FILE} + TIMEOUT 60 # seconds + TLS_VERIFY ON + ) + file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/test/c3dFiles/C3dTestSuite/${FOLDER_NAME}) + execute_process( + COMMAND ${CMAKE_COMMAND} -E tar -xf ../${FILE} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test/c3dFiles/C3dTestSuite/${FOLDER_NAME}/ + ) + endif() + file(GLOB C3D_TEST_FILES ${CMAKE_SOURCE_DIR}/test/c3dFiles/C3dTestSuite/${FOLDER_NAME}/*.c3d) + file(COPY ${C3D_TEST_FILES} + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/c3dTestFiles/) +endforeach() + +# Copy also some local c3d test files +file(GLOB C3D_TEST_FILES ${CMAKE_SOURCE_DIR}/test/c3dFiles/*.c3d) +file(COPY ${C3D_TEST_FILES} + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/c3dTestFiles/)