MantisBT - CMake
View Issue Details
0015235CMakeCMakepublic2014-11-06 11:572015-05-04 09:05
Andrew Aladjev 
 
normalmajoralways
closedduplicate 
LinuxGentoo2.2
CMake 3.0.2 
 
0015235: CMAKE_LD_FLAGS from toolchain is ignored by compiler's check
I want to use gcc's thread sanitizer. I have toolchain.cmake

set (CMAKE_SYSTEM_NAME "Linux")
set (CMAKE_C_COMPILER "gcc-4.8.3")
set (CMAKE_C_FLAGS "-fPIE -Werror -Wno-maybe-uninitialized -fsanitize=thread -fno-omit-frame-pointer" CACHE STRING "gcc-4.8.3 thread cflags")
set (CMAKE_LD_FLAGS "-pie")
cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake ..

/usr/bin/gcc-4.8.3 -fPIE -Werror -Wno-maybe-uninitialized -fsanitize=thread -fno-omit-frame-pointer
CMakeFiles/cmTryCompileExec3265698553.dir/testCCompiler.c.o -o cmTryCompileExec3265698553 -rdynamic

gcc-4.8.3: error: -fsanitize=thread linking must be done with -pie or -shared

CMAKE_C_FLAGS works, but CMAKE_LD_FLAGS is ignored.
No tags attached.
related to 0014066closed Brad King Provided CMAKE_*_LINKER_FLAGS ignored during configuration step 
Issue History
2014-11-06 11:57Andrew AladjevNew Issue
2014-11-06 12:50Brad KingNote Added: 0037159
2014-11-27 21:12HinterwaeldlerNote Added: 0037308
2014-12-01 08:36Brad KingRelationship addedrelated to 0014066
2014-12-16 10:11Brad KingNote Added: 0037468
2014-12-16 10:11Brad KingStatusnew => resolved
2014-12-16 10:11Brad KingResolutionopen => duplicate
2015-05-04 09:05Robert MaynardNote Added: 0038701
2015-05-04 09:05Robert MaynardStatusresolved => closed

Notes
(0037159)
Brad King   
2014-11-06 12:50   
The variable is called CMAKE_EXE_LINKER_FLAGS. This works for me:

$ cat toolchain.cmake
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_C_COMPILER /usr/bin/cc)
set(CMAKE_C_FLAGS "-fPIE -fsanitize=thread" CACHE STRING "thread cflags")
set(CMAKE_EXE_LINKER_FLAGS "-pie" CACHE STRING "thread ldflags")
(0037308)
Hinterwaeldler   
2014-11-27 21:12   
Within my cmake update the same thing happens close to the described problem above, but happens only on a deploy machine (both debian testing with cmake 3.0.2)
The difference: I use the exe linker flag but the result seems to be the same (as described form brad king)

As this has not been seen on the developer machine yet i played around a little bit with cmake call and make call.
No real solution so far, but at leas a workaround, which seems to work:
1. Trigger the cmake call
2. Touch the Toolchain-file
3. Trigger the make

One line call:
rm -rf build ; mkdir build ; cd build ; cmake -DCMAKE_TOOLCHAIN_FILE=../Toolchain-file.cmake .. ; touch ../Toolchain-file.cmake ; make VERBOSE=1 # to see if the flags are appended correctly

btw. i've appended appended a few message logouts to determine the current flags. Every of them looks like expected, but the links.txt does not contain any of the assinged values
(0037468)
Brad King   
2014-12-16 10:11   
The solution in 0014066 should address this too.
(0038701)
Robert Maynard   
2015-05-04 09:05   
Closing resolved issues that have not been updated in more than 4 months.