Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… system, \n issue open-license-manager#38 added clang format
  • Loading branch information
gcontini committed Nov 16, 2019
1 parent bd25f80 commit 5a8a12d
Show file tree
Hide file tree
Showing 29 changed files with 460 additions and 210 deletions.
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BasedOnStyle: Google
Language: Cpp
Standard: Cpp11
IndentWidth: 4
TabWidth: 4
ColumnLimit: 120
UseTab: Always
AccessModifierOffset: -4
AlignTrailingComments: false
FixNamespaceComments: true
SortIncludes: false
SortUsingDeclarations : true
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "extern/license-generator"]
path = extern/license-generator
url = https://github.com/open-license-manager/olm-license-generator.git
url = https://github.com/open-license-manager/lcc-license-generator.git
branch = develop
85 changes: 69 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SET(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
IF(NOT LCC_PROJECT_NAME)
message(WARNING "You should define a variable LCC_PROJECT_NAME containing the name of the software you want to add a license to."
"A mock product named DEFAULT has been added for you.")
set(LCC_PROJECT_NAME "DEFAULT")
set(LCC_PROJECT_NAME "DEFAULT" CACHE STRING "Project name (name of the software for which you want to issue a license)")
ENDIF(NOT LCC_PROJECT_NAME)

#base folder where projects are stored (/projects)
Expand All @@ -26,8 +26,69 @@ project (licensecc C CXX )
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")

#find olm executable or build it.
find_package(olm REQUIRED)
#find lcc executable or build it.
find_package(lcc REQUIRED)

#Not sure about this. My system doesn't support binfmt misc
IF( ( CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" ) AND CMAKE_CROSSCOMPILING AND NOT DEFINED CMAKE_CROSSCOMPILING_EMULATOR )
SET(CMAKE_CROSSCOMPILING_EMULATOR "wine")
ENDIF()

if(MSVC)
include(target_arch)
target_architecture( TARGET_ARCHITECTURE )
message(STATUS "architecture detected: ${TARGET_ARCHITECTURE}")

#Boost > 3.15 handle the /MD flag more nicely than this
if(${STATIC_RUNTIME})
string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
SET(Boost_USE_STATIC_RUNTIME ON)
endif(${STATIC_RUNTIME})

add_definitions("/D _CRT_SECURE_NO_WARNINGS")
else(MSVC)
if(MINGW)
list(APPEND EXTERNAL_LIBS "-lcrypt32 -lws2_32 -liphlpapi")
SET(CMAKE_EXE_LINKER_FLAGS "-static")
endif(MINGW)
endif(MSVC)

if(UNIX) #this is true for all the linux systems but not for cross compiling "linux->windows"
#find a static version of openssl crypto library
SET ( OPENSSL_USE_STATIC_LIBS ON )
find_package(OpenSSL REQUIRED COMPONENTS Crypto)
include_directories(${OPENSSL_INCLUDE_DIR})
#list(APPEND EXTERNAL_LIBS ${OPENSSL_CRYPTO_LIBRARY})
#find_package(Threads)
#if(THREADS_HAVE_PTHREAD_ARG)
# list(APPEND EXTERNAL_LIBS "-pthread")
#else(THREADS_HAVE_PTHREAD_ARG)
# if(CMAKE_THREAD_LIBS_INIT)
# list(APPEND EXTERNAL_LIBS "${CMAKE_THREAD_LIBS_INIT}")
# endif()
#endif(THREADS_HAVE_PTHREAD_ARG)
MESSAGE(STATUS "Found openssl version ${OPENSSL_VERSION} ")
#Zlib required when openssl version < 1.0.1f
#SET ( ZLIB_USE_STATIC_LIBS ON )
#find_package(ZLIB REQUIRED)
#MESSAGE(STATUS "Found zlib version ${ZLIB_VERSION} ")
find_program( MEMORYCHECK_COMMAND valgrind )
set( MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full" )
if(USE_DBUS_IDENTIFIER)
FIND_PACKAGE(Dbus REQUIRED)
add_definitions(-DUSE_DBUS)
include_directories(${DBUS_INCLUDE_DIR})
include_directories(${DBUS_ARCH_INCLUDE_DIR})
list(APPEND EXTERNAL_LIBS ${DBUS_LIBRARIES})
endif(USE_DBUS_IDENTIFIER)
if(NOT MINGW)
list(APPEND EXTERNAL_LIBS ${CMAKE_DL_LIBS})
endif(NOT MINGW)
endif(UNIX)


#load the current project from files or find it from environment variables or create a default one
set(LCC_INCLUDE_DIR "${LCC_PROJECTS_BASE_DIR}/${LCC_PROJECT_NAME}/include/${PROJECT_NAME}/${LCC_PROJECT_NAME}" )
Expand All @@ -36,18 +97,14 @@ set(LCC_PROJECT_PRIVATE_KEY "${LCC_PROJECTS_BASE_DIR}/${LCC_PROJECT_NAME}/privat

add_custom_command(
OUTPUT "${LCC_PROJECT_PUBLIC_KEY}" "${LCC_PROJECT_PRIVATE_KEY}"
COMMAND license_generator::olm project initialize -t "${PROJECT_SOURCE_DIR}/src/templates" -n "${LCC_PROJECT_NAME}" -p "${LCC_PROJECTS_BASE_DIR}"
COMMAND license_generator::lcc project initialize -t "${PROJECT_SOURCE_DIR}/src/templates" -n "${LCC_PROJECT_NAME}" -p "${LCC_PROJECTS_BASE_DIR}"
COMMENT "generating ${LCC_PROJECT_PUBLIC_KEY}"
USES_TERMINAL
)

add_custom_target(project_initialize DEPENDS "${LCC_PROJECT_PUBLIC_KEY}" "${LCC_PROJECT_PRIVATE_KEY}")

configure_file (
"src/templates/build_properties.h.in"
"${LCC_INCLUDE_DIR}/build_properties.h"
)
include_directories( ${LCC_INCLUDE_DIR} )
include_directories( ${LCC_INCLUDE_DIR} ${CMAKE_BINARY_DIR} )

message( STATUS "C compiler : " ${CMAKE_C_COMPILER})
message( STATUS "C compiler flags : " ${CMAKE_C_FLAGS})
Expand All @@ -62,6 +119,8 @@ message( STATUS "Install prefix : " ${CMAKE_INSTALL_PREFIX})
message( STATUS "Project name : " ${LCC_PROJECT_NAME} )
message( STATUS "Project base dir : " ${LCC_PROJECTS_BASE_DIR}/${LCC_PROJECT_NAME} )

add_subdirectory(src)

#boost is required only for tests
#bug in cmake win32 - can't find boost compiled with mingw
if(WIN32 AND "x${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "x")
Expand All @@ -73,15 +132,9 @@ if(WIN32 AND "x${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "x")
endif()
message(STATUS "Compiler architecture: ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")
endif()

add_subdirectory(src)

SET( Boost_USE_STATIC_LIBS ON )
find_package(Boost REQUIRED COMPONENTS date_time unit_test_framework program_options system filesystem)

#set below in case of dynamic linking in debug.
#set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:BOOST_TEST_DYN_LINK>)

#if boost is found enable tests
IF(Boost_FOUND)
INCLUDE(CTest)
Expand All @@ -91,7 +144,7 @@ IF(Boost_FOUND)
add_definitions(-DBOOST_ALL_NO_LIB) #Disable Boost Microsoft magic, all dependencies are handled by cmake
add_definitions(-DBOOST_LIB_DIAGNOSTIC) #Check it is really disabled
include_directories(${Boost_INCLUDE_DIRS})
# add_subdirectory(test)
add_subdirectory(test)
ENDIF(BUILD_TESTING)
ELSE(Boost_FOUND)
message(WARNING "Boost not found, disabling tests")
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Open License Manager

[![Language](https://img.shields.io/badge/language-C++-blue.svg)](https://isocpp.org/)
[![Standard](https://img.shields.io/badge/c%2B%2B-11-blue.svg)](https://en.wikipedia.org/wiki/C%2B%2B#Standardization)
[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![Build Status](https://travis-ci.org/open-license-manager/open-license-manager.svg?branch=develop)](https://travis-ci.org/open-license-manager/open-license-manager)
[![Coverage Status](https://codecov.io/gh/jinja2cpp/Jinja2Cpp/branch/master/graph/badge.svg)](https://codecov.io/gh/jinja2cpp/Jinja2Cpp)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/62d6e1bb22d648bd85b6f3bc344a545a)](https://www.codacy.com/manual/gcontini/open-license-manager?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=open-license-manager/open-license-manager&amp;utm_campaign=Badge_Grade)
[![Github Issues](![GitHub issues](https://img.shields.io/github/issues/open-license-manager/open-license-manager))](http://github.com/open-license-manager/open-license-manager/issues)

Expand All @@ -19,24 +17,24 @@ software closed :smirk: . A comprehensive [list of features](https://github.com/
The project is donated to the community. It comes with a very large freedom of use for everyone, and it will always be.
It uses a [BSD 3 clauses](https://opensource.org/licenses/BSD-3-Clause) licensing schema, that allows free modification and inclusion in commercial software.


## Project Structure
The software is made by 2 main sub-components:
* a C++ library with a nice C api, `licensecc` with minimal (or no) external dependencies (the part you have to integrate in your software).
* a license generator open-license-manager `olm` that allows you to generate a license.
* a license generator lcc-license-generator `lcc` for customizing the library and generate the licenses.

these modules are planned....
* a license [backoffice](../../issues/7) in php (in order to handle multiple licenses).
* a license debugger to be sent to the final customer when there are licensing problems.
* a [log descriptor](../../issues/8) in order to decrypt logs generated by the license system.

# How to build

Below an overview of the basic build procedure, you can find detailed instructions for each [supported environment](https://github.com/open-license-manager/open-license-manager/wiki/Build-the-library) in the wiki.
Below an overview of the basic build procedure, you can find [detailed instructions](https://github.com/open-license-manager/open-license-manager/wiki/Build-the-library) for your environment in the wiki.

## prerequisites
* compilsers: GCC (Linux) MINGW (Linux cross compile for Windows), MINGW or MSVC (Windows)
* tools/libs: cmake, boost. If target is linux openssl is necessary.
* compilers: GCC (Linux) MINGW (Linux cross compile for Windows), MINGW or MSVC (Windows)
* tools : cmake, git, make/ninja(linux)
* libs : If target is linux Openssl is required. Windows depends only on system libraries. Boost is necessary to build license generator and to run the tests but it's NOT a dependency of the `licensecc` library.


```
git clone https://github.com/open-license-manager/open-license-manager.git
Expand Down
63 changes: 32 additions & 31 deletions cmake/Findolm.cmake → cmake/Findlcc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,63 @@
# file Copyright.txt or https://cmake.org/licensing for details.

#[=======================================================================[.rst:
Findolm
Findlcc
-------
Find or build the olm executable.
Find or build the lcc executable.
Imported Targets
^^^^^^^^^^^^^^^^
This module provides the following imported targets, if found:
``license_generator::olm``
The olm executable
``license_generator::lcc``
The lcc executable
If olm is not found this module will try to download it as a submodule
If lcc is not found this module will try to download it as a submodule
Git must be installed.
Input variables
^^^^^^^^^^^^^^^^
``OLM_LOCATION`` Hint for locating the olm executable
``LCC_LOCATION`` Hint for locating the lcc executable
Result Variables
^^^^^^^^^^^^^^^^
This will define the following variables:
``OLM_FOUND``
``LCC_FOUND``
True if the system has the Foo library.
``olm_VERSION``
``lcc_VERSION``
Cache Variables
^^^^^^^^^^^^^^^
The following cache variables may also be set:
The following cache variables will also be set:
``OLM_EXECUTABLE``
Path to the olm executable.
``LCC_EXECUTABLE``
Path to the lcc executable.
#]=======================================================================]

set(olm_names olm olm.exe)
set (failure_messge "Error finding olm executable.")
set(lcc_names lcc lcc.exe)
set (failure_messge "Error finding lcc executable.")
find_package(PkgConfig)

if(OLM_LOCATION)
if(LCC_LOCATION)
# First search the PATH and specific locations.
find_program(OLM_EXECUTABLE
NAMES ${olm_names} HINTS ${OLM_LOCATION} DOC "olm command line client")
FIND_PACKAGE_HANDLE_STANDARD_ARGS(olm FOUND_VAR OLM_FOUND
REQUIRED_VARS OLM_EXECUTABLE
FAIL_MESSAGE "Error finding olm executable. variable OLM_LOCATION non set correctly.")
add_executable(license_generator::olm IMPORTED GLOBAL)
set_property(TARGET license_generator::olm PROPERTY IMPORTED_LOCATION ${OLM_EXECUTABLE})
ELSE(OLM_LOCATION)
find_package(olm REQUIRED NO_CMAKE_PATH) #try to find it without looping on this module
message(STATUS ${olm_FOUND})
IF(NOT olm_FOUND)
find_program(LCC_EXECUTABLE
NAMES ${lcc_names} HINTS ${LCC_LOCATION} DOC "lcc command line client")
FIND_PACKAGE_HANDLE_STANDARD_ARGS(lcc FOUND_VAR LCC_FOUND
REQUIRED_VARS LCC_EXECUTABLE
FAIL_MESSAGE "Error finding lcc executable. variable LCC_LOCATION non set correctly.")
add_executable(license_generator::lcc IMPORTED GLOBAL)
set_property(TARGET license_generator::lcc PROPERTY IMPORTED_LOCATION ${LCC_EXECUTABLE})
ELSE(LCC_LOCATION)
find_package(lcc HINTS ${CMAKE_BINARY_DIR} NO_CMAKE_PATH) #try to find it without looping on this module

IF(NOT lcc_FOUND)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
Expand All @@ -68,16 +68,17 @@ ELSE(OLM_LOCATION)
# execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
set(failure_messge "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
# if(NOT GIT_SUBMOD_RESULT EQUAL "0")
# set(failure_messge "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
# endif()
endif()
endif()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/license-generator/CMakeLists.txt")
set(failure_messge "All the options to find olm executable failed. And i can't compile one from source GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
set(failure_messge "All the options to find lcc executable failed. And i can't compile one from source GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/license-generator")
ENDIF(NOT olm_FOUND)
ENDIF(OLM_LOCATION)
ENDIF(NOT lcc_FOUND)
set(LCC_EXECUTABLE $<TARGET_FILE:license_generator::lcc>)
ENDIF(LCC_LOCATION)


1 change: 0 additions & 1 deletion extern/license-generator
Submodule license-generator deleted from 1c3043
1 change: 1 addition & 0 deletions extern/license-generator
9 changes: 8 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
add_subdirectory("library")



configure_file (
"templates/licensecc_properties_test.h.in"
"${CMAKE_BINARY_DIR}/licensecc_properties_test.h"
)
configure_file (
"templates/licensecc_properties.h.in"
"${LCC_INCLUDE_DIR}/licensecc_properties.h"
)
2 changes: 1 addition & 1 deletion src/library/LicenseReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#include <math.h>

#include <public_key.h>
#include <licensecc_properties.h>

#include "pc-identifiers.h"
#include "build_properties.h"
#include "LicenseReader.hpp"
#include "base/StringUtils.h"
#include "base/logger.h"
Expand Down
1 change: 1 addition & 0 deletions src/library/base/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#ifndef LOG_DISABLED
#include <errno.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/library/locate/EnvironmentVarData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "EnvironmentVarData.hpp"

#include <build_properties.h>
#include <licensecc_properties.h>
#include <cstdlib>
#include <regex>
#include <string>
Expand Down
Loading

0 comments on commit 5a8a12d

Please sign in to comment.