diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt new file mode 100644 index 0000000..814967a --- /dev/null +++ b/cpp/CMakeLists.txt @@ -0,0 +1,87 @@ +# +# Makefile for QR Code generator (C++) +# +# Copyright (c) Project Nayuki. (MIT License) +# https://www.nayuki.io/page/qr-code-generator-library +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# - The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# - The Software is provided "as is", without warranty of any kind, express or +# implied, including but not limited to the warranties of merchantability, +# fitness for a particular purpose and noninfringement. In no event shall the +# authors or copyright holders be liable for any claim, damages or other +# liability, whether in an action of contract, tort or otherwise, arising from, +# out of or in connection with the Software or the use or other dealings in the +# Software. +# +cmake_minimum_required(VERSION 3.0) + +project(QrCode VERSION 1.0.0) + +add_definitions("-Wall") +add_definitions("-Wextra") +add_definitions("-Werror") +#add_definitions("-fsanitize=undefined") + +set(${PROJECT_NAME}_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}") + +include_directories(${${PROJECT_NAME}_INCLUDE_DIR}) + +file(GLOB ${PROJECT_NAME}_PUBLIC_HEADERS "${${PROJECT_NAME}_INCLUDE_DIR}/*.hpp") +file(GLOB ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") + +add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SOURCES}) + +set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO) + +set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${${PROJECT_NAME}_PUBLIC_HEADERS}") +set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) + +# Installation options +include(GNUInstallDirs) +set(${PROJECT_NAME}_INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Installation directory for libraries") +set(${PROJECT_NAME}_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} CACHE PATH "Installation directory for header files") +set(${PROJECT_NAME}_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} CACHE PATH "Installation directory for CMake files") + +# Get absolute path where to install files +foreach(p LIB BIN INCLUDE CMAKE) + set(var ${PROJECT_NAME}_INSTALL_${p}_DIR) + if(NOT IS_ABSOLUTE "${${var}}") + set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") + endif() +endforeach() + +# Exporting target +export(TARGETS ${PROJECT_NAME} FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.cmake") +export(PACKAGE ${PROJECT_NAME}) + +file(RELATIVE_PATH ${PROJECT_NAME}_REL_INCLUDE_DIR "${${PROJECT_NAME}_INSTALL_CMAKE_DIR}" "${${PROJECT_NAME}_INSTALL_INCLUDE_DIR}") + +## configure for build tree +set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}") +configure_file(${PROJECT_NAME}Config.cmake.in "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @ONLY) + +## configure for install tree +set(CONF_INCLUDE_DIRS "\${${PROJECT_NAME}_CMAKE_DIR}/${REL_INCLUDE_DIR}") +configure_file(${PROJECT_NAME}Config.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake" @ONLY) + +## ... for both +configure_file(${PROJECT_NAME}ConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" @ONLY) + +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME} DESTINATION "${${PROJECT_NAME}_INSTALL_CMAKE_DIR}" COMPONENT dev + LIBRARY DESTINATION "${${PROJECT_NAME}_INSTALL_LIB_DIR}" + PUBLIC_HEADER DESTINATION "${${PROJECT_NAME}_INSTALL_INCLUDE_DIR}" COMPONENT dev) + +install(FILES + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION "${${PROJECT_NAME}_INSTALL_CMAKE_DIR}" COMPONENT dev) \ No newline at end of file diff --git a/cpp/Makefile b/cpp/Makefile index 151a4da..dffafdc 100644 --- a/cpp/Makefile +++ b/cpp/Makefile @@ -32,6 +32,7 @@ CXXFLAGS += -std=c++11 # Diagnostics. Adding '-fsanitize=address' is helpful for most versions of Clang and newer versions of GCC. CXXFLAGS += -Wall -fsanitize=undefined +CXXFLAGS += -IQrCode # Optimization level CXXFLAGS += -O1 @@ -62,5 +63,5 @@ clean: rm -f -- $(MAINS) # Executable files -%: %.cpp $(LIBSRC:=.cpp) $(LIBSRC:=.hpp) - $(CXX) $(CXXFLAGS) -o $@ $< $(LIBSRC:=.cpp) +%: examples/%.cpp $(addprefix src/,$(LIBSRC:=.cpp)) $(addprefix QrCode/,$(LIBSRC:=.hpp)) + $(CXX) $(CXXFLAGS) -o $@ $< $(addprefix src/,$(LIBSRC:=.cpp)) diff --git a/cpp/BitBuffer.hpp b/cpp/QrCode/BitBuffer.hpp similarity index 100% rename from cpp/BitBuffer.hpp rename to cpp/QrCode/BitBuffer.hpp diff --git a/cpp/QrCode.hpp b/cpp/QrCode/QrCode.hpp similarity index 100% rename from cpp/QrCode.hpp rename to cpp/QrCode/QrCode.hpp diff --git a/cpp/QrSegment.hpp b/cpp/QrCode/QrSegment.hpp similarity index 100% rename from cpp/QrSegment.hpp rename to cpp/QrCode/QrSegment.hpp diff --git a/cpp/QrCodeConfig.cmake.in b/cpp/QrCodeConfig.cmake.in new file mode 100644 index 0000000..8b52989 --- /dev/null +++ b/cpp/QrCodeConfig.cmake.in @@ -0,0 +1,14 @@ +# - Config file for the @PROJECT_NAME@ package +# It defines the following variables +# @PROJECT_NAME@_INCLUDE_DIRS - include directories for @PROJECT_NAME@ +# @PROJECT_NAME@_LIBRARIES - libraries to link against + +# Compute paths +get_filename_component(@PROJECT_NAME@_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(@PROJECT_NAME@_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") + +# Our library dependencies (contains definitions for IMPORTED targets) +include("${@PROJECT_NAME@_CMAKE_DIR}/@PROJECT_NAME@Targets.cmake") + +# These are IMPORTED targets created by @PROJECT_NAME@Targets.cmake +set(@PROJECT_NAME@_LIBRARIES "@PROJECT_NAME@") \ No newline at end of file diff --git a/cpp/QrCodeConfigVersion.cmake.in b/cpp/QrCodeConfigVersion.cmake.in new file mode 100644 index 0000000..e3c4e1a --- /dev/null +++ b/cpp/QrCodeConfigVersion.cmake.in @@ -0,0 +1,11 @@ +set(PACKAGE_VERSION "@PROJECT_VERSION@") + +# Check whether the requested PACKAGE_FIND_VERSION is compatible +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() \ No newline at end of file diff --git a/cpp/QrCodeGeneratorDemo.cpp b/cpp/examples/QrCodeGeneratorDemo.cpp similarity index 100% rename from cpp/QrCodeGeneratorDemo.cpp rename to cpp/examples/QrCodeGeneratorDemo.cpp diff --git a/cpp/QrCodeGeneratorWorker.cpp b/cpp/examples/QrCodeGeneratorWorker.cpp similarity index 100% rename from cpp/QrCodeGeneratorWorker.cpp rename to cpp/examples/QrCodeGeneratorWorker.cpp diff --git a/cpp/BitBuffer.cpp b/cpp/src/BitBuffer.cpp similarity index 100% rename from cpp/BitBuffer.cpp rename to cpp/src/BitBuffer.cpp diff --git a/cpp/QrCode.cpp b/cpp/src/QrCode.cpp similarity index 100% rename from cpp/QrCode.cpp rename to cpp/src/QrCode.cpp diff --git a/cpp/QrSegment.cpp b/cpp/src/QrSegment.cpp similarity index 100% rename from cpp/QrSegment.cpp rename to cpp/src/QrSegment.cpp