[CMake] setting different include_directories, link_directories, etc for different targets

Jakub Bican jakub.bican at gmail.com
Thu Mar 26 10:27:57 EDT 2009


Thanks.

Your proposal is very near where I am actually. The problem is here:

if ( ${ActivePlatform} STREQUAL "WinCE")
 set_target_properties( roj1_${ActivePlatform} ... ....)
elseif( ${ActivePlatform} STREQUAL "Win32")
 set_target_properties( roj1_${ActivePlatform} ... ....)
endif()

You can't simply set the LINK_DIRECTORIES and INCLUDE_DIRECTORIES for
each of those targets separately.

Just to illustrate: My platforms are WIN32, various PharLap ETS
versions, various RTX versions, UNIX/LINUX platforms. At the time, it
is supposed to compile UNIX plaforms on the target machines, but all
other are compiled undex Windows and should be developed/compiled
simultaneously.

If such use of CMake is not preferred - could anyone recommend a
better solution/tool?

Thanks again.

    Jakub


2009/3/26 Michael Jackson <mike.jackson at bluequartz.net>:
> Just thinking out loud here so none of this may work.
>
> You _could_ potentially have the same "target" compiled for 2 different
> platforms but this generally goes against the general CMake workflow. I
> guess you could have a tope level CMakeLists.txt file that has something
> like:
>
> # Make this a cache variable so it shows in the cmake-gui
> set (PLATFORMS "" CACHE STRING "Semi-colon separated list of Platforms to
> compile for")
>
> # Assume We have 3 subdirectories called Proj1, Proj2, Proj3
> set (MyProjects "Proj1;Proj2;Proj3")
>
> foreach(proj ${MyProjects})
>
>  foreach(platform ${platforms})
>     set(ActivePlatform ${platform} CACHE STRING "The current platform being
> configured" FORCE)
>     add_subdirectory(${proj} ${CMAKE_CURRENT_BINARY_DIR}_${platform} )
>
>  endforeach()
> endforeach()
>
>
> So the user needs to enter a list of platforms that they want to compile for
> as a semi-colon separated list. Now, in the CMakeLists.txt file in the
> "Project" subdirectories you will need something like the following:
>
>
> add_executable( Proj1_${ActivePlatform}  .... )
> target_link_libraries(Proj1_${ActivePlatform} ...)
>
> if ( ${ActivePlatform} STREQUAL "WinCE")
>  set_target_properties( roj1_${ActivePlatform} ... ....)
> elseif( ${ActivePlatform} STREQUAL "Win32")
>  set_target_properties( roj1_${ActivePlatform} ... ....)
> endif()
>
>
> All this is an abuse of how CMake is supposed to work in my opinion but may
> work for you.
>
> It is better to have a completely separate build directory for each type of
> build. Try the code and see if it will work for your situation.
>
> ---
> Mike Jackson                 www.bluequartz.net
>
>
>
> On Mar 26, 2009, at 9:46 AM, Kuba Bican wrote:
>
>> Thanks for quick answers.
>>
>> So one of the basic problems is that it is not possible to build the
>> same file several times in different targets? (Because the object
>> files would collide?) Then it makes me sense that the properties can
>> be set on directories and not on targets.
>>
>> OK, I can configure a separate project for each platform. For that it
>> would be helpful to have:
>> * multi-choice option in CMake to select from available platforms. Or
>> is there some good workaround if multi-choice options are not
>> available.
>> * and finally, to somehow include all generated projects in single
>> solution. Or such thing has to be done manually?
>>
>> Thanks again. Regards,
>>
>>   Jakub
>>
>>
>>
>> 2009/3/26 Denis Scherbakov <denis_scherbakov at yahoo.com>:
>>>
>>> Jakub,
>>>
>>> I don't really understand, how it is possible, to share the same build
>>> directory with WIN32 object files and say Sparc-Solaris?
>>>
>>> Even, if you only talk about windows variations, how will you
>>> distinguish, file WindowUtilApp.obj was compiled for WinXP or WinCE?
>>>
>>> At build time - it is NOT possible to share build directories. At install
>>> time - you can specify common installation directory for all build trees,
>>> say C:\Project\BIN and perform installation of executables there, but you'll
>>> have to make sure that executable names still differ. Otherwise they will
>>> overwrite each other.
>>>
>>> Denis
>>>
>>>
>>>> Yes, this is one of the possibilities which does not solve
>>>> the problem
>>>> very nice ... or is it possible to have the final generated
>>>> projects
>>>> in one solution, with one "BUILD_ALL" and
>>>> "RUN_TESTS" and all the
>>>> things around?
>>>
>>>
>>>
>>>
>>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list