diff --git a/.gitignore b/.gitignore index 6f580d6..29c5803 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vscode/* build/* +debug/* UserDir/* CMakeCache.txt \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index fe4098a..0ffa45d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,9 @@ add_subdirectory(${INCLUDES}/tomlc17) add_subdirectory(src/utils) include(cmake/JuiceModule.cmake) +include(cmake/BuildVersion.cmake) + +build_version() # modules add_juice_module(agent) diff --git a/CMakePresets.json b/CMakePresets.json index dff1689..017f4e8 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -6,7 +6,16 @@ "generator": "Ninja", "binaryDir": "${sourceDir}/build", "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" + "CMAKE_BUILD_TYPE": "Release", + "RELEASE_BUILD": "ON" + } + }, + { + "name": "ninja-debug", + "generator": "Ninja", + "binaryDir": "${sourceDir}/debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" } } ] diff --git a/README.md b/README.md index 9e08ab5..1976ffe 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ If the injection is successful, EntryClass .EntryMethod() of will - Java 8+ - MinGW - CMake +- Ninja ``` git clone https://github.com/xiaozhou233/JuiceAgent.git cd JuiceAgent diff --git a/cmake/BuildVersion.cmake b/cmake/BuildVersion.cmake new file mode 100644 index 0000000..413d397 --- /dev/null +++ b/cmake/BuildVersion.cmake @@ -0,0 +1,36 @@ +# BuildVersion.cmake +# function to get and set the build version + +function(build_version) + set(VERSION_FILE "${CMAKE_SOURCE_DIR}/version.txt") + + file(READ "${VERSION_FILE}" VERSION_CONTENT) + + # VERSION_MAJOR + string(REGEX MATCH "VERSION_MAJOR=([0-9]+)" _ ${VERSION_CONTENT}) + set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1}) + # VERSION_MINOR + string(REGEX MATCH "VERSION_MINOR=([0-9]+)" _ ${VERSION_CONTENT}) + set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_1}) + # BUILD_NUMBER + string(REGEX MATCH "BUILD_NUMBER=([0-9]+)" _ ${VERSION_CONTENT}) + set(PROJECT_BUILD_NUMBER ${CMAKE_MATCH_1}) + if(RELEASE_BUILD) + math(EXPR PROJECT_BUILD_NUMBER "${PROJECT_BUILD_NUMBER} + 1") + file(WRITE "${VERSION_FILE}" + "VERSION_MAJOR=${PROJECT_VERSION_MAJOR}\n" + "VERSION_MINOR=${PROJECT_VERSION_MINOR}\n" + "BUILD_NUMBER=${PROJECT_BUILD_NUMBER}\n" + ) + endif() + + set(PROJECT_VERSION_STRING "v${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}-b${PROJECT_BUILD_NUMBER}") + + message(STATUS "Build version: ${PROJECT_VERSION_STRING}") + + add_compile_definitions( + PROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR} + PROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR} + PROJECT_BUILD_NUMBER=${PROJECT_BUILD_NUMBER} + PROJECT_VERSION_STRING=\"${PROJECT_VERSION_STRING}\") +endfunction() \ No newline at end of file diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..65e0c4e --- /dev/null +++ b/version.txt @@ -0,0 +1,3 @@ +VERSION_MAJOR=1 +VERSION_MINOR=0 +BUILD_NUMBER=19