Skip to content

Commit a6f4797

Browse files
misc: add CMakeLists.txt
1 parent 1b02a8f commit a6f4797

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

.github/workflows/check_build.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build library
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
tests-build-linux:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
16+
17+
name: Build library with Python ${{ matrix.python-version }} on ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20+
21+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
22+
with:
23+
python-version: ${{ matrix.python-version }}-dev
24+
25+
- name: Install dependencies
26+
run: |
27+
sudo apt-get remove -qy man-db
28+
sudo apt-get update
29+
sudo apt-get install --no-install-recommends -qy gdb liblzma-dev
30+
sudo -E bash scripts/build_libunwind.sh
31+
32+
- name: Build shared object
33+
run: |
34+
mkdir cmake_build/
35+
cd cmake_build/
36+
cmake .. -DPython3_EXECUTABLE=$(which python)
37+
make -j$(nproc)
38+
39+
tests-build-macos:
40+
runs-on: macos-latest
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
45+
46+
name: Build library with Python ${{ matrix.python-version }} on macos-latest
47+
steps:
48+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
49+
50+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
51+
with:
52+
python-version: ${{ matrix.python-version }}-dev
53+
54+
- name: Build shared object
55+
run: |
56+
mkdir cmake_build/
57+
cd cmake_build/
58+
cmake .. -DPython3_EXECUTABLE=$(which python)
59+
make -j$(nproc)

CMakeLists.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(Echion LANGUAGES CXX)
3+
4+
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
5+
6+
set(CMAKE_REMOVE_ON_FAILURE OFF)
7+
set(CMAKE_CXX_STANDARD 17)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
10+
# Use glob to get all the source files
11+
file(GLOB_RECURSE SOURCE_FILES "echion/*.cc")
12+
13+
# Add source files
14+
add_library(echion SHARED ${SOURCE_FILES})
15+
target_include_directories(echion PUBLIC include)
16+
target_include_directories(echion PUBLIC ${CMAKE_HOME_DIRECTORY})
17+
18+
target_compile_options(echion PUBLIC -Werror -Wall -pedantic -Wold-style-cast)
19+
20+
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
21+
target_compile_definitions(echion PUBLIC PL_LINUX)
22+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
23+
target_compile_definitions(echion PUBLIC PL_DARWIN)
24+
else()
25+
message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}")
26+
endif()
27+
28+
include_directories(SYSTEM ${Python3_INCLUDE_DIRS})
29+
target_link_libraries(echion PUBLIC Python3::Python lzma)
30+
31+
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
32+
target_link_libraries(echion PUBLIC unwind)
33+
endif()
34+
35+
target_compile_options(echion PRIVATE -Wno-unused-function -Wno-unused-parameter -Wno-macro-redefined -Wno-reorder -Wextra -Wall)
36+
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
37+
target_compile_options(echion PRIVATE -Wno-changes-meaning)
38+
endif()

0 commit comments

Comments
 (0)