Jump to content
  • Advertisement
Sign in to follow this  
elih1

anybody with cmake experience here

This topic is 3567 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I need to add reference to an external library to my project. I have two directories in which cmakelists.txt is placed. The first directory is for my static library , and the second directory for the dll module that is using the static library. How to add library dependencies in cmakelists.txt of the dll module so when the source code of the static library is changed the static library automatically is rebuilt and relinked to my dll project. The cmake documentation lacks of clarity for such fundamental future, also I can't find any primer on the web that is enough clear and understandable. Thanks

Share this post


Link to post
Share on other sites
Advertisement
This dependency should be implied when you link the static library to the dll, like so:

target_link_library( dll staticlibrary )

But you can also explicitely add a dependency to a target like this:

add_dependencies(target-name depend-target1 depend-target2 ...)

Share this post


Link to post
Share on other sites
Thank you for the reply
"This dependency should be implied when you link the static library to the dll, like so:

target_link_library( dll staticlibrary )"

Yes,but this line only specifies that the dll should link to the static .lib file,
and if the static library source files are changed but the static library is not build anew manually (that is the old static .lib file is not modified) this wont work when I rebuild my dll project i.e the dll project will still link with the old .lib file.so I practically want when the staticlib source changes that the static library is rebuilt and relinked when I build my dll project automatically, without the effort to manually rebuilt the static lib.

"But you can also explicitly add a dependency to a target like this:

add_dependencies(target-name depend-target1 depend-target2 ...)"

Whart the command actually means?
If I write as follows:
add_dependencies(Projectdll staticlib)
Does this actually mean that everytime before ProjectDll is build staticlib should be built first or is staticlib built only if its source files are changed? Also my staticlib is in another directory so can I add it to cmakelists of the dll project as dependency?

Share this post


Link to post
Share on other sites
Quote:
Original post by elih1
Whart the command actually means?
If I write as follows:
add_dependencies(Projectdll staticlib)
Does this actually mean that everytime before ProjectDll is build staticlib should be built first or is staticlib built only if its source files are changed? Also my staticlib is in another directory so can I add it to cmakelists of the dll project as dependency?


It is only build if there are changes since the last time it was build, IE: the source changes.

Yes, you can add projects in different directories as dependencies, but I think you should have a CMakeLists.txt on the top directory specifying the cmake project name, something like this:


PROJECT(YourProjectName)
ADD_SUBDIRECTORY(staticlib)
ADD_SUBDIRECTORY(Projectdll)


Share this post


Link to post
Share on other sites
Kwizatz is correct, you should have all your stuff in the same cmake project, even if said project is located in the parent directory and then includes the sub directories.

Don't think of it like cmake project = visual studio project. It's more like cmake project = visual studio solution, and subdirectory in cmake = visual studio project.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!