[CMake] Way to use precompilation directive on cmake and conditionnal linking

Nadir SOUALEM nadir.soualem at irisa.fr
Tue Mar 24 11:55:53 EDT 2009


Tyler Roscoe wrote:
> On Tue, Mar 24, 2009 at 09:18:01AM +0100, Nadir SOUALEM wrote:
>   
>> I would like to use precompilation directive such NO_OPENGL
>> Is there a way to use it with this command line ?
>> cmake -DCMAKE_BUILD_TYPE=Debug
>>
>> or must i use something like:
>> cmake -DCMAKE_BUILD_TYPE=Debug -DWITH_OPENGL=0
>>
>> with an if statement:
>> if(NOT WITH_OPENGL)
>> ADD_DEFINITIONS(-DNO_OPENGL)
>> endif
>>     
>
> I'm not sure I understand this question, but that solution looks
> reasonable. Maybe what you want is more like:
>
> if (WITH_OPENGL)
>     add_definitions (-DOPENGL)
> else (WITH_OPENGL)
>     add_definitions (-DNO_OPENGL)
> endif (WITH_OPENGL)
>
>   
>> How to make a conditional linking, for example if NO_OPENGL
>>
>>
>> TARGET_LINK_LIBRARIES(MyExe
>> A
>> B
>> C)
>>
>> else
>>
>> TARGET_LINK_LIBRARIES(MyExe
>> A
>> B
>> C
>> GL
>> GLU
>> GLUT)
>>     
>
> In my projects I do something like:
>
> set (MyExe_LINK_LIBS
>     A
>     B
>     C)
>
> if (WITH_OPENGL)
>     set (MyExe_LINK_LIBS
>         ${MyExe_LINK_LIBS}
>         GL
>         GLU
>         GLUT)
> endif (WITH_OPENGL)
>
> target_link_libraries(MyExe ${MyExe_LINK_LIBS})
>
>
> hth,
> tyler
>   
Thank you Tyler , i use the same method for linking, but i thought there 
was a better way than:

if (WITH_OPENGL)
add_definitions (-DOPENGL)
else (WITH_OPENGL)
add_definitions (-DNO_OPENGL)
endif (WITH_OPENGL)

for preprocessing vars ....

Thank You Tyler

-- 
Nadir SOUALEM
Ingénieur INRIA - Équipe SAGE
INRIA-IRISA . campus de Beaulieu . F - 35 042 Rennes Cedex 
Tel: 02 99 84 71 47



More information about the CMake mailing list