Building c++ project on Windows with CMake, Clang and Ninja - c++

I currently have cmake, clang and ninja installed on windows. I am trying to use CMake to generate a ninja build file to compile a very simple hello world program.
My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 2.8)
project(test_project)
add_executable(main main.cpp)
main.cpp is a simple hello world program.
On the command line I run this: cmake -G Ninja .. and I get the following errors:
-- The C compiler identification is Clang 3.5.0
clang.exe: error: no such file or directory: '/nologo'
clang.exe: error: no such file or directory: '/showIncludes'
-- The CXX compiler identification is Clang 3.5.0
clang.exe: error: no such file or directory: '/nologo'
clang.exe: error: no such file or directory: '/showIncludes'
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "C:/llvm_build/RelWithDebInfo/bin/clang.exe" is
not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/test_proj/build/CMakeFiles/CMakeTmp
Run Build Command:C:/ninja/ninja.exe cmTryCompileExec375034429
[1/2] Building C object
CMakeFiles\cmTryCompileExec375034429.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTryCompileExec375034429.exe
FAILED: cmd.exe /c cd . &&
C:\llvm_build\RelWithDebInfo\bin\clang.exe
CMakeFiles\cmTryCompileExec375034429.dir\testCCompiler.c.obj -o
cmTryCompileExec375034429.exe && cd .
clang.exe: error: unable to execute command: program not executable
clang.exe: error: linker command failed with exit code 1 (use -v to see
invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "C:/test_proj/build/CMakeFiles/CMakeOutput.log".
See also "C:/test_proj/build/CMakeFiles/CMakeError.log".
The CMakeError.log file looks like this:
Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: C:/llvm_build/RelWithDebInfo/bin/clang.exe
Build flags:
Id flags:
The output was:
1
clang.exe: error: unable to execute command: program not executable
clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/llvm_build/RelWithDebInfo/bin/clang++.exe
Build flags:
Id flags:
The output was:
1
clang++.exe: error: unable to execute command: program not executable
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
Determining if the C compiler works failed with the following output:
Change Dir: C:/test_proj/build/CMakeFiles/CMakeTmp
Run Build Command:C:/ninja/ninja.exe cmTryCompileExec2120850158
[1/2] Building C object CMakeFiles\cmTryCompileExec2120850158.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTryCompileExec2120850158.exe
FAILED: cmd.exe /c cd . && C:\llvm_build\RelWithDebInfo\bin\clang.exe CMakeFiles\cmTryCompileExec2120850158.dir\testCCompiler.c.obj -o cmTryCompileExec2120850158.exe && cd .
clang.exe: error: unable to execute command: program not executable
clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
It appears that cmake is trying to test clang with windows options /nologo and /showIncludes. I cannot figure out how to tell cmake to pass the proper arguments.
FWIW I'm running 64bit Windows 7
EDIT:
So I looked through the built in cmake files and I found that the CMakeClDeps.cmake file was the culprit for adding the /nologo /showIncludes options. It appears that if I set Clang as the compiler then cmake thinks that visual studio is the compiler (it sets MSVC_C_ARCHITECTURE_ID to x86).
I removed the line in CMakeDetermineCompilerId.cmake that sets MSVC_C_ARCHITECTURE_ID and after trying again I get the following errors:
-- The C compiler identification is Clang 3.5.0
-- The CXX compiler identification is Clang 3.5.0
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "C:/llvm_build/RelWithDebInfo/bin/clang.exe" is
not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/test_proj/build/CMakeFiles/CMakeTmp
Run Build Command:C:/ninja/ninja.exe cmTryCompileExec2815594422
[1/2] Building C object
CMakeFiles\cmTryCompileExec2815594422.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTryCompileExec2815594422.exe
FAILED: cmd.exe /c cd . &&
C:\llvm_build\RelWithDebInfo\bin\clang.exe
CMakeFiles\cmTryCompileExec2815594422.dir\testCCompiler.c.obj -o
cmTryCompileExec2815594422.exe && cd .
clang.exe: error: unable to execute command: program not executable
clang.exe: error: linker command failed with exit code 1 (use -v to see
invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "C:/test_proj/build/CMakeFiles/CMakeOutput.log".
See also "C:/test_proj/build/CMakeFiles/CMakeError.log".

Don't know if it can be helpful but I had the same error. Now I can compile with clang(3.7.1)/ninja(1.6)/cmake(3.4.1) on Windows performing the following actions in a build directory:
load the relevant vcvarsXX.bat file (e.g. "<Your Visual Studio location>\VC\vcvarsall.bat" x86)
set both CC and CXX to clang-cl (instead of clang and clang++)
run cmake -G Ninja <project>
run cmake --build .

Turns out the second set of errors I received were because clang could not find the linker. I had built clang using visual studio but at the time it couldn't find the visual studio linker. All I had to do was run it in the visual studio development console.
CMake still thinks that clang is a visual studio compiler so in the CMakeDetermineCompilerId.cmake file there is a line that looks like this:
set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
and I changed it to look like this
if (COMPILER_ID MATCHES "MSVC")
set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
endif()
Hopefully this doesn't break any other CMake functionality.

Related

Failure to compile for arm64 devices

Hello i am quite new to linux and i am trying to do some cross-compilation to run a flutter app on an external device.
Setup :
VM under virtual box : Ubuntu 22.04 LTS
External device : (imx8) with arm64
So i need to compile my app to match the arm64 architecture but i am having many errors that i have no idea how to fix and no idea where they come from :
Failed to cmake:
-- The CXX compiler identification is Clang 14.0.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ - broken
-- Configuring incomplete, errors occurred!
See also "/home/tom/test_app/build/elinux/arm64/release/CMakeFiles/CMakeOutput.log".
See also "/home/tom/test_app/build/elinux/arm64/release/CMakeFiles/CMakeError.log".
CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
The C++ compiler
"/usr/bin/clang++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/tom/test_app/build/elinux/arm64/release/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_46f48/fast && /usr/bin/gmake -f CMakeFiles/cmTC_46f48.dir/build.make CMakeFiles/cmTC_46f48.dir/build
gmake[1]: Entering directory '/home/tom/test_app/build/elinux/arm64/release/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_46f48.dir/testCXXCompiler.cxx.o
/usr/bin/clang++ --target=aarch64-linux-gnu --sysroot=/opt/arm64-sysroot -MD -MT CMakeFiles/cmTC_46f48.dir/testCXXCompiler.cxx.o -MF
CMakeFiles/cmTC_46f48.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_46f48.dir/testCXXCompiler.cxx.o -c
/home/tom/test_app/build/elinux/arm64/release/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
Linking CXX executable cmTC_46f48
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_46f48.dir/link.txt --verbose=1
/usr/bin/clang++ --target=aarch64-linux-gnu --sysroot=/opt/arm64-sysroot CMakeFiles/cmTC_46f48.dir/testCXXCompiler.cxx.o -o cmTC_46f48
/usr/bin/aarch64-linux-gnu-ld: cannot find Scrt1.o: No such file or directory
/usr/bin/aarch64-linux-gnu-ld: cannot find crti.o: No such file or directory
/usr/bin/aarch64-linux-gnu-ld: cannot find crtbeginS.o: No such file or directory
/usr/bin/aarch64-linux-gnu-ld: cannot find -lstdc++: No such file or directory
/usr/bin/aarch64-linux-gnu-ld: cannot find -lm: No such file or directory
/usr/bin/aarch64-linux-gnu-ld: cannot find -lgcc_s: No such file or directory
/usr/bin/aarch64-linux-gnu-ld: cannot find -lgcc: No such file or directory
/usr/bin/aarch64-linux-gnu-ld: cannot find -lc: No such file or directory
/usr/bin/aarch64-linux-gnu-ld: cannot find -lgcc_s: No such file or directory
/usr/bin/aarch64-linux-gnu-ld: cannot find -lgcc: No such file or directory
/usr/bin/aarch64-linux-gnu-ld: cannot find crtendS.o: No such file or directory
/usr/bin/aarch64-linux-gnu-ld: cannot find crtn.o: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[1]: *** [CMakeFiles/cmTC_46f48.dir/build.make:100: cmTC_46f48] Error 1
gmake[1]: Leaving directory '/home/tom/test_app/build/elinux/arm64/release/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:127: cmTC_46f48/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
For more specification, i am using the flutter-elinux package to cross-compile and i have raised an issue there, but i am not sure the issue comes from the package as i don't know anything about linux compilation.
I have installed manually the following packages :
sudo apt install cpp-aarch64-linux-gnu
sudo apt install binutils-aarch64-linux-gnu
Thanks in advance for any help i really need to get this working...
EDIT : i have tried another solution using a docker container and the image arm64v8/ubuntu:18.04.
I have created a systroot ubuntu18-arm64-sysroot on my host and i use it to compile my app in arm64 arch. I am having the following error only :
Failed to cmake:
-- The CXX compiler identification is unknown
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /home/tom/ubuntu18-arm64-sysroot/usr/bin/clang++
-- Check for working CXX compiler: /home/tom/ubuntu18-arm64-sysroot/usr/bin/clang++ - broken
-- Configuring incomplete, errors occurred!
See also "/home/tom/test_app/build/elinux/arm64/debug/CMakeFiles/CMakeOutput.log".
See also "/home/tom/test_app/build/elinux/arm64/debug/CMakeFiles/CMakeError.log".
CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
The C++ compiler
"/home/tom/ubuntu18-arm64-sysroot/usr/bin/clang++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/tom/test_app/build/elinux/arm64/debug/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_848af/fast && /usr/bin/gmake -f
CMakeFiles/cmTC_848af.dir/build.make CMakeFiles/cmTC_848af.dir/build
gmake[1]: Entering directory '/home/tom/test_app/build/elinux/arm64/debug/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_848af.dir/testCXXCompiler.cxx.o
/home/tom/ubuntu18-arm64-sysroot/usr/bin/clang++ -o CMakeFiles/cmTC_848af.dir/testCXXCompiler.cxx.o -c
/home/tom/test_app/build/elinux/arm64/debug/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
aarch64-binfmt-P: Could not open '/lib/ld-linux-aarch64.so.1': No such file or directory
gmake[1]: *** [CMakeFiles/cmTC_848af.dir/build.make:78: CMakeFiles/cmTC_848af.dir/testCXXCompiler.cxx.o] Error 255
gmake[1]: Leaving directory '/home/tom/test_app/build/elinux/arm64/debug/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:127: cmTC_848af/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)

ninja: fatal: CreateProcess: Access is denied. in windows 10

the repo i'm trying to build is https://github.com/svenstaro/glsl-language-server
this is the error i get
glsl-language-server [ master][△ v3.22.3]
❯ cmake -Bbuild -GNinja
-- The C compiler identification is unknown
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/cygwin64/bin/cc
-- Check for working C compiler: C:/cygwin64/bin/cc - broken
CMake Error at C:/Users/hitus/scoop/apps/cmake/3.22.3/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"C:/cygwin64/bin/cc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: E:/software/glsl-language-server/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Users/hitus/scoop/shims/ninja.exe cmTC_f7f6a &&
CreateProcess failed. Command attempted:
"C:\cygwin64\bin\cc -o CMakeFiles\cmTC_f7f6a.dir\testCCompiler.c.obj -c E:\software\glsl-language-server\build\CMakeFiles\CMakeTmp\testCCompiler.c"
ninja: fatal: CreateProcess: Access is denied.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "E:/software/glsl-language-server/build/CMakeFiles/CMakeOutput.log".
See also "E:/software/glsl-language-server/build/CMakeFiles/CMakeError.log".
running c++ works
glsl-language-server [ master][△ v3.22.3]
❯ c++
c++: fatal error: no input files
compilation terminated.
but running cc doesn't
ResourceUnavailable: Program 'cc' failed to run: An error occurred trying to start process 'C:\cygwin64\bin\cc' with working directory 'E:\software\glsl-language-server'. No application is as
sociated with the specified file for this operation.At line:1 char:1
+ cc
+ ~~.
i'm using powershell 7 and cygwin, ninja and cmake are installed from scoop

CMake ARM GCC Undefined reference to "_exit" [duplicate]

This question already has answers here:
CMake: The C Compiler is not able to compile a simple test program
(4 answers)
Linker error on a C project using Eclipse
(5 answers)
How to cross compile with cmake + arm-none-eabi on windows?
(1 answer)
Closed 1 year ago.
I am trying to use arm-none-eabi-gcc with CMake but am getting an error about an undefined reference to "_exit". The following is the terminal output after running cmake (the first line is the command):
cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=F:\Resources\Dev\Tools\GNU-arm\10.3-2021.07\bin\arm-none-eabi-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=F:\Resources\Dev\Tools\GNU-arm\10.3-2021.07\bin\arm-none-eabi-g++.exe -Hf:/Projects/Dev/VS-Code/CPP/CPP-Sandbox "-Bf:/Projects/Dev/VS-Code/CPP/CPP-Sandbox/build/GCC 10.3.1 arm-none-eabi/Debug" -G Ninja
Not searching for unused variables given on the command line.
-- The C compiler identification is GNU 10.3.1
-- Check for working C compiler: F:/Resources/Dev/Tools/GNU-arm/10.3-2021.07/bin/arm-none-eabi-gcc.exe
-- Check for working C compiler: F:/Resources/Dev/Tools/GNU-arm/10.3-2021.07/bin/arm-none-eabi-gcc.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"F:/Resources/Dev/Tools/GNU-arm/10.3-2021.07/bin/arm-none-eabi-gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: F:/Projects/Dev/VS-Code/CPP/CPP-Sandbox/build/GCC 10.3.1 arm-none-eabi/Debug/CMakeFiles/CMakeTmp
Run Build Command(s):F:/Resources/Dev/Tools/MinGW/MinGW-9.0.0-x64/bin/ninja.exe cmTC_1a12b && [1/2] Building C object CMakeFiles/cmTC_1a12b.dir/testCCompiler.c.obj
[2/2] Linking C executable cmTC_1a12b
FAILED: cmTC_1a12b
cmd.exe /C "cd . && F:\Resources\Dev\Tools\GNU-arm\10.3-2021.07\bin\arm-none-eabi-gcc.exe CMakeFiles/cmTC_1a12b.dir/testCCompiler.c.obj -o cmTC_1a12b && cd ."
f:/resources/dev/tools/gnu-arm/10.3-2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: f:/resources/dev/tools/gnu-arm/10.3-2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:41 (project)
-- Configuring incomplete, errors occurred!
See also "F:/Projects/Dev/VS-Code/CPP/CPP-Sandbox/build/GCC 10.3.1 arm-none-eabi/Debug/CMakeFiles/CMakeOutput.log".
See also "F:/Projects/Dev/VS-Code/CPP/CPP-Sandbox/build/GCC 10.3.1 arm-none-eabi/Debug/CMakeFiles/CMakeError.log".
I have tried the following solution (i.e. adding simply adding -specs=nosys.specs to my CMakeLists.txt but to no avail. Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_STANDARD 99)
# Project variables
set(LOCAL_PROJECT_NAME "C-Sandbox")
set(LOCAL_PROJECT_VERSION "0.0.1")
set(LOCAL_PROJECT_DESCRIPTION "Description")
# Project setup
project(${LOCAL_PROJECT_NAME}
VERSION ${LOCAL_PROJECT_VERSION}
DESCRIPTION ${LOCAL_PROJECT_DESCRIPTION}
LANGUAGES C)
add_executable(${LOCAL_PROJECT_NAME})
target_sources(${LOCAL_PROJECT_NAME} PRIVATE src/main.c)
target_link_options(${LOCAL_PROJECT_NAME} PRIVATE "-specs=nosys.specs")
set_target_properties(${LOCAL_PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "bin")
Edit:
When I cd into my source folder and run arm-none-eabi-gcc main.c -lc "-specs=nosys.specs" I get no error and an a.out file.

Conda CMake not finding GCC -- Windows

I'm running a conda environment on Windows to get a bash-similar environment (I'm a native Linux Mint user and this is my first time running Windows). But when I run cmake in my conda environment I get the following error:
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:33 (project):
The CMAKE_C_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:33 (project):
The CMAKE_CXX_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C://CMakeFiles/CMakeOutput.log".
See also "C://CMakeFiles/CMakeError.log".
CMake Error: Cannot open file for write: C://CMakeCache.txt.tmp
CMake Error: : System Error: Permission denied
CMake Error: Unable to open cache file for save. C://CMakeCache.txt
CMake Error: : System Error: Permission denied
I've installed GCC on my conda environment, but I'm not sure how to force CMake to find it.
UPDATE:
I was able to point the compiler to where gcc is installed, but now I get this error:
-- Building for: NMake Makefiles
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/Users/aeglick/AppData/Local/Continuum/anaconda2/Library/mingw-w64/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: nmake /nologo cmTC_da93e\fast &&
-- Check for working C compiler: C:/Users/aeglick/AppData/Local/Continuum/anaconda2/Library/mingw-w64/bin/gcc.exe - broken
CMake Error at C:/Users/aeglick/AppData/Local/Continuum/anaconda2/Library/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/Users/aeglick/AppData/Local/Continuum/anaconda2/Library/mingw-w64/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/aeglick/Documents/GEANT4.10.07/geant4-build/CMakeFiles/CMakeTmp
Run Build Command(s):nmake /nologo cmTC_da93e\fast && The system cannot find the file specified
Generator: execution of make failed. Make command was: nmake /nologo cmTC_da93e\fast &&
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:33 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/aeglick/Documents/GEANT4.10.07/geant4-build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/aeglick/Documents/GEANT4.10.07/geant4-build/CMakeFiles/CMakeError.log".

CMake passes Visual C++ parameters to clang instead of expexted GCC ones

I'm trying to build the project under win10 using mingw latest toolchain and clang compilers (from CLion IDE) with explicitly specified compilers in commandline options :
-DCMAKE_C_COMPILER=C:/dev/tools/LLVM/bin/clang.exe
-DCMAKE_CXX_COMPILER=C:/dev/tools/LLVM/bin/clang++.exe
cmake recognize clang correctly, but during the test compilations tries to pass cl (Visual C++ compiler) flags:
C:\dev\tools\CLion.RC\bin\cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=C:/dev/tools/LLVM/bin/clang.exe -DCMAKE_CXX_COMPILER=C:/dev/tools/LLVM/bin/clang++.exe -G "CodeBlocks - MinGW Makefiles" C:\Users\amigo421\ClionProjects\hr2
-- The C compiler identification is unknown
-- The CXX compiler identification is Clang 3.9.0
-- Check for working C compiler: C:/dev/tools/LLVM/bin/clang.exe
-- Check for working C compiler: C:/dev/tools/LLVM/bin/clang.exe -- broken CMake Error at
C:/dev/tools/CLion.RC/bin/cmake/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61
(message): The C compiler "C:/dev/tools/LLVM/bin/clang.exe" is not
able to compile a simple test program.
It fails with the following output:
C:\dev\tools\LLVM\bin\clang.exe /DWIN32 /D_WINDOWS /W3 -o
CMakeFiles\cmTC_397ea.dir\testCCompiler.c.obj -c
C:\Users\amigo421\ClionProjects\hr2\cmake-build-debug\CMakeFiles\CMakeTmp\testCCompiler.c
**clang.exe: error: no such file or directory: '/DWIN32'**
**clang.exe: error: no such file or directory: '/D_WINDOWS'**
**clang.exe: error: no such file or directory: '/W3'**
CMakeFiles\cmTC_397ea.dir\build.make:64: recipe for target
'CMakeFiles/cmTC_397ea.dir/testCCompiler.c.obj' failed
mingw32-make.exe[1]: ***
[CMakeFiles/cmTC_397ea.dir/testCCompiler.c.obj] Error 1
mingw32-make.exe[1]: Leaving directory
'C:/Users/amigo421/ClionProjects/hr2/cmake-build-debug/CMakeFiles/CMakeTmp'
you see that cmake passes visual c++ flags , I don't plan to use clang-cl.
I suppose that cmake should use GCC (MinGW) parameters in command line
any idea how to fix this