CMAKE_POSITION_INDEPENDENT_CODE causes "CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise" on Solaris
Sun Studio 12.2 through 12.4 have a dirty compile when using CMake and CMAKE_POSITION_INDEPENDENT_CODE
.
Our CMakeList.txt
enables -fPIC
for non-WIndows, non-i386 builds. -fPIC
is disabled for i386 due to register pressures and the GOT pointer.
Sun Studio 12.2
# Only set when cross-compiling, http://www.vtk.org/Wiki/CMake_Cross_Compiling
if (NOT (CMAKE_SYSTEM_VERSION AND CMAKE_SYSTEM_PROCESSOR))
set(CRYPTOPP_CROSS_COMPILE 1)
else()
set(CRYPTOPP_CROSS_COMPILE 0)
endif()
...
# We need the output 'uname -m' for Unix and Linux platform detection
if (NOT CRYPTOPP_CROSS_COMPILE)
set (UNAME_CMD "uname")
set (UNAME_ARG "-m")
execute_process(COMMAND ${UNAME_CMD} ${UNAME_ARG}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE UNAME_RESULT
OUTPUT_VARIABLE UNAME_MACHINE)
string(REGEX REPLACE "\n$" "" UNAME_MACHINE "${UNAME_MACHINE}")
endif()
...
if ((NOT CRYPTOPP_CROSS_COMPILE) AND (NOT (WINDOWS OR WINDOWS_STORE OR WINDOWS_PHONE)))
# Use Regex; match i386, i486, i586 and i686
if (NOT (${UNAME_MACHINE} MATCHES "i.86"))
SET(CMAKE_POSITION_INDEPENDENT_CODE 1)
endif()
endif()
And:
cryptopp-build$ rm -rf * && CXX=/opt/solstudio12.2/bin/CC cmake ../cryptopp
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is SunPro 5.11.0
-- Check for working C compiler: /bin/gcc
-- Check for working C compiler: /bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /opt/solstudio12.2/bin/CC
-- Check for working CXX compiler: /opt/solstudio12.2/bin/CC -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Compiler:
-- Flags: -native -m64 -template=no%extdef
--
-- The following OPTIONAL packages have been found:
* Threads
-- Configuring done
-- Generating done
-- Build files have been written to: /export/home/jwalton/cryptopp-build
And then:
cryptopp-build$ make
Scanning dependencies of target cryptopp-object
[ 1%] Building CXX object CMakeFiles/cryptopp-object.dir/cryptlib.cpp.o
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
[ 2%] Building CXX object CMakeFiles/cryptopp-object.dir/cpu.cpp.o
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
...
Scanning dependencies of target cryptopp-static
[ 91%] Linking CXX static library libcryptopp.a
[ 91%] Built target cryptopp-static
Scanning dependencies of target cryptest
[ 91%] Building CXX object CMakeFiles/cryptest.dir/test.cpp.o
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise
"/export/home/jwalton/cryptopp/wait.h", line 162: Warning: Identifier expected instead of "}".
1 Warning(s) detected.
[ 92%] Building CXX object CMakeFiles/cryptest.dir/bench1.cpp.o
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise
[ 93%] Building CXX object CMakeFiles/cryptest.dir/bench2.cpp.o
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise
[ 93%] Building CXX object CMakeFiles/cryptest.dir/validat1.cpp.o
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise
[ 94%] Building CXX object CMakeFiles/cryptest.dir/validat2.cpp.o
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise
[ 95%] Building CXX object CMakeFiles/cryptest.dir/validat3.cpp.o
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise
[ 96%] Building CXX object CMakeFiles/cryptest.dir/datatest.cpp.o
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise
[ 96%] Building CXX object CMakeFiles/cryptest.dir/regtest.cpp.o
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise
[ 97%] Building CXX object CMakeFiles/cryptest.dir/fipsalgt.cpp.o
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise
[ 98%] Building CXX object CMakeFiles/cryptest.dir/dlltest.cpp.o
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise
[ 99%] Building CXX object CMakeFiles/cryptest.dir/fipstest.cpp.o
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise
[ 99%] Linking CXX executable cryptest.exe
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
[ 99%] Built target cryptest
...
CMake version is:
$ cmake --version
cmake version 3.6.2
Sun Studio 12.3
Scanning dependencies of target cryptest
make -f CMakeFiles/cryptest.dir/build.make CMakeFiles/cryptest.dir/build
[ 91%] Building CXX object CMakeFiles/cryptest.dir/test.cpp.o
/opt/solarisstudio12.3/bin/CC -I/export/home/jwalton/cryptopp -native -m64 -template=no%extdef -fPIE -o CMakeFiles/cryptest.dir/test.cpp.o -c /export/home/jwalton/cryptopp/test.cpp
CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise
CC: Warning: -xchip=native detection failed, falling back to -xchip=generic
"/export/home/jwalton/cryptopp/wait.h", line 162: Warning: Identifier expected instead of "}".
1 Warning(s) detected.
....
Sun Studio 12.4
Scanning dependencies of target cryptest
make -f CMakeFiles/cryptest.dir/build.make CMakeFiles/cryptest.dir/build
[ 91%] Building CXX object CMakeFiles/cryptest.dir/test.cpp.o
/opt/solarisstudio12.4/bin/CC -I/export/home/jwalton/cryptopp -native -m64 -template=no%extdef -fPIE -o CMakeFiles/cryptest.dir/test.cpp.o -c /export/home/jwalton/cryptopp/test.cpp
CC: Warning: Option -fPIE passed to ld, if ld is invoked, ignored otherwise
"/export/home/jwalton/cryptopp/wait.h", line 162: Warning: Identifier expected instead of "}".
1 Warning(s) detected.
...