Skip to content

Instantly share code, notes, and snippets.

@mikilian
Created June 29, 2021 21:27
Show Gist options
  • Save mikilian/d92f9cd22803b9c61725c86391618615 to your computer and use it in GitHub Desktop.
Save mikilian/d92f9cd22803b9c61725c86391618615 to your computer and use it in GitHub Desktop.
Modern C++ development with alpine linux, cmake, clang inside a docker container
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
cmake_minimum_required(VERSION 3.18)
set(APP_NAME "example-app")
project("${APP_NAME}")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++20 -Wno-multichar")
include_directories(
"${PROJECT_SOURCE_DIR}/include"
)
file(
GLOB
SOURCES
"src/**/*.cpp"
"src/*.cpp"
)
set(
PROJECT_LINK_LIBS
pthread
dl
)
add_executable("${APP_NAME}" ${SOURCES})
target_link_libraries("${APP_NAME}" ${PROJECT_LINK_LIBS})
version: '3.7'
services:
dev:
build: .
environment:
APP_NAME: example-app
APP_EXEC: 1
volumes:
- ./include:/code/include
- ./src:/code/src
- ./CMakeLists.txt:/code/CMakeLists.txt
FROM alpine:latest
RUN apk update \
&& apk upgrade \
&& apk add --no-cache \
clang \
clang-dev \
alpine-sdk \
dpkg \
cmake \
ccache \
python3
RUN ln -sf /usr/bin/clang /usr/bin/cc \
&& ln -sf /usr/bin/clang++ /usr/bin/c++ \
&& update-alternatives --install /usr/bin/cc cc /usr/bin/clang 10\
&& update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 10\
&& update-alternatives --auto cc \
&& update-alternatives --auto c++ \
&& update-alternatives --display cc \
&& update-alternatives --display c++ \
&& ls -l /usr/bin/cc /usr/bin/c++ \
&& cc --version \
&& c++ --version
WORKDIR /code
ENV APP_NAME=''
ENTRYPOINT ["/code/entrypoint.sh"]
#!/usr/bin/env sh
if test -d "build"; then
rm -rf build;
fi
mkdir -p build
cd build
cmake ..
make -j20
if [ "${APP_EXEC}" -eq "1" ]; then
./$APP_NAME
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment