[CMake] -pipe, -g and -fPIC on WIN32

Brandon Van Every bvanevery at gmail.com
Wed Nov 7 11:45:22 EST 2007


On Nov 7, 2007 6:35 AM, Salvatore Iovene
<salvatore.iovene+cmake at googlemail.com> wrote:
> Hi list,
> I'm doing the following:
>
> CHECK_CXX_COMPILER_FLAG("-fPIC" HAVE_FPIC_FLAG)
>
> IF(HAVE_FPIC_FLAG)
>   SET(${CMAKE_CXX_FLAGS} "${CMAKE_CXX_FLAGS} -fPIC")
> ENDIF(HAVE_FPIC_FLAG)
>
> And the same with -pipe and -g.
>
> This works fine in Linux, but when trying on WIN32 with Visual Studio
> command line prompt, I get that the check for the flag succedes, but
> then the compiler options are actually -pipe -g -fPIC and the compiler
> issues a warning about ignoring those unknown options.
>
> What is the right way of doing this?
> Thanks!

I say it's bugged.  CheckCCompilerFlag.cmake is passing your flag in
CMAKE_REQUIRED_DEFINITIONS.  It should be passing it in
CMAKE_REQUIRED_FLAGS.  CHECK_C_COMPILER_FLAG calls
CHECK_C_SOURCE_COMPILES, which ultimately invokes a TRY_COMPILE.  Your
flag should be passed to CMAKE_FLAGS and it isn't.  The only other
possibility I see is that all the docs are wrong when they say that
COMPILE_DEFINITIONS is for -D flags.


Cheers,
Brandon Van Every


More information about the CMake mailing list