diff --git a/CMakeLists.txt b/CMakeLists.txt index 33e5995..5335152 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -project(hmac_cpp LANGUAGES CXX) +project(hmac_cpp VERSION 0.1.0 LANGUAGES CXX) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) @@ -25,17 +25,38 @@ set(HMAC_HEADERS include/hmac_cpp/sha512.hpp ) -add_library(hmac STATIC ${HMAC_SOURCES}) -target_include_directories(hmac PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) +add_library(hmac_cpp STATIC ${HMAC_SOURCES}) +target_include_directories(hmac_cpp PUBLIC + $ + $ +) if(BUILD_EXAMPLE) add_executable(example example.cpp) - target_link_libraries(example PRIVATE hmac) + target_link_libraries(example PRIVATE hmac_cpp) target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) endif() -install(TARGETS hmac DESTINATION lib) +include(CMakePackageConfigHelpers) +install(TARGETS hmac_cpp EXPORT hmac_cppTargets DESTINATION lib) install(FILES ${HMAC_HEADERS} DESTINATION include/hmac_cpp) +install(EXPORT hmac_cppTargets NAMESPACE hmac_cpp:: DESTINATION lib/cmake/hmac_cpp) + +configure_package_config_file( + cmake/hmac_cppConfig.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/hmac_cppConfig.cmake" + INSTALL_DESTINATION lib/cmake/hmac_cpp +) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/hmac_cppConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/hmac_cppConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/hmac_cppConfigVersion.cmake" + DESTINATION lib/cmake/hmac_cpp +) if(BUILD_TESTS) enable_testing() @@ -46,7 +67,7 @@ if(BUILD_TESTS) ) FetchContent_MakeAvailable(googletest) add_executable(test_all test_all.cpp) - target_link_libraries(test_all PRIVATE hmac gtest_main) + target_link_libraries(test_all PRIVATE hmac_cpp gtest_main) target_include_directories(test_all PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) add_test(NAME test_all COMMAND test_all) endif() diff --git a/README.md b/README.md index 620c3c9..1114e5b 100644 --- a/README.md +++ b/README.md @@ -43,12 +43,19 @@ _install/ │ ├── sha1.hpp │ ├── sha256.hpp │ └── sha512.hpp -└── lib/ - └── libhmac.a + └── lib/ + └── libhmac_cpp.a ``` Predefined `.bat` scripts for MinGW builds are also available: `build_*.bat`. +After installation, the package can be found and linked in other projects using `find_package`: + +```cmake +find_package(hmac_cpp CONFIG REQUIRED) +target_link_libraries(my_app PRIVATE hmac_cpp::hmac_cpp) +``` + ## 📦 MQL5 Compatibility The repository includes `sha256.mqh`, `sha512.mqh`, `hmac.mqh`, and `hmac_utils.mqh` files, fully compatible with `MetaTrader 5`. diff --git a/cmake/hmac_cppConfig.cmake.in b/cmake/hmac_cppConfig.cmake.in new file mode 100644 index 0000000..644e5a6 --- /dev/null +++ b/cmake/hmac_cppConfig.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/hmac_cppTargets.cmake") + +check_required_components(hmac_cpp) diff --git a/cmake/hmac_cppConfigVersion.cmake.in b/cmake/hmac_cppConfigVersion.cmake.in new file mode 100644 index 0000000..d239389 --- /dev/null +++ b/cmake/hmac_cppConfigVersion.cmake.in @@ -0,0 +1 @@ +# hmac_cppConfigVersion.cmake is generated by write_basic_package_version_file