diff --git a/Dockerfile.dropshell-build b/Dockerfile.dropshell-build index 5a18f90..413f317 100644 --- a/Dockerfile.dropshell-build +++ b/Dockerfile.dropshell-build @@ -27,8 +27,8 @@ COPY . . # Configure and build with ccache RUN --mount=type=cache,target=/build \ - mkdir -p build_static && \ - cmake -G Ninja -B build_static \ + mkdir -p /build && \ + cmake -G Ninja -S /app -B /build \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ @@ -48,9 +48,15 @@ RUN --mount=type=cache,target=/build cmake --build /build --target run_prebuild_ RUN --mount=type=cache,target=/build cmake --build /build +# Copy the built executable to a regular directory for the final stage +RUN --mount=type=cache,target=/build mkdir -p /output && \ + find /build -type f -executable -name "*${PROJECT}*" -exec cp {} /output/${PROJECT} \; || \ + find /build -type f -executable -exec cp {} /output/${PROJECT} \; + # Final stage that only contains the binary -FROM scratch AS project +FROM alpine:latest AS project ARG PROJECT -COPY --from=builder /build/${PROJECT} /${PROJECT} +# Copy the actual binary from the regular directory +COPY --from=builder /output/ /output/ diff --git a/build.sh b/build.sh index 9a08616..1e76629 100755 --- a/build.sh +++ b/build.sh @@ -5,25 +5,6 @@ set -euo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" PROJECT="ipdemo" # Define your project name here -function update_sources() { - CMAKE_FILE="${SCRIPT_DIR}/${PROJECT}/CMakeLists.txt" - - # Generate the list of source files with relative paths - SOURCE_FILES=$(cd "${SCRIPT_DIR}/${PROJECT}" && find "src" -name '*.cpp' | sort | sed 's/^/ /') - - # Use awk to replace the SOURCES block in CMakeLists.txt - awk -v sources="$SOURCE_FILES" ' - BEGIN {in_sources=0} - /^set\(SOURCES/ {print; print sources; in_sources=1; next} - in_sources && /^\)/ {in_sources=0; print; next} - !in_sources {print} - ' "$CMAKE_FILE" > "${CMAKE_FILE}.tmp" && mv "${CMAKE_FILE}.tmp" "$CMAKE_FILE" - - echo "Updated SOURCES in ${CMAKE_FILE}" -} - -update_sources - mkdir -p "${SCRIPT_DIR}/output" export CMAKE_BUILD_TYPE="Debug" diff --git a/ipdemo/CMakeLists.txt b/ipdemo/CMakeLists.txt index 00210c2..0f4a180 100644 --- a/ipdemo/CMakeLists.txt +++ b/ipdemo/CMakeLists.txt @@ -52,9 +52,7 @@ add_custom_target(run_prebuild_script ALL WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) -set(SOURCES - src/main.cpp -) +file(GLOB_RECURSE SOURCES "src/*.cpp") # Mark sources as GENERATED to defer existence check until build time set_source_files_properties(${SOURCES} PROPERTIES GENERATED TRUE)