Browse Source

build: git describe tag as version info

dev
Dnomd343 2 years ago
parent
commit
c6f1fd25f0
  1. 4
      .gitignore
  2. 43
      CMakeLists.txt
  3. 4
      include/constant.h.in
  4. 5
      src/CMakeLists.txt
  5. 1
      src/cleardns.c
  6. 2
      src/common/sundry.c

4
.gitignore

@ -1,7 +1,9 @@
/bin/
/.idea/
/assets/*.txt
/src/target/
/cmake-build/
/cmake-build-debug/
/cmake-build-release/
/assets/*.txt
/include/constant.h

43
CMakeLists.txt

@ -1,6 +1,45 @@
cmake_minimum_required(VERSION 2.8.12)
project(cleardns)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
project(cleardns LANGUAGES C)
set(CMAKE_C_STANDARD 99)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
###############################################################
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if(NOT CMAKE_EXE_LINKER_FLAGS)
set(CMAKE_EXE_LINKER_FLAGS -static)
endif()
###############################################################
macro(git_tag _tag)
find_package(Git QUIET)
if (GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags
OUTPUT_VARIABLE ${_tag}
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
endif()
endmacro()
set(VERSION "")
git_tag(VERSION)
if(VERSION STREQUAL "") # without git tag
message(FATAL_ERROR "Git command not found")
endif()
###############################################################
add_subdirectory(src)
###############################################################

4
include/constant.h → include/constant.h.in

@ -13,9 +13,7 @@
#define RESTART_DELAY 1
#define DIVERTER_TIMEOUT 6
// TODO: using CMAKE template
#define VERSION "1.3.3"
#define VERSION "@VERSION@"
#define CONFIG_FILE "cleardns.yml"
#define DNSPROXY_BIN "dnsproxy"

5
src/CMakeLists.txt

@ -9,6 +9,11 @@ include_directories(${PROJECT_SOURCE_DIR}/include/loader)
link_directories(${PROJECT_SOURCE_DIR}/src/target/release)
configure_file(
${PROJECT_SOURCE_DIR}/include/constant.h.in
${PROJECT_SOURCE_DIR}/include/constant.h
)
add_subdirectory(utils)
add_subdirectory(applet)
add_subdirectory(bcrypt)

1
src/cleardns.c

@ -5,7 +5,6 @@
#include <sys/wait.h>
#include "loader.h"
#include "logger.h"
#include "sundry.h"
#include "system.h"
#include "assets.h"
#include "adguard.h"

2
src/common/sundry.c

@ -49,7 +49,7 @@ void uint32_list_debug(char *describe, uint32_t **uint32_list) { // show uint32
}
uint8_t check_port(uint16_t port) { // whether port is valid
if (port > 0 && port <= 65535) { // 1 ~ 65535
if (port > 0) { // 1 ~ 65535 (uint16_t <= 65535)
return TRUE;
}
return FALSE;

Loading…
Cancel
Save