0

I'm trying to get a rather unusual compiler (CC65) to work with CMake so I can use CLion for my project.

I got as far as getting CMake to call the correct compiler but CMake still adds all sorts of GNU compiler options which I don't need:

    Compiler exited with error code 1: /opt/local/bin/cc65 -xc -g -D DEBUG --asm-define DEBUG -t atari -fpch-preprocess -v -dD -E
    cc65: Unknown option: -xc -g -D DEBUG --asm-define DEBUG -t atari -fpch-preprocess -v -dD -E -D___CIDR_DEFINITIONS_END

How to get rid off all the default options so I can start from scratch building up the correct options step by step?


Update 1:

The toolchain file used wasn't developed by me and is rather on the simple side:

https://github.com/jviskari/cc65_cmake/blob/master/toolchain/cc65-toolchain.cmake


Update 2:

I'm not calling the CMake file myself. I only make this effort to used JetBrains CLion. If it wasn't for CLion I would just use GNU-Make.

Since I don't call CMake myself a command-line option won't work so I use set() function

set (CMAKE_TOOLCHAIN_FILE "${PROJECT_SOURCE_DIR}/Library/CMake/Atari/cc65-toolchain.cmake")

The full output is:

/Applications/Developer/apps/CLion/ch-0/222.4345.21/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/opt/local/bin/gmake -DCMAKE_C_COMPILER=/opt/local/bin/cc65 -G "CodeBlocks - Unix Makefiles" -S /Users/Shared/Work/Projects/6502Tutorial -B /Users/Shared/Work/Projects/6502Tutorial/cmake-build-debug-c65
-- Warning: Did not find file Compiler/cc65-ASM
> CMAKE_ASM_COMPILER:  /opt/local/bin/ca65
> CMAKE_C_COMPILER:    /opt/local/bin/cc65
> CMAKE_AR:            /opt/local/bin/ar65
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Shared/Work/Projects/6502Tutorial/cmake-build-debug-c65

Cannot get compiler information:
    Compiler exited with error code 1: /opt/local/bin/cc65 -xc -g -D DEBUG --asm-define DEBUG -t atari -fpch-preprocess -v -dD -E
    cc65: Unknown option: -xc -g -D DEBUG --asm-define DEBUG -t atari -fpch-preprocess -v -dD -E -D___CIDR_DEFINITIONS_END
    
    

[Previous CMake output restored: 17.10.22, 17:40]

Full CMakeLists.txt here:

https://sourceforge.net/p/tutorial-6502/code/ci/feature/compiler/~/tree/CMakeLists.txt


Update 3:

Just to be sure I checked if I can tweak the CLion generated command. I was successful, the output is slightly different but the net result stays the same:

/Applications/Developer/apps/CLion/ch-0/222.4345.21/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/opt/local/bin/gmake -DCMAKE_C_COMPILER=/opt/local/bin/cc65 --toolchain Library/CMake/Atari/cc65-toolchain.cmake -G "CodeBlocks - Unix Makefiles" -S /Users/Shared/Work/Projects/6502Tutorial -B /Users/Shared/Work/Projects/6502Tutorial/cmake-build-release-c65
>>cc65-toolchain.cmake
>>cc65-toolchain.cmake
-- The ASM compiler identification is cc65
-- Found assembler: /opt/local/bin/ca65
-- Detecting C compiler ABI info
>>cc65-toolchain.cmake
-- Detecting C compiler ABI info - failed
-- Warning: Did not find file Compiler/cc65-ASM
> CMAKE_ASM_COMPILER:  /opt/local/bin/ca65
> CMAKE_C_COMPILER:    /opt/local/bin/cc65
> CMAKE_AR:            /opt/local/bin/ar65
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Shared/Work/Projects/6502Tutorial/cmake-build-release-c65

Cannot get compiler information:
    Compiler exited with error code 1: /opt/local/bin/cc65 -xc -t atari -fpch-preprocess -v -dD -E
    cc65: Unknown option: -xc -t atari -fpch-preprocess -v -dD -E -D___CIDR_DEFINITIONS_END
    
    

Update 4:

Switch to CLion's default toolchain configuration to see if there is a conflict between the two toolchains. But this results in all the options being passed “DOS style” with a '/' instead of an '-'.

/Applications/Developer/apps/CLion/ch-0/222.4345.21/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/Applications/Developer/apps/CLion/ch-0/222.4345.21/CLion.app/Contents/bin/ninja/mac/ninja --toolchain Library/CMake/Atari/cc65-toolchain.cmake -G Ninja -S /Users/Shared/Work/Projects/6502Tutorial -B /Users/Shared/Work/Projects/6502Tutorial/cmake-build-release
>>cc65-toolchain.cmake
>>cc65-toolchain.cmake
-- The ASM compiler identification is cc65
-- Found assembler: /opt/local/bin/ca65
-- Detecting C compiler ABI info
>>cc65-toolchain.cmake
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/local/bin/cl65 - skipped
-- Warning: Did not find file Compiler/cc65-ASM
> CMAKE_ASM_COMPILER:  /opt/local/bin/ca65
> CMAKE_C_COMPILER:    /opt/local/bin/cl65
> CMAKE_AR:            /opt/local/bin/ar65
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Shared/Work/Projects/6502Tutorial/cmake-build-release

Cannot get compiler information:
    Compiler exited with error code 1: /opt/local/bin/cl65 @/private/var/folders/yv/kps0l5k55db3bmvbp4mbcdpw0000gn/T/response-file5391882336445539336 /private/var/folders/yv/kps0l5k55db3bmvbp4mbcdpw0000gn/T/compiler-file6838441381382142237 | @response-file5391882336445539336=/TC -t atari /Be /Bd /EP
    cl65: Don't know what to do with '/TC -t atari /Be /Bd /EP'

Martin
  • 11,577
  • 16
  • 80
  • 110
  • "I got as far as getting CMake to call the correct compiler" - How did you do that? If you set `CMAKE_C_COMPILER` after the `project()` call, then it is a [wrong way](https://stackoverflow.com/a/63944545/3440745). Instead, set CC environment variable or pass `CMAKE_C_COMPILER` to `cmake` executable. In case of real cross-compiling you need to prepare a **toolchain file**. – Tsyvarev Oct 17 '22 at 14:20
  • @tsyvarev Simple: by setting `CMAKE_C_COMPILER` **before** the `project()` using a toolchain file. Sadly the some defaults still made it past the toolchain file. How do I get rid of them? – Martin Oct 17 '22 at 15:00
  • These are not "defaults", they are selected by a platform script according to the compiler. And the error "Unknown option" smells like the rest of the line is interpreted by the compiler as a **single option**. So the problem could be in the way how options are passed to the compiler. Show (add to the question post): 1. The exact toolchain file. 2. The way how do you pass it to CMake (is it command a line parameter `CMAKE_TOOLCHAIN_FILE`?). 3. The exact output of CMake (the error message you show is the `CMakeErrorLog.txt`, which should be interpreted only according to CMake output). – Tsyvarev Oct 17 '22 at 15:42
  • @tsyvarev I added the requested informations. Even through I fear that this will only lead to side tracking. Which already happened. The cl65 is a very simple compiler targeting an old 8bit CPU. The error message might not off of the usual quality. – Martin Oct 17 '22 at 18:47
  • The error message "Cannot get compiler information" seems to be **specific to CLion**. See e.g. [this question](https://stackoverflow.com/questions/54504153/clang-with-clion-cannot-get-compiler-information) or [that one](https://stackoverflow.com/questions/60032017/unreal-engine-and-clion-cannot-get-compiler-information). "Since I don't call CMake myself a command-line option won't work" - You have searched for that topic, am I right? https://intellij-support.jetbrains.com/hc/en-us/community/posts/360005140999-CLion-and-CMake-Toolchain-Files – Tsyvarev Oct 17 '22 at 20:49
  • "I fear that this will only lead to side tracking. Which already happened. The cl65 is a very simple compiler..." - You just make things upside down. You got **specific** errors and blame CMake in incorrect handling the "very simple compiler". However, the "Warning: Did not find file Compiler/cc65-ASM" is not about compiler/CMake, it is about the **toolchain file you use**. You got the error message which is **specific to CLion**. Please, do not *generalize* a problem from the beginning. Incorrect generalization harms more than excessive specialization. Always provide exact error messages. – Tsyvarev Oct 17 '22 at 21:05
  • Look at my profile: _„Member for 12 years, 5 months“_ — In those 12 years on this platform I made the observation that giving out to many informations will lead to any amount of unrelated comments. And, BTW, I have a CLion toolchain file as well. The `-DCMAKE_C_COMPILER=/opt/local/bin/cc65` is a dead giveaway for that. Which might be a problem. I shall make another test without. – Martin Oct 18 '22 at 05:45

1 Answers1

0

With some help from the CMake Forum the (remaining) problems have been localised to be be (most likely) in CLion. Build files are now created when using the terminal:

>cmake --toolchain Library/cc65-toolchain.cmake -S . -B cmake-build-release 
-- The ASM compiler identification is cc65
-- Found assembler: /opt/local/bin/cl65
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /opt/local/bin/cl65
-- Check for working C compiler: /opt/local/bin/cl65 - works
-- Warning: Did not find file Compiler/cc65-ASM
> CMAKE_ASM_COMPILER:  /opt/local/bin/cl65
> CMAKE_C_COMPILER:    /opt/local/bin/cl65
> CMAKE_AR:            /opt/local/bin/ar65
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Shared/Work/Projects/6502Tutorial/Atari/cmake-build-release

Of course I tried calling CMake from on the terminal before and at the time it didn't work.

My guess is that there were multiple problems some of which I fixed and now all problems left are with CLion. As such the original question has been answered:

CMake default options can be removed by using an appropriate toolchain file.

Thanks to everybody who helped with this rather tricky problem. I will open a follow up post on the JetBrains forum.

Martin
  • 11,577
  • 16
  • 80
  • 110