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

Draft: refactor the structure #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
147 changes: 90 additions & 57 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,77 +1,110 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.12)

project(duckx VERSION 0.2)
project(duckx VERSION "0.3.0")

set(CMAKE_CXX_STANDARD 11)

# build the tests only if the project is being built as a standalone one
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
option(CMAKE_DISABLE_TESTING OFF)
else()
option(CMAKE_DISABLE_TESTING ON)
endif()

option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF)
option(BUILD_SAMPLES "Build provided samples" OFF)

# Fix issues when building with clang 12, next version of clang
# else we might encounter errors making the library
# not being able to be compiled

set(CMAKE_CXX_STANDARD 11)

set(HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/duckx.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/constants.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/duckxiterator.hpp")
set(SOURCES src/duckx.cpp)
# thirdparty
include(ExternalProject)
include(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/pugixml.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zip.cmake)

set(THIRD_PARTY_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/pugixml/pugixml.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/pugixml/pugiconfig.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zip/zip.h")
set(THIRD_PARTY_SRC "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zip/zip.c")
file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*)
file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*)

include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/pugixml"
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zip")
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${PUGIXML_INCLUDE}
${ZIP_INCLUDE}
)

if(BUILD_SHARED_LIBS)
add_library(duckx SHARED ${SOURCES} ${THIRD_PARTY_SRC})
else()
add_library(duckx STATIC ${SOURCES} ${THIRD_PARTY_SRC})
endif()
add_library(${PROJECT_NAME} ${SOURCES})
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

add_library(duckx::duckx ALIAS duckx)
target_link_libraries(${PROJECT_NAME} ${PUGIXML_LIB} ${ZIP_LIB})

target_include_directories(duckx PUBLIC
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>
)

mark_as_advanced(CLEAR CMAKE_INSTALL_LIBDIR CMAKE_INSTALL_INCLUDEDIR)
# tests
if(NOT CMAKE_DISABLE_TESTING)
enable_testing()
add_subdirectory(test)
endif()

if (BUILD_SAMPLES)
# Sample executable
set(SAMPLE1_SOURCES samples/sample1.cpp)
add_executable(duckx_sample1 ${SAMPLE1_SOURCES})
target_link_libraries(duckx_sample1 duckx)

set(SAMPLE2_SOURCES samples/sample2.cpp)
add_executable(duckx_sample2 ${SAMPLE2_SOURCES})
target_link_libraries(duckx_sample2 duckx)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/samples/my_test.docx
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif()
# option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF)
# option(BUILD_SAMPLES "Build provided samples" OFF)

include(GNUInstallDirs)
install(
TARGETS duckx
EXPORT duckxConfig
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${INSTALL_SUFFIX}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${INSTALL_SUFFIX}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(EXPORT duckxConfig NAMESPACE duckx:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/duckx)
install(FILES ${HEADERS} ${THIRD_PARTY_HEADERS} DESTINATION include/duckx)


if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
enable_testing()
add_subdirectory(test)
endif()

# set(HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/duckx.hpp"
# "${CMAKE_CURRENT_SOURCE_DIR}/include/constants.hpp"
# "${CMAKE_CURRENT_SOURCE_DIR}/include/duckxiterator.hpp")
# set(SOURCES src/duckx.cpp)

# set(THIRD_PARTY_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/pugixml/pugixml.hpp"
# "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/pugixml/pugiconfig.hpp"
# "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zip/zip.h")
# set(THIRD_PARTY_SRC "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zip/zip.c")

# include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include"
# "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/pugixml"
# "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zip")

# if(BUILD_SHARED_LIBS)
# add_library(duckx SHARED ${SOURCES} ${THIRD_PARTY_SRC})
# else()
# add_library(duckx STATIC ${SOURCES} ${THIRD_PARTY_SRC})
# endif()

# add_library(duckx::duckx ALIAS duckx)

# target_include_directories(duckx PUBLIC
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
# $<INSTALL_INTERFACE:include>
# )

# mark_as_advanced(CLEAR CMAKE_INSTALL_LIBDIR CMAKE_INSTALL_INCLUDEDIR)

# if (BUILD_SAMPLES)
# # Sample executable
# set(SAMPLE1_SOURCES samples/sample1.cpp)
# add_executable(duckx_sample1 ${SAMPLE1_SOURCES})
# target_link_libraries(duckx_sample1 duckx)

# set(SAMPLE2_SOURCES samples/sample2.cpp)
# add_executable(duckx_sample2 ${SAMPLE2_SOURCES})
# target_link_libraries(duckx_sample2 duckx)

# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/samples/my_test.docx
# DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
# endif()

# include(GNUInstallDirs)
# install(
# TARGETS duckx
# EXPORT duckxConfig
# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${INSTALL_SUFFIX}
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${INSTALL_SUFFIX}
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
# )
# install(EXPORT duckxConfig NAMESPACE duckx:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/duckx)
# install(FILES ${HEADERS} ${THIRD_PARTY_HEADERS} DESTINATION include/duckx)


# if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
# enable_testing()
# add_subdirectory(test)
# endif()

File renamed without changes.
2 changes: 1 addition & 1 deletion samples/sample1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using namespace std;

int main() {
duckx::Document doc("my_test.docx");
duckx::Document doc("sample.docx");
doc.open();

for (auto p = doc.paragraphs(); p.has_next(); p.next()) {
Expand Down
2 changes: 1 addition & 1 deletion samples/sample2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using namespace std;

int main() {
duckx::Document doc("my_test.docx");
duckx::Document doc("sample.docx");
doc.open();

duckx::Paragraph p =
Expand Down
55 changes: 17 additions & 38 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,44 +1,23 @@
set (CMAKE_CXX_STANDARD 11)
cmake_minimum_required(VERSION 3.12)

add_executable(
unit_tests
basic_tests.cpp
)
set(CMAKE_CXX_STANDARD 11)

target_link_libraries(
unit_tests
duckx
)
# Install doctest
if(NOT EXISTS ${CMAKE_BINARY_DIR}/doctest.h)
file(DOWNLOAD
https://github.com/doctest/doctest/releases/download/v2.4.9/doctest.h
doctest.h)
endif()
include_directories(${CMAKE_BINARY_DIR})

add_test(
NAME
unit
COMMAND
unit_tests
)
configure_file(sample.docx ${CMAKE_BINARY_DIR}/sample.docx COPYONLY)

add_executable(
iterator_tests
iterator_tests.cpp
)
# Tests
add_executable(basic_tests basic_tests.cpp)
target_link_libraries(basic_tests duckx)
add_test(NAME basic_tests COMMAND basic_tests)

target_link_libraries(
iterator_tests
duckx
)
add_executable(iterator_tests iterator_tests.cpp)
target_link_libraries(iterator_tests duckx)
add_test(NAME iterator_tests COMMAND iterator_tests)

add_test(
NAME
iterator
COMMAND
iterator_tests
)

# Need C++11 for iterator tests
set_target_properties(iterator_tests PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)

configure_file(my_test.docx ${CMAKE_CURRENT_BINARY_DIR}/my_test.docx COPYONLY)
4 changes: 2 additions & 2 deletions test/basic_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"

TEST_CASE("checks contents of my_test.docx") {
duckx::Document doc("my_test.docx");
TEST_CASE("checks contents of sample.docx") {
duckx::Document doc("sample.docx");
doc.open();

std::ostringstream ss;
Expand Down
Loading