[CMake] 2.6.4: how to avoid -fPIC when cross compiling for an embedded target

Ingolf Steinbach ingolf.steinbach at googlemail.com
Fri Nov 6 11:09:05 EST 2009


Hi,

how can I avoid having -fPIC in the set of flags used during *linking*
when using a GCC based cross compiler? I use the following contents
for my toolchain file:

set(CMAKE_SYSTEM_NAME Generic)
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS OFF)
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_FIND_ROOT_PATH /some/path/here)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_C_COMPILER /path/to/cross_gcc)
set(CMAKE_C_FLAGS "-Wall -W")
set(CMAKE_SHARED_LIBRARY_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "")
set(CMAKE_SHARED_MODULE_C_FLAGS "")
set(CMAKE_SHARED_MODULE_CXX_FLAGS "")

Note that the compilation of the sources is preformed without -fPIC.
Only when linking the executable, there is a -fPIC directly between
the CMAKE_C_FLAGS and LINK_FLAGS.

Kind regards
Ingolf


More information about the CMake mailing list