Have CMake use the CXX and CXXFLAGS while driving?

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}") 
0
gcc linker solaris cmake
source share

No one has answered this question yet.

See similar questions:

fifty
CMake: How to set LDFLAGS in CMakeLists.txt?
eighteen
Difference between add_compile_options and SET (CMAKE_CXX_FLAGS ...)

or similar:

48
cmake CFLAGS CXXFLAGS modification
23
CMake and Static Binding
7
Linking C and CXX Files in CMake
2
CMake (Android Toolchain) - Link execution error: there is no such file or directory
one
Enable mongocxx drivers with Cmake results with undefined methods on Ubuntu
one
build static linked clang with gcc 4.8.3 on centos
0
CMake Undefined characters using the external poco library
0
Ffmpeg communication problems using CMake
0
Error using cmake on vk_chopper
0
Creating CMake executables using multiple libraries

All Articles