feat: handling include folder
This commit is contained in:
@@ -15,7 +15,7 @@ option(DO_NOT_INCREASE_VERSION "Disable custom target that automatically increas
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||
include(CheckCompileOptions)
|
||||
include(FetchZlog)
|
||||
include(FetchArgparse)
|
||||
include(FetchCargs)
|
||||
|
||||
if(BUILD_TESTS)
|
||||
enable_testing()
|
||||
@@ -33,15 +33,28 @@ if(BUILD_DOCS)
|
||||
add_subdirectory(docs)
|
||||
endif()
|
||||
|
||||
add_executable(${PROJECT_NAME} src/main.c)
|
||||
set_target_properties(
|
||||
${PROJECT_NAME}
|
||||
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||
|
||||
if(NOT DO_NOT_INCREASE_VERSION)
|
||||
add_custom_target(
|
||||
run_versioning_script
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "$$(date +%s)" > "${CMAKE_CURRENT_BINARY_DIR}/update_versioning_signal"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "$(date +%s)" > "${CMAKE_CURRENT_BINARY_DIR}/update_versioning_signal"
|
||||
COMMAND ${PROJECT_SOURCE_DIR}/scripts/versioning.sh patch
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
COMMENT "Running versioning script")
|
||||
add_dependencies(${PROJECT_NAME} run_versioning_script)
|
||||
endif()
|
||||
|
||||
execute_process(COMMAND ${PROJECT_SOURCE_DIR}/scripts/versioning.sh print WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE ${PROJECT_NAME}_VERSION)
|
||||
|
||||
message(STATUS "Building [${PROJECT_NAME}] version ${${PROJECT_NAME}_VERSION}")
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE "${COMPILE_FLAGS}")
|
||||
target_link_options(${PROJECT_NAME} PRIVATE "${LINK_FLAGS}")
|
||||
|
||||
add_subdirectory(include)
|
||||
add_subdirectory(src)
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
include(FetchContent)
|
||||
|
||||
option(STATIC_ARGPARSE "Statically build and link argparse" ON)
|
||||
|
||||
if(NOT ARGPARSE_VERSION)
|
||||
set(ARGPARSE_VERSION "682d4520b4bc2b646cdfcf078b2fed00b3d2da30")
|
||||
endif()
|
||||
message(STATUS "Fetching and configuring argparse version ${ARGPARSE_VERSION}")
|
||||
|
||||
set(FETCHCONTENT_QUIET TRUE)
|
||||
if(STATIC_ARGPARSE)
|
||||
set(ARGPARSE_STATIC ON CACHE STRING "" FORCE)
|
||||
set(ARGPARSE_SHARED OFF CACHE STRING "" FORCE)
|
||||
else()
|
||||
set(ARGPARSE_STATIC OFF CACHE STRING "" FORCE)
|
||||
set(ARGPARSE_SHARED ON CACHE STRING "" FORCE)
|
||||
endif()
|
||||
|
||||
FetchContent_Declare(
|
||||
argparse
|
||||
GIT_REPOSITORY https://github.com/cofyc/argparse.git
|
||||
GIT_TAG ${ARGPARSE_VERSION}
|
||||
GIT_PROGRESS TRUE
|
||||
OVERRIDE_FIND_PACKAGE)
|
||||
FetchContent_MakeAvailable(argparse)
|
||||
|
||||
if(TARGET argparse_shared)
|
||||
target_compile_options(argparse_shared PRIVATE ${COMPILE_FLAGS})
|
||||
target_link_options(argparse_shared PRIVATE "${LINK_FLAGS}")
|
||||
endif()
|
||||
|
||||
if(TARGET argparse_static)
|
||||
target_compile_options(argparse_static PRIVATE ${COMPILE_FLAGS})
|
||||
target_link_options(argparse_static PRIVATE "${LINK_FLAGS}")
|
||||
endif()
|
||||
20
cmake/FetchCargs.cmake
Normal file
20
cmake/FetchCargs.cmake
Normal file
@@ -0,0 +1,20 @@
|
||||
include(FetchContent)
|
||||
|
||||
set(FETCHCONTENT_QUIET TRUE)
|
||||
set(ENABLE_COVERAGE FALSE)
|
||||
set(ENABLE_SANITIZER FALSE)
|
||||
set(ENABLE_TESTS FALSE)
|
||||
set(ENABLE_DEMO FALSE)
|
||||
|
||||
FetchContent_Declare(
|
||||
cargs
|
||||
GIT_REPOSITORY https://github.com/likle/cargs.git
|
||||
GIT_TAG v1.2.0
|
||||
GIT_PROGRESS TRUE
|
||||
OVERRIDE_FIND_PACKAGE)
|
||||
FetchContent_MakeAvailable(cargs)
|
||||
|
||||
if(TARGET cargs)
|
||||
target_compile_options(cargs PRIVATE "-fPIE")
|
||||
target_link_options(cargs PRIVATE "-pie")
|
||||
endif()
|
||||
@@ -4,9 +4,9 @@ FetchContent_Declare(
|
||||
zlog
|
||||
GIT_REPOSITORY https://github.com/HardySimpson/zlog
|
||||
GIT_TAG 1.2.18
|
||||
GIT_SHALLOW TRUE
|
||||
# This patch fixes leak: https://github.com/HardySimpson/zlog/issues/256
|
||||
PATCH_COMMAND git fetch origin pull/285/head:pr285 && git merge pr285)
|
||||
GIT_SHALLOW TRUE)
|
||||
# # This patch fixes leak: https://github.com/HardySimpson/zlog/issues/256
|
||||
# PATCH_COMMAND git fetch origin pull/285/head:pr285 && git merge pr285)
|
||||
FetchContent_MakeAvailable(zlog)
|
||||
target_compile_options(zlog PRIVATE "-fPIC")
|
||||
target_compile_options(zlog_s PRIVATE "-fPIE")
|
||||
|
||||
4
include/CMakeLists.txt
Normal file
4
include/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
file(GLOB H_FILES CONFIGURE_DEPENDS *.h)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_sources(${PROJECT_NAME} PUBLIC ${H_FILES})
|
||||
16
include/version.h
Normal file
16
include/version.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef INCLUDE_C_TEMPLATE_VERSION_H_
|
||||
#define INCLUDE_C_TEMPLATE_VERSION_H_
|
||||
|
||||
#define STRINGIFY(x) #x
|
||||
#define TOSTRING(x) STRINGIFY(x)
|
||||
|
||||
#define C_TEMPLATE_VERSION \
|
||||
TOSTRING(C_TEMPLATE_VERSION_MAJOR) "." TOSTRING(C_TEMPLATE_VERSION_MINOR) "." TOSTRING(C_TEMPLATE_VERSION_PATCH)
|
||||
|
||||
#define C_TEMPLATE_VERSION_MAJOR 0
|
||||
#define C_TEMPLATE_VERSION_MINOR 0
|
||||
#define C_TEMPLATE_VERSION_PATCH 4
|
||||
#define C_TEMPLATE_COMMIT_HASH "cda7a68e0ed8662c354fd4cbd80850d232706475"
|
||||
#define C_TEMPLATE_BUILD_TIMESTAMP 1754406240
|
||||
|
||||
#endif // INCLUDE_C_TEMPLATE_VERSION_H_
|
||||
0
scripts/versioning.sh
Normal file → Executable file
0
scripts/versioning.sh
Normal file → Executable file
@@ -1,19 +1,7 @@
|
||||
add_executable(c-template main.c)
|
||||
set_target_properties(
|
||||
c-template PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||
|
||||
execute_process(COMMAND ${PROJECT_SOURCE_DIR}/scripts/versioning.sh print WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE MULTIPERF_VERSION)
|
||||
|
||||
message(STATUS "Building [${PROJECT_NAME}] version ${MULTIPERF_VERSION}")
|
||||
target_compile_options(multiperf PRIVATE "${COMPILE_FLAGS}")
|
||||
target_link_options(multiperf PRIVATE "${LINK_FLAGS}")
|
||||
|
||||
file(GLOB C_FILES CONFIGURE_DEPENDS *.c)
|
||||
file(GLOB H_FILES CONFIGURE_DEPENDS *.h)
|
||||
|
||||
target_sources(c-template PRIVATE ${C_FILES} PUBLIC ${H_FILES})
|
||||
target_include_directories(c-template PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_sources(${PROJECT_NAME} PRIVATE ${C_FILES} PUBLIC ${H_FILES})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_link_libraries(c-template cargs zlog_s)
|
||||
target_link_libraries(${PROJECT_NAME} cargs zlog_s)
|
||||
|
||||
34
src/main.c
34
src/main.c
@@ -1,6 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include "version.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define UNUSED(x) UNUSED_##x __attribute__((__unused__))
|
||||
#else
|
||||
#define UNUSED(x) UNUSED_##x
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_##x
|
||||
#else
|
||||
#define UNUSED_FUNCTION(x) UNUSED_##x
|
||||
#endif
|
||||
|
||||
#define MAX_ISO8601_STR_SIZE 32
|
||||
|
||||
static void timestamp_to_iso8601(time_t timestamp, char *output, size_t size) {
|
||||
struct tm time_info;
|
||||
localtime_r(×tamp, &time_info);
|
||||
strftime(output, size, "%Y-%m-%dT%H:%M:%S%z", &time_info);
|
||||
}
|
||||
|
||||
static void print_version() {
|
||||
fprintf(stdout, "c-template version %s\n", C_TEMPLATE_VERSION);
|
||||
fflush(stdout);
|
||||
|
||||
char iso8601[MAX_ISO8601_STR_SIZE];
|
||||
timestamp_to_iso8601(C_TEMPLATE_BUILD_TIMESTAMP, iso8601, sizeof(iso8601));
|
||||
fprintf(stdout, "built on %s from commit %s\n", iso8601, C_TEMPLATE_COMMIT_HASH);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
print_version();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user