I need to pass a specific compiler switch to CXX compiler by following statement, in this example use clang and arg: -emit-llvm but during generation, it complains the linker can not use this argument. Apparently cmake is passing this arg to both during object file generation and linking stage.
How do I tell cmake such that, compiling and linking will use different arguments, or more so, tell it to do whole stages separately?
Here is my code:
cmake_minimum_required(VERSION 3.10)
set(ROCMOPENCL /opt/rocm/opencl/)
set(CMAKE_C_COMPILER /opt/rocm-4.1.0/llvm//bin//clang -emit-llvm)
set(CMAKE_CXX_COMPILER /opt/rocm-4.1.0/llvm//bin//clang)
message( “ROCM library path:” ${ROCMOPENCL} )
#add_subdirectory(${ROCMOPENCL}/lib/ build)
foreach(var p25 p31 p188 p41 ex-code-1)
message(STATUS “Generating makefile for ${var}”)
project(${var})
add_executable(${var} ${var}.c)
project(${var})
add_executable(${var}.out ${var}.c)
target_link_libraries(${var} PUBLIC ${ROCMOPENCL}/lib/libOpenCL.so)
target_include_directories(${var} PUBLIC ${ROCMOPENCL}/include)
endforeach()
output of cmake …
– Generating makefile for p25
– The C compiler identification is unknown
– The CXX compiler identification is Clang 12.0.0
– Check for working C compiler: /opt/rocm-4.1.0/llvm//bin//clang
– Check for working C compiler: /opt/rocm-4.1.0/llvm//bin//clang – broken
CMake Error at /usr/local/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"/opt/rocm-4.1.0/llvm//bin//clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /git.co/dev-learn/rocm/opencl/opencl-programming-guide/cuda-conversion/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_4eae3/fast && /usr/bin/make -f CMakeFiles/cmTC_4eae3.dir/build.make CMakeFiles/cmTC_4eae3.dir/build
make[1]: Entering directory '/git.co/dev-learn/rocm/opencl/opencl-programming-guide/cuda-conversion/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_4eae3.dir/testCCompiler.c.o
/opt/rocm-4.1.0/llvm//bin//clang -emit-llvm -o CMakeFiles/cmTC_4eae3.dir/testCCompiler.c.o -c /git.co/dev-learn/rocm/opencl/opencl-programming-guide/cuda-conversion/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_4eae3
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_4eae3.dir/link.txt --verbose=1
/opt/rocm-4.1.0/llvm//bin//clang -emit-llvm CMakeFiles/cmTC_4eae3.dir/testCCompiler.c.o -o cmTC_4eae3
clang-12: error: -emit-llvm cannot be used when linking
CMakeFiles/cmTC_4eae3.dir/build.make:89: recipe for target 'cmTC_4eae3' failed
make[1]: *** [cmTC_4eae3] Error 1
make[1]: Leaving directory '/git.co/dev-learn/rocm/opencl/opencl-programming-guide/cuda-conversion/build/CMakeFiles/CMakeTmp'
Makefile:124: recipe for target 'cmTC_4eae3/fast' failed
make: *** [cmTC_4eae3/fast] Error 2