Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake question #2

Open
halbux opened this issue Mar 15, 2021 · 4 comments
Open

cmake question #2

halbux opened this issue Mar 15, 2021 · 4 comments

Comments

@halbux
Copy link

halbux commented Mar 15, 2021

Hi @matsievskiysv

I am absolutely enjoying using the cmake you provided for sparselizard, thanks again so much for that! :)

Everything is working perfectly with the symlink you created for the main.cpp and all other .msh files from sparselizard/simulation/default to build/simulation/default.

One minor issue however is that the symlink is done during the cmake config "cmake .." step... which means that if the user adds another .msh file to sparselizard/simulation/default then it is not made available in build/simulation/default by the cmake--build call .
Is there a way to force cmake to do the symlink again at every build call also and not only at the initial cmake .. call?

Alex

@matsievskiysv
Copy link
Owner

I've found this so question that describes similar functionality. I'll try to implement it in a bit.

@matsievskiysv
Copy link
Owner

matsievskiysv commented Mar 15, 2021

@halbux you may use this command for the mesh files:

function(custom_build_copy_file TARGET FROMDIRS TODIR GLOBS)
    foreach(d IN LISTS FROMDIRS)
        foreach(g IN LISTS GLOBS)
	    add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${d}/${g}" ${TODIR}/${DEST})
        endforeach()
    endforeach()
endfunction(custom_build_copy_file)

It has limitations though:

  • it copies files instead of making links
  • you have to trigger target rebuilding (by modifying or touching main.c)

Use it like other copy commands:

custom_build_copy_file(sparselizard ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} "*.msh")

@halbux
Copy link
Author

halbux commented Mar 15, 2021

Thanks a lot for that! Hm, I loved your symlink, sometimes meshes can be very large and you don't want to copy them. The touch however should be ok since we can assume the user changes the main.cpp when adding new mesh files. But symlink is definitely better so I'll leave it like it is.

@matsievskiysv
Copy link
Owner

function(custom_build_copy_file TARGET FROMDIRS TODIR GLOBS)
    foreach(d IN LISTS FROMDIRS)
        foreach(g IN LISTS GLOBS)
	    add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND find "${d}" -maxdepth 1 -iname '${g}' "|" xargs -I '{}' ln -fs '{}' ${TODIR} USES_TERMINAL)
        endforeach()
    endforeach()
endfunction(custom_build_copy_file)

This version creates symlinks but it uses shell commands, so it's not as portable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants