diff --git a/CMakeLists.txt b/CMakeLists.txt index c1c5a35..892d420 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,15 +52,13 @@ target_link_libraries(${APP_NAME} ${CMAKE_SOURCE_DIR}/third_party/lib/libpaho-mqtt3c.a ) -# 拷贝配置文件 +# 拷贝配置文件(仅在不存在时) add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND sh -c - "if [ ! -f \"$/${CONFIG_FILE}\" ]; then \ - mkdir -p \"$\" && \ - cp \"${CMAKE_SOURCE_DIR}/${CONFIG_EXAMPLE_FILE}\" \ - \"$/${CONFIG_FILE}\" && \ - echo \"config.json created from example\"; \ - else \ - echo \"config.json exists, keep it\"; \ - fi" + "test -f \"$/${CONFIG_FILE}\" || \ + (mkdir -p \"$\" && \ + cp \"${CMAKE_SOURCE_DIR}/${CONFIG_EXAMPLE_FILE}\" \ + \"$/${CONFIG_FILE}\" && \ + echo \"config.json created from example\")" ) +