From a26bd812ef3fd21dd3d68bd10704ae3dd8eeea6b Mon Sep 17 00:00:00 2001 From: Gabriele Contini <contini.mailing@gmail.com> Date: 周日, 10 11月 2019 22:25:22 +0800 Subject: [PATCH] improvements for issue #42 --- src/templates/public_key.inja | 2 ++ .gitignore | 4 ++-- projects/.gitkeep | 0 src/library/LicenseReader.cpp | 6 +++--- .travis.yml | 2 +- cmake/Findolm.cmake | 1 + src/library/os/os.c | 2 +- CMakeLists.txt | 36 +++++++++++++++++++++++------------- src/library/locate/ApplicationFolder.cpp | 2 +- src/library/base/CMakeLists.txt | 2 +- 10 files changed, 35 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 469799c..6f0748c 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,6 @@ *.out /Default/ -product/* -!product/.gitkeep +projects/* +!projects/.gitkeep diff --git a/.travis.yml b/.travis.yml index 8c0456d..53a3cba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,7 +104,7 @@ - ./bootstrap.sh - travis_wait 30 ./b2 toolset=gcc-mingw target-os=windows address-model=64 --with-date_time --with-test --with-filesystem --with-program_options --with-regex --with-serialization --with-system runtime-link=static --prefix=./dist release install - cd .. - - cmake -DCMAKE_TOOLCHAIN_FILE=../modules/toolchain-ubuntu-mingw64.cmake -DCMAKE_INSTALL_PREFIX=../../install -DBOOST_ROOT=$PWD/boost_1_71_0/dist .. + - cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain-ubuntu-mingw64.cmake -DCMAKE_INSTALL_PREFIX=../../install -DBOOST_ROOT=$PWD/boost_1_71_0/dist .. - os: windows name: "Widnows server 1803 - Visual Studio 15 2017 Win64 - (/MD)" before_script: diff --git a/CMakeLists.txt b/CMakeLists.txt index 509c4a8..0ab019a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,16 +11,16 @@ SET(CMAKE_DISABLE_SOURCE_CHANGES OFF) #keys are generated in the source tree by default SET(CMAKE_DISABLE_IN_SOURCE_BUILD ON) -IF(NOT LCC_PRODUCT_NAME) - message(WARNING "You should define a variable LCC_PRODUCT_NAME containing the name of the software you want to add a license to." +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_PRODUCT_NAME "DEFAULT") -ENDIF(NOT LCC_PRODUCT_NAME) + set(LCC_PROJECT_NAME "DEFAULT") +ENDIF(NOT LCC_PROJECT_NAME) -#base folder where product names are stored (/projects) -IF(NOT LCC_PRODUCTS_BASE_DIR) - set(LCC_PRODUCTS_BASE_DIR "${CMAKE_SOURCE_DIR}/product") -ENDIF(NOT LCC_PRODUCTS_BASE_DIR) +#base folder where projects are stored (/projects) +IF(NOT LCC_PROJECTS_BASE_DIR) + set(LCC_PROJECTS_BASE_DIR "${CMAKE_SOURCE_DIR}/projects") +ENDIF(NOT LCC_PROJECTS_BASE_DIR) project (licensecc C CXX ) SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) @@ -30,17 +30,24 @@ find_package(olm REQUIRED) #load the current project from files or find it from environment variables or create a default one -set(LCC_PROJECT_PUBLIC_KEY "${LCC_PRODUCTS_BASE_DIR}/${LCC_PRODUCT_NAME}/include/${PROJECT_NAME}/${LCC_PRODUCT_NAME}/public_key.h" ) -set(LCC_PROJECT_PRIVATE_KEY "${LCC_PRODUCTS_BASE_DIR}/${LCC_PRODUCT_NAME}/private_key.rsa" ) +set(LCC_INCLUDE_DIR "${LCC_PROJECTS_BASE_DIR}/${LCC_PROJECT_NAME}/include/${PROJECT_NAME}/${LCC_PROJECT_NAME}" ) +set(LCC_PROJECT_PUBLIC_KEY "${LCC_INCLUDE_DIR}/public_key.h" ) +set(LCC_PROJECT_PRIVATE_KEY "${LCC_PROJECTS_BASE_DIR}/${LCC_PROJECT_NAME}/private_key.rsa" ) add_custom_command( OUTPUT "${LCC_PROJECT_PUBLIC_KEY}" "${LCC_PROJECT_PRIVATE_KEY}" - COMMAND license_generator::olm project initialize -s "${PROJECT_SOURCE_DIR}" -n "${LCC_PRODUCT_NAME}" -p "${LCC_PRODUCTS_BASE_DIR}" + COMMAND license_generator::olm project initialize -s "${PROJECT_SOURCE_DIR}/src" -n "${LCC_PROJECT_NAME}" -p "${LCC_PROJECTS_BASE_DIR}" COMMENT "generating ${LCC_PROJECT_PUBLIC_KEY}" USES_TERMINAL ) -add_custom_target(product_initialize DEPENDS "${LCC_PROJECT_PUBLIC_KEY}" "${LCC_PROJECT_PRIVATE_KEY}") +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} ) message( STATUS "C compiler : " ${CMAKE_C_COMPILER}) message( STATUS "C compiler flags : " ${CMAKE_C_FLAGS}) @@ -52,7 +59,8 @@ message( STATUS "Build type : " ${CMAKE_BUILD_TYPE}) endif(CMAKE_BUILD_TYPE) message( STATUS "Install prefix : " ${CMAKE_INSTALL_PREFIX}) -message( STATUS "olm executable : " ${OLM_VERSION}) +message( STATUS "Project name : " ${LCC_PROJECT_NAME} ) +message( STATUS "Project base dir : " ${LCC_PROJECTS_BASE_DIR}/${LCC_PROJECT_NAME} ) #boost is required only for tests #bug in cmake win32 - can't find boost compiled with mingw @@ -70,6 +78,7 @@ 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>) @@ -81,6 +90,7 @@ MARK_AS_ADVANCED(BUILDNAME) 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) ENDIF(BUILD_TESTING) ELSE(Boost_FOUND) diff --git a/cmake/Findolm.cmake b/cmake/Findolm.cmake index 87b35e7..7e5157b 100644 --- a/cmake/Findolm.cmake +++ b/cmake/Findolm.cmake @@ -57,6 +57,7 @@ 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_package(Git QUIET) if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") diff --git a/product/.gitkeep b/projects/.gitkeep similarity index 100% rename from product/.gitkeep rename to projects/.gitkeep diff --git a/src/library/LicenseReader.cpp b/src/library/LicenseReader.cpp index 84de09d..5ae8390 100644 --- a/src/library/LicenseReader.cpp +++ b/src/library/LicenseReader.cpp @@ -22,9 +22,10 @@ #include <stdlib.h> #include <math.h> +#include <public_key.h> + #include "pc-identifiers.h" #include "build_properties.h" -#include "public-key.h" #include "LicenseReader.hpp" #include "base/StringUtils.h" #include "base/logger.h" @@ -207,8 +208,7 @@ string FullLicenseInfo::printForSign() const { ostringstream oss; oss << toupper_copy(trim_copy(this->product)); - oss << SHARED_RANDOM - ; + //oss << SHARED_RANDOM; if (has_client_sig) { oss << trim_copy(this->client_signature); } diff --git a/src/library/base/CMakeLists.txt b/src/library/base/CMakeLists.txt index 0ca6e50..deab8b0 100644 --- a/src/library/base/CMakeLists.txt +++ b/src/library/base/CMakeLists.txt @@ -6,6 +6,6 @@ base64.c ) -add_dependencies( base product_initialize ) +add_dependencies( base project_initialize ) install(TARGETS base ARCHIVE DESTINATION lib) diff --git a/src/library/locate/ApplicationFolder.cpp b/src/library/locate/ApplicationFolder.cpp index b1fb0e3..e6a7446 100644 --- a/src/library/locate/ApplicationFolder.cpp +++ b/src/library/locate/ApplicationFolder.cpp @@ -8,7 +8,7 @@ #include <sstream> #include <string> -#include <build_properties.h> +//B#include <build_properties.h> #include "../base/logger.h" #include "../api/datatypes.h" diff --git a/src/library/os/os.c b/src/library/os/os.c index ad4803b..d38c68a 100644 --- a/src/library/os/os.c +++ b/src/library/os/os.c @@ -1,6 +1,6 @@ #include "os.h" #include "../base/logger.h" -#include "public-key.h" +#include <public_key.h> #include <stdio.h> #ifdef __linux__ diff --git a/src/templates/public_key.inja b/src/templates/public_key.inja new file mode 100644 index 0000000..19f4d42 --- /dev/null +++ b/src/templates/public_key.inja @@ -0,0 +1,2 @@ +#define PRODUCT_NAME {{ product_name }} +#define PUBLIC_KEY {1,2,3} \ No newline at end of file -- Gitblit v1.9.1