-
-
Save lynsei/eb85f678990e9679e7c8b1f988d5eb9c to your computer and use it in GitHub Desktop.
Modern C++ development with alpine linux, cmake, clang inside a docker container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set(CMAKE_C_COMPILER clang) | |
set(CMAKE_CXX_COMPILER clang++) | |
# TODO: Implement GetText and LibINTL so I can figure out the blocker on LynsLang. | |
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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