[CMake] Accepted way to add "-fPIC" onto CMAKE_CXX_FLAGS?

Mathias Gaunard mathias.gaunard at ens-lyon.org
Mon Jun 18 18:54:16 EDT 2012


On 18/06/2012 23:09, Michael Jackson wrote:
> Linux really wants to have -fPIC for some of my code and I am trying to detect linux and then add this flag for my project but I am having no luck.
>
> if (LINUX)
> 	set(CMAKE_CXX_FLAGS ${CMAKE_CSS_FLAGS} "-fPIC")
> endif()
>
> Is this NOT the way I should be doing this?

You probably meant

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

Also, -fPIC should already be added when building shared libraries or 
modules.

Maybe you should build your code as a shared library rather than a 
static one.



More information about the CMake mailing list