Skip to content

Commit

Permalink
Merge pull request #74 from pariterre/dev
Browse files Browse the repository at this point in the history
CMakes improvements
  • Loading branch information
pariterre authored Sep 5, 2019
2 parents 6e34fa5 + df730c5 commit 0bf0e5d
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ __pycache__

# Testing suite
Testing
test/c3dFiles/C3dTestSuite
test/c3dFiles/*
19 changes: 16 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..;
Expand Down
138 changes: 19 additions & 119 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()


Expand Down
22 changes: 22 additions & 0 deletions cmake_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -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)

18 changes: 18 additions & 0 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 )
10 changes: 5 additions & 5 deletions docs/Doxyfile.in
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
8 changes: 6 additions & 2 deletions src/Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> 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<float> 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<int> analogZeroOffset(c3d.parameters().group("ANALOG").parameter("OFFSET").valuesAsInt());
for (size_t j = 0; j < c3d.header().nbFrames(); ++j){
Expand Down
90 changes: 90 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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/)

0 comments on commit 0bf0e5d

Please sign in to comment.