Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to cmake cppfront delivery #7

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3a22ed9
reuse cmake - cppfront script project
SavenkovIgor Jul 11, 2024
283dc2c
chore: Update Conan package manager to version 2.5.0
SavenkovIgor Jul 11, 2024
4ebf806
chore: Update default Conan profile to use Clang 18 and C++23
SavenkovIgor Jul 11, 2024
bd1deaa
chore: Update default Conan profile to use Clang 18 and libc++11
SavenkovIgor Jul 11, 2024
1cfdbba
chore: Update default Conan profile to use Clang 18 and libc++
SavenkovIgor Jul 11, 2024
a5c431a
chore: Update default Conan profile to use Clang 18 and libc++
SavenkovIgor Jul 11, 2024
3433de2
chore: Update alternatives for c++
SavenkovIgor Jul 11, 2024
d231f34
chore: Update default Conan profile to use Ninja generator
SavenkovIgor Jul 11, 2024
a41dcc7
Add print version step
SavenkovIgor Jul 13, 2024
05d3064
Update default Conan profile to use Clang 18 and libc++
SavenkovIgor Jul 13, 2024
7549d4b
Add pull request condition
SavenkovIgor Jul 13, 2024
3486f9b
chore: Update Build.yml to install libc++ and libc++abi
SavenkovIgor Jul 13, 2024
abd8134
chore: Update CMakeLists.txt to display C and C++ compilers
SavenkovIgor Jul 13, 2024
c076698
chore: Update alternatives for c
SavenkovIgor Jul 13, 2024
430b493
chore: Update Build.yml to install libc++ and libc++abi
SavenkovIgor Jul 13, 2024
a68111a
chore: Set environment variables for Clang in Build.yml
SavenkovIgor Jul 13, 2024
b8e0200
chore: Update Build.yml to set environment variables for Clang and in…
SavenkovIgor Jul 13, 2024
a0f03aa
chore: Install clang-tools in Build.yml
SavenkovIgor Jul 13, 2024
d2070e4
chore: Comment out unused environment variables in Build.yml
SavenkovIgor Jul 13, 2024
3487d8f
chore: Update Build.yml to enable Clang environment variables and ins…
SavenkovIgor Jul 13, 2024
9b58157
+
SavenkovIgor Jul 13, 2024
dcec20c
chore: Update Build.yml to enable Clang environment variables and ins…
SavenkovIgor Jul 13, 2024
8634e4b
chore: Update Build.yml to use Clang 18 and install libc++ and libc++abi
SavenkovIgor Jul 13, 2024
db37274
chore: Update Build.yml to remove clang-14, install Clang, and update…
SavenkovIgor Jul 13, 2024
8f76c31
chore: Update Build.yml to remove unused environment variables, enabl…
SavenkovIgor Jul 13, 2024
0c5fdf6
chore: Update project build command to include Conan profiles
SavenkovIgor Jul 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,60 @@
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CLANG_VERSION: 18
# CXX: clang++-18
# CC: clang-18
# CXXFLAGS: "-stdlib=libc++ -I/usr/include/c++/v1"
# LDFLAGS: "-L/usr/lib"

jobs:
build:
timeout-minutes: 30

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Completely remove clang-14
run: |
sudo apt remove -y clang-14 clang-tools-14
sudo apt autoremove -y

- name: Install Clang
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh ${{ env.CLANG_VERSION }} all
sudo apt install -y libc++-${{ env.CLANG_VERSION }}-dev libc++abi-${{ env.CLANG_VERSION }}-dev
sudo apt install -y clang-tools-${{ env.CLANG_VERSION }}

- name: Update alternatives
run: |
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-${{ env.CLANG_VERSION }} 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-${{ env.CLANG_VERSION }} 100
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${{ env.CLANG_VERSION }} 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${{ env.CLANG_VERSION }} 100

- name: Install latest cmake and ninja
uses: lukka/get-cmake@latest

- name: Install Conan package manager
uses: turtlebrowser/get-conan@main
with:
version: 2.0.9
version: 2.5.0

- name: Print versions
run: |
cc --version
c++ --version
clang --version
clang++ --version
cmake --version
ninja --version
conan --version

- name: Create default Conan profile
run: conan profile detect
Expand Down
49 changes: 13 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,25 @@
cmake_minimum_required (VERSION 3.27)
cmake_minimum_required (VERSION 3.30)

project (cpp_template)

find_package (fmt REQUIRED)
find_package (cppfront REQUIRED)
message(STATUS "C Compiler: ${CMAKE_C_COMPILER}")
message(STATUS "C++ Compiler: ${CMAKE_CXX_COMPILER}")

set (cppfront_CMD "${cppfront_PACKAGE_FOLDER_RELEASE}/bin/cppfront")
# cppfront setup
include (FetchContent)

# Set variable for generated files directory
set(GEN_DIR ${CMAKE_BINARY_DIR}/gen)
FetchContent_Declare (
cppfront
GIT_REPOSITORY https://github.com/modern-cmake/cppfront.git
GIT_TAG main
)

# Make directory for generated files
file(MAKE_DIRECTORY ${GEN_DIR})
FetchContent_MakeAvailable (cppfront)

set(CPP2_SOURCES
src/main.cpp2
)
find_package (fmt REQUIRED)

# Function to generate a cpp file from a cpp2 file using cppfront
function (generate_cpp cpp2_file)
get_filename_component(cpp_file ${cpp2_file} NAME_WE)
set(cpp_file "${cpp_file}.cpp")
add_custom_command (
COMMAND ${cppfront_CMD} ${CMAKE_CURRENT_SOURCE_DIR}/${cpp2_file} -o ${GEN_DIR}/${cpp_file}
DEPENDS ${cpp2_file}
OUTPUT ${GEN_DIR}/${cpp_file}
COMMENT "Cppfront: ${cpp2_file} -> ${GEN_DIR}/${cpp_file}"
)
set(cpp_file_path ${GEN_DIR}/${cpp_file})
return(PROPAGATE cpp_file_path)
endfunction()

# Call the function to generate cpp files from cpp2 files
set(GEN_CPP_SOURCES "")
foreach(cpp2_file ${CPP2_SOURCES})
generate_cpp(${cpp2_file})
list(APPEND GEN_CPP_SOURCES ${cpp_file_path})
endforeach()

message(STATUS "GEN_CPP_SOURCES: ${GEN_CPP_SOURCES}")

add_executable (cpp_template ${GEN_CPP_SOURCES})
add_executable (cpp_template src/main.cpp2)

set_property (TARGET cpp_template PROPERTY CXX_STANDARD 20)

target_link_libraries (cpp_template PUBLIC fmt::fmt)
target_link_libraries (cpp_template PUBLIC cppfront::cppfront)
11 changes: 7 additions & 4 deletions conan_profile/default
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=20
compiler.libcxx=libstdc++11
compiler.version=12
compiler=clang
compiler.version=18
compiler.cppstd=23
compiler.libcxx=libc++
os=Linux

[conf]
tools.cmake.cmaketoolchain:generator=Ninja
3 changes: 1 addition & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CppTemplate(ConanFile):
generators = 'CMakeToolchain', 'CMakeDeps'
settings = 'os', 'arch', 'compiler', 'build_type'

requires = 'cppfront/cci.20231017', 'fmt/9.0.0'
requires = 'fmt/9.0.0'

def validate(self):
if self.info.settings.compiler.cppstd:
Expand All @@ -20,4 +20,3 @@ def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

2 changes: 1 addition & 1 deletion project.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def install(self):
def build(self):
self.install()
print(f'---BUILD {self.name}---')
system_call(f'conan build -of ./conanfiles ./')
system_call(f'conan build -of ./conanfiles ./ -pr:h=./conan_profile/default -pr:b=./conan_profile/default')

def run(self):
print(f'---RUN {self.name}---')
Expand Down
Loading