From f07deeaa7ef30196b750cacd511699f02ac1395d Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Thu, 6 Oct 2022 07:56:42 +0200 Subject: [PATCH] Adds CMake support Adds a simple CMake script and makes the tests portable with both Windows and Linux support. --- .gitignore | 2 ++ CMakeLists.txt | 36 +++++++++++++++++++++++++++++++ README.md | 4 ++++ regression-tests/run-tests.bat.in | 17 +++++++++++++++ regression-tests/run-tests.sh.in | 23 ++++++++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 regression-tests/run-tests.bat.in create mode 100644 regression-tests/run-tests.sh.in diff --git a/.gitignore b/.gitignore index 93669d9eb4..7115ee7a10 100644 --- a/.gitignore +++ b/.gitignore @@ -16,9 +16,11 @@ *.sln *.exe *.txt +!CMakeLists.txt *.db-shm *.db-wal *.opendb *.vsidx *.lock .editorconfig +/build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..d29fffac39 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,36 @@ +project(cppfront) +cmake_minimum_required(VERSION 3.20) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED YES) +set(CMAKE_CXX_EXTENSIONS OFF) + +add_executable(cppfront source/cppfront.cpp) + +# The test scripts are generated in two steps - configure to replace the +# variables, - geneated the configured output to replace the generator +# expressions. +configure_file(regression-tests/run-tests.bat.in + ${CMAKE_BINARY_DIR}/run-tests.bat.in @ONLY) + +file( + GENERATE + OUTPUT run-tests.bat + INPUT ${CMAKE_BINARY_DIR}/run-tests.bat.in) + +configure_file(regression-tests/run-tests.sh.in + ${CMAKE_BINARY_DIR}/run-tests.sh.in @ONLY) + +file( + GENERATE + OUTPUT run-tests.sh + INPUT ${CMAKE_BINARY_DIR}/run-tests.sh.in + FILE_PERMISSIONS + OWNER_READ + OWNER_WRITE + OWNER_EXECUTE + GROUP_READ + GROUP_WRITE + GROUP_EXECUTE + WORLD_READ + WORLD_EXECUTE) diff --git a/README.md b/README.md index a8ff95d06e..45ba165439 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,10 @@ Cppfront builds with any major C++20 compiler. clang++-12 cppfront.cpp -std=c++20 -o cppfront +### CMake support + + Alternatively the code can be build using CMake. The build directory will contain the regression test scripts. + ## How do I build my `.cpp2` file? Run `cppfront your.cpp2`, then run the generated `your.cpp` through any major C++20 compiler after putting `/cppfront/include` in the path so it can find `cpp2util.h`. diff --git a/regression-tests/run-tests.bat.in b/regression-tests/run-tests.bat.in new file mode 100644 index 0000000000..251cbc0fa2 --- /dev/null +++ b/regression-tests/run-tests.bat.in @@ -0,0 +1,17 @@ +@echo off +copy @CMAKE_SOURCE_DIR@\*.cpp2 . +set count=0 +for %%f in (mixed-*.cpp2) do ( + echo Starting cppfront.exe %%f + $ %%f > %%f.output 2>&1 + del %%f + set /a count+=1 +) +for %%f in (pure2-*.cpp2) do ( + echo Starting cppfront.exe %%f -p + $ %%f -p > %%f.output 2>&1 + del %%f + set /a count+=1 +) +echo Done: %count% tests + diff --git a/regression-tests/run-tests.sh.in b/regression-tests/run-tests.sh.in new file mode 100644 index 0000000000..4ecd1dd068 --- /dev/null +++ b/regression-tests/run-tests.sh.in @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +cp @CMAKE_SOURCE_DIR@/regression-tests/*.cpp2 . +count=0 + +for f in mixed-*.cpp2 +do + echo Starting cppfront $f + $ $f > $f.output 2>&1 + rm $f + count=$((count+1)) +done + +for f in pure2-*.cpp2 +do + echo Starting cppfront $f -p + $ $f -p > $f.output 2>&1 + rm $f + count=$((count+1)) +done +echo Done: $count tests