diff --git a/CMakelists.txt b/CMakelists.txt index 01a0e29..a3a7db8 100644 --- a/CMakelists.txt +++ b/CMakelists.txt @@ -10,6 +10,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) # 2. 配置项目 option(USE_DEMO "use demo application interface" ON) +set(VERSION "1.0") # 2. 配置文件 configure_file( @@ -38,3 +39,19 @@ add_executable(demo ${DIR_SRC}) # 1. 添加链接库 target_link_libraries(demo list) + +# 3. 配置安装路径 +set(CMAKE_INSTALL_PREFIX "./release") +install(TARGETS demo DESTINATION bin) +install (FILES "${PROJECT_BINARY_DIR}/config.h" + DESTINATION include) + +# 4. 启用测试 +enable_testing() +# 测试程序是否成功运行 +add_test (NAME test_demo COMMAND demo 1 2 3 5 8) + +# 5. 支持GDB +set(CMAKE_BUILD_TYPE "Debug") +set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") +set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall") diff --git a/config.h.in b/config.h.in index 58faf5d..458ea57 100644 --- a/config.h.in +++ b/config.h.in @@ -1 +1,2 @@ -#cmakedefine USE_DEMO \ No newline at end of file +#cmakedefine USE_DEMO +#cmakedefine VERSION "@VERSION@" \ No newline at end of file diff --git a/main.c b/main.c index 8d4948c..092b0e3 100644 --- a/main.c +++ b/main.c @@ -17,9 +17,19 @@ void list_demo(void) list_print(&list); } - -void main(int arg, char *argv[]) +int main(int argc, char *argv[]) { + printf("----- Version = %s -----\n", VERSION); + + if(argc != 1) + { + printf("# Program = [%s]\n", argv[0]); + for(uint32_t i = 1; i < argc; i++) + { + printf("# Param[%d] = %s\n", i ,argv[i]); + } + } + #ifndef USE_DEMO printf("list test!\n"); struct list_t list; diff --git a/mk.bat b/mk.bat index 9eb6d2a..8eee1f1 100644 --- a/mk.bat +++ b/mk.bat @@ -2,3 +2,5 @@ cmake . -G "MinGW Makefiles" -B build make -C build +make -C build install +make -C build test diff --git a/src/CMakelists.txt b/src/CMakelists.txt index 29f2e5a..405094d 100644 --- a/src/CMakelists.txt +++ b/src/CMakelists.txt @@ -4,3 +4,7 @@ aux_source_directory(. DIR_LIB_SRC) # 生成链接库 add_library(list ${DIR_LIB_SRC}) + +# 配置安装路径 +install (TARGETS list DESTINATION bin) +install (FILES list.h DESTINATION include)