diff --git a/CMake-SDCC/.gitignore b/CMake-SDCC/.gitignore new file mode 100644 index 0000000..59b50f7 --- /dev/null +++ b/CMake-SDCC/.gitignore @@ -0,0 +1 @@ +/cmake-build*/ diff --git a/CMake-SDCC/.idea/.gitignore b/CMake-SDCC/.idea/.gitignore new file mode 100644 index 0000000..7a02034 --- /dev/null +++ b/CMake-SDCC/.idea/.gitignore @@ -0,0 +1,6 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +/deployment.xml \ No newline at end of file diff --git a/CMake-SDCC/.idea/CMake-SDCC.iml b/CMake-SDCC/.idea/CMake-SDCC.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/CMake-SDCC/.idea/CMake-SDCC.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/CMake-SDCC/.idea/custom-compiler.xml b/CMake-SDCC/.idea/custom-compiler.xml new file mode 100644 index 0000000..b748584 --- /dev/null +++ b/CMake-SDCC/.idea/custom-compiler.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/CMake-SDCC/.idea/jsonSchemas.xml b/CMake-SDCC/.idea/jsonSchemas.xml new file mode 100644 index 0000000..9f8a145 --- /dev/null +++ b/CMake-SDCC/.idea/jsonSchemas.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CMake-SDCC/.idea/misc.xml b/CMake-SDCC/.idea/misc.xml new file mode 100644 index 0000000..089d1d9 --- /dev/null +++ b/CMake-SDCC/.idea/misc.xml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CMake-SDCC/.idea/modules.xml b/CMake-SDCC/.idea/modules.xml new file mode 100644 index 0000000..50de00e --- /dev/null +++ b/CMake-SDCC/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/CMake-SDCC/.idea/vcs.xml b/CMake-SDCC/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/CMake-SDCC/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CMake-SDCC/CMakeLists.txt b/CMake-SDCC/CMakeLists.txt new file mode 100644 index 0000000..34792eb --- /dev/null +++ b/CMake-SDCC/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.21) +set(CMAKE_SYSTEM_NAME Generic) +# Trick CMake that the compiler always works +set(CMAKE_C_COMPILER_WORKS 1) #todo +set(CMAKE_CXX_COMPILER_WORKS 1) #todo +# End of trick + +#Find the compiler +find_program(SDCC_COMPILER sdcc) +if (${CMAKE_HOST_WIN32}) + if (NOT EXISTS "${SDCC_COMPILER}") + list(APPEND CMAKE_PROGRAM_PATH "C:/Program Files(86)/SDCC/bin") + find_program(SDCC_COMPILER sdcc) + endif () + if (NOT EXISTS "${SDCC_COMPILER}") + list(APPEND CMAKE_PROGRAM_PATH "C:/Program Files/SDCC/bin") + find_program(SDCC_COMPILER sdcc) + endif () +endif () +if (EXISTS "${SDCC_COMPILER}") + set(CMAKE_C_COMPILER "${SDCC_COMPILER}") +else () + message(FATAL_ERROR "SDCC compiler is not found at your computer.") +endif () + +project(CMake-SDCC C) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_C_STANDARD 99) + +add_compile_options(-mstm8) +add_link_options(-mstm8) + +add_executable(custom-compiler-test cmain.c) + diff --git a/CMake-SDCC/README.md b/CMake-SDCC/README.md new file mode 100644 index 0000000..87ca093 --- /dev/null +++ b/CMake-SDCC/README.md @@ -0,0 +1,8 @@ +Test project for Custom Compiler feature +=== + +This project is an example how to use [SDCC](http://sdcc.sourceforge.net/) for stm8 +with [CMake](https://cmake.org/) and [CLion](https://www.jetbrains.com/clion/) +using [Custom Defined Compiler](https://youtrack.jetbrains.com/issue/CPP-9615) + +There is a custom compiler definition file for the compiler: [custom-compiler-sdcc-stm8.yaml](custom-compiler-sdcc-stm8.yaml) diff --git a/CMake-SDCC/cmain.c b/CMake-SDCC/cmain.c new file mode 100644 index 0000000..60c0037 --- /dev/null +++ b/CMake-SDCC/cmain.c @@ -0,0 +1,22 @@ +#include + +#pragma message ("Compile C") +int getInt(); +long long fn() { + return 3ll; +} + +void fan(unsigned int x) { + const int res = x == 123; + if (x == 456) {} +} + +int main() { + puts("Hello, World from C!"); + return 0; +} + +int putchar(int c) { + //fake function + return 1; +} diff --git a/CMake-SDCC/custom-compiler-sdcc-stm8.yaml b/CMake-SDCC/custom-compiler-sdcc-stm8.yaml new file mode 100644 index 0000000..7cd614c --- /dev/null +++ b/CMake-SDCC/custom-compiler-sdcc-stm8.yaml @@ -0,0 +1,31 @@ + +compilers: + + - description: SDCC 4.1.0 STM8 Medium Memory model + match-args: "-mstm8" + match-compiler-exe: "(.*/)?sdcc(\\.exe)?" + code-insight-target-name: avr + include-dirs: "${compiler-exe-dir}/../include" + defines-text: " +#define __STDC_VERSION__ 201112L +#define __SDCC_INT_LONG_REENT 1 +#define __SDCC_MODEL_MEDIUM 1 +#define __STDC_HOSTED__ 0 +#define __STDC_UTF_16__ 1 +#define __SDCC_VERSION_MINOR 1 +#define __STDC_ISO_10646__ 201409L +#define __SDCC_VERSION_PATCH 0 +#define __SDCC_stm8 1 +#define __SDCC_FLOAT_REENT 1 +#define __SDCC_VERSION_MAJOR 4 +#define __STDC_NO_VLA__ 1 +#define __SDCC 4_1_0 +#define __STDC_UTF_32__ 1 +#define __STDC_NO_THREADS__ 1 +#define __SDCC_CHAR_UNSIGNED 1 +#define __STDC_NO_ATOMICS__ 1 +#define __SDCC_STACK_AUTO 1 +#define __STDC__ 1 +#define __SDCC_REVISION 12072 +#define __STDC_NO_COMPLEX__ 1 +" \ No newline at end of file diff --git a/CMake-Texas-Instruments-MSP430-CGT/README.md b/CMake-Texas-Instruments-MSP430-CGT/README.md index 6fed743..cba892c 100644 --- a/CMake-Texas-Instruments-MSP430-CGT/README.md +++ b/CMake-Texas-Instruments-MSP430-CGT/README.md @@ -5,6 +5,4 @@ This project is an example how to use [TI MSP430 CGT compiler](https://www.ti.co with [CMake](https://cmake.org/) and [CLion](https://www.jetbrains.com/clion/) using [Custom Defined Compiler](https://youtrack.jetbrains.com/issue/CPP-9615) -There is a custom compiler definition file for the compiler: [custom-compiler-msp430.yaml](custom-compiler-msp430.yaml) - -**NB**: The compiler is supposed to be installed to `c:\tools\bcc102` folder \ No newline at end of file +There is a custom compiler definition file for the compiler: [custom-compiler-msp430.yaml](custom-compiler-msp430.yaml) \ No newline at end of file diff --git a/README.md b/README.md index 23fef70..afaae38 100644 --- a/README.md +++ b/README.md @@ -16,4 +16,10 @@ Set of examples how to use [CLion](https://www.jetbrains.com/clion/) with variou * Compiler definition file: [custom-compiler-msp430.yaml](CMake-Texas-Instruments-MSP430-CGT/custom-compiler-msp430.yaml) * Host Platforms: Windows, Linux, Mac * Target Platform: MSP430 MCU +* [CMake-SDCC](CMake-SDCC) + * Build System: [CMake](https://cmake.org/) + * Compiler: [SDCC](http://sdcc.sourceforge.net/) for stm8 + * Compiler definition file: [custom-compiler-sdcc-stm8.yaml](CCMake-SDCC/custom-compiler-sdcc-stm8.yaml) + * Host Platforms: Windows, Linux, Mac + * Target Platform: STM8 MCU \ No newline at end of file