diff --git a/CMakeLists.tpl b/CMakeLists.tpl index a6d01be..3967c1d 100644 --- a/CMakeLists.tpl +++ b/CMakeLists.tpl @@ -6,6 +6,20 @@ add_compile_definitions(F_CPU=16000000) %build_flags% +# Capture the effective build-time flags for the -v/--version output. +string(TOUPPER "${CMAKE_BUILD_TYPE}" _sim_build_type) +if(_sim_build_type STREQUAL "") + set(SIM_BUILD_TYPE "None") +else() + set(SIM_BUILD_TYPE "${CMAKE_BUILD_TYPE}") +endif() +string(STRIP "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_sim_build_type}}" SIM_C_FLAGS) +configure_file( + ${CMAKE_CURRENT_LIST_DIR}/../src/build_info.h.in + ${CMAKE_CURRENT_BINARY_DIR}/build_info.h + @ONLY +) + include(../src/grbl/CMakeLists.txt) if (WIN32) @@ -53,13 +67,16 @@ add_executable(grblHAL_sim ${platform_SRC} ) -target_link_libraries(grblHAL_sim PRIVATE +target_link_libraries(grblHAL_sim PRIVATE m grbl ${platform_LIB} ) -add_executable(grblHAL_validator +# Generated build_info.h lands in the build dir. +target_include_directories(grblHAL_sim PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + +add_executable(grblHAL_validator ../src/eeprom.c ../src/grbl_eeprom_extensions.c ../src/validator.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d1c19e9..f54e2e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,20 @@ project(grblHAL-sim C) add_compile_definitions(F_CPU=16000000) #add_compile_definitions(SQUARING_ENABLED=1) +# Capture the effective build-time flags for the -v/--version output. +string(TOUPPER "${CMAKE_BUILD_TYPE}" _sim_build_type) +if(_sim_build_type STREQUAL "") + set(SIM_BUILD_TYPE "None") +else() + set(SIM_BUILD_TYPE "${CMAKE_BUILD_TYPE}") +endif() +string(STRIP "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_sim_build_type}}" SIM_C_FLAGS) +configure_file( + ${CMAKE_CURRENT_LIST_DIR}/src/build_info.h.in + ${CMAKE_CURRENT_BINARY_DIR}/build_info.h + @ONLY +) + include(src/grbl/CMakeLists.txt) if (WIN32) @@ -51,13 +65,16 @@ add_executable(grblHAL_sim ${platform_SRC} ) -target_link_libraries(grblHAL_sim PRIVATE +target_link_libraries(grblHAL_sim PRIVATE m grbl ${platform_LIB} ) -add_executable(grblHAL_validator +# Generated build_info.h lands in the build dir. +target_include_directories(grblHAL_sim PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + +add_executable(grblHAL_validator src/eeprom.c src/grbl_eeprom_extensions.c src/validator.c diff --git a/src/build_info.h.in b/src/build_info.h.in new file mode 100644 index 0000000..0b8303e --- /dev/null +++ b/src/build_info.h.in @@ -0,0 +1,10 @@ +/* Generated by CMake from build_info.h.in - do not edit directly. */ +#ifndef _BUILD_INFO_H_ +#define _BUILD_INFO_H_ + +#define SIM_BUILD_TYPE "@SIM_BUILD_TYPE@" +#define SIM_C_FLAGS "@SIM_C_FLAGS@" +#define SIM_COMPILER "@CMAKE_C_COMPILER_ID@ @CMAKE_C_COMPILER_VERSION@" +#define SIM_TARGET "@CMAKE_SYSTEM_NAME@ @CMAKE_SYSTEM_PROCESSOR@" + +#endif diff --git a/src/main.c b/src/main.c index 38224ee..196512d 100644 --- a/src/main.c +++ b/src/main.c @@ -40,6 +40,7 @@ #include "simulator.h" #include "eeprom.h" #include "grbl_interface.h" +#include "build_info.h" #include "grbl/grbllib.h" @@ -70,6 +71,7 @@ void print_usage(const char* badarg) " -p : port to open raw telnet communication.\n" " -c : character to print before each line from grbl. default = '#'\n" " -n : no comments before grbl response lines.\n" + " -v : print version and build information.\n" " -h : this help.\n" "\n" " and can be specifed with option flags or positional parameters\n" @@ -79,6 +81,21 @@ void print_usage(const char* badarg) progname); } +void print_version(void) +{ + printf("grblHAL simulator\n" + " Build type : %s\n" + " Compiler : %s\n" + " Target : %s\n" + " C flags : %s\n" + " Built : %s %s\n", + SIM_BUILD_TYPE, + SIM_COMPILER, + SIM_TARGET, + SIM_C_FLAGS[0] ? SIM_C_FLAGS : "(none)", + __DATE__, __TIME__); +} + //wrapper for thread interface PLAT_THREAD_FUNC(grbl_main_thread, exit) { @@ -199,6 +216,11 @@ int main(int argc, char *argv[]) argv++; argc--; if (argv[0][0] == '-') { + if (!strcmp(argv[0], "--version")) { + print_version(); + return EXIT_SUCCESS; + } + switch(argv[0][1]){ case 'c': //set Comment char @@ -259,6 +281,10 @@ int main(int argc, char *argv[]) args.port = atoi(*argv); break; + case 'v': + print_version(); + return EXIT_SUCCESS; + case 'h': print_usage(NULL); return EXIT_SUCCESS;