We catch Solaris link errors with makefiles created by CMake 3.6.2. In testing below, we use GCC, not SunCC. In appearance, CMake uses our options inconsistently:
Typical Compilation Command
[ 2%] Building CXX object CMakeFiles/cryptopp-object.dir/cpu.cpp.o /bin/c++ -fPIC -march=native -m64 -Wa,--divide -o CMakeFiles/cryptopp-object.dir/cryptlib.cpp.o -c /export/home/jwalton/cryptopp/cpu.cpp
Short link
/bin/c++ CMakeFiles/cryptest.dir/bench1.cpp.o CMakeFiles/cryptest.dir/bench2.cpp.o ... CMakeFiles/cryptest.dir/fipstest.cpp.o -o cryptest.exe libcryptopp.a -lnsl -lsocket
Typical Link Error
ld: fatal: file CMakeFiles/cryptopp-object.dir/cryptlib.cpp.o: wrong ELF class: ELFCLASS64
Note that the file was compiled with -march=native -m64 (its 64-bit machine and kernel), but there is no link invocation (the default is 32-bit Solaris).
Trying to search for "cmake use CXXFLAGS link" creates too much unulocal noise, and I was not very lucky to find CMakeList.txt . I also want to avoid duplication of work in LDFLAGS or do the job of reformatting options ( CXXFLAGS option -Wl,-x becomes LDFLAGS option -x ).
How can I tell CMake to use both CXX and CXXFLAGS when passing links?
I found Launching another program for the linker on the CMake user mailing list, but that doesn't seem right to me (also, the problem and context are slightly different). It also does not work.
Here is a small example:
PROJECT(foo) SET(CMAKE_CXX_LINK_EXECUTABLE "purify <CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") ADD_EXECUTABLE(foo foo.cxx)
I also found setting global link flags on the mailing list. This also does not work.
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_CXX_FLAGS}") SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_CXX_FLAGS}") SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_CXX_FLAGS}")