[CMake] Get configuration-dependant LOCATION property

John Drescher drescherjm at gmail.com
Mon Oct 4 17:26:43 EDT 2010


On Mon, Oct 4, 2010 at 5:15 PM, Mateusz Loskot <mateusz at loskot.net> wrote:
> On 04/10/10 14:24, Michael Hertling wrote:
>> On 10/04/2010 10:53 AM, Mateusz Loskot wrote:
>>> On 04/10/10 07:33, J Decker wrote:
>>>> CMAKE_INSTALL_CONFIG_NAME I don't know if there's a simple flag like
>>>> 'project supports multiple targets' so I have an if(MSVC) set(
>>>> MULTI_TARGET) endif()  .... if( MULTI_TARGET ) Install( targets ...
>>>> ${CMAKE_INSTALL_CONFIG_NAME ) else() isntall( ... ${CMAKE_BUILD_TYPE}
>>>
>>>
>>> I need it before firing up install procedures.
>>> I build.
>>> I run tests (here I need to know location of build output per target).
>>
>> Have you already taken a look at ADD_TEST()'s generator expressions like
>> $<TARGET_FILE_DIR:tgt>? AFAIK, they've been introduced quite exactly to
>> meet requirements such as yours.
>
> Hmm, I've seen this expressions, but I'm not sure how it can be useful
> because the expressions are used to generate test input.
>
> My problem is about getting property to generate environment
> for test before it is executed:
>
> In one subtree of my sources, I have mylib target building mylib.dll
> In another subtree, I have test. Next, I build and run test:
>
> add_executable(mytest test.cpp)
>
> target_link_libraries(mytest mylib_import.lib)
>
> add_test(mytest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mytest)
>
> set_tests_properties(mytest PROPERTIES
>  ENVIRONMENT "PATH=c:\path\to\dir\with\mylib.dll\")
>
> I need to figure out this: "c:\path\to\dir\with\mylib.dll\"
>

If you are inside the CMakeLists.txt file that creates the shared
library then you have full access to the location of the .dll (it
should be in the same location of the import library) that is created
using the CMake variables (there are several of these). If you are in
some other application then put this path a UseProjectName.cmake for
your library.

John


More information about the CMake mailing list