From ceca3e1e4618440c7639686015ee131adc4c1bae Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Mon, 26 Feb 2024 21:08:14 +0530 Subject: [PATCH] A preliminary addition to config.cmake to copy libraries. The function name is copy_lib3mf_libraries --- SDK/Examples/CppNew/CMakeLists.txt | 9 +++++++++ cmake/lib3mfConfig.cmake | 26 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/SDK/Examples/CppNew/CMakeLists.txt b/SDK/Examples/CppNew/CMakeLists.txt index 969bde05f..eda3d4662 100644 --- a/SDK/Examples/CppNew/CMakeLists.txt +++ b/SDK/Examples/CppNew/CMakeLists.txt @@ -27,30 +27,39 @@ add_definitions(-DTEXTURESPATH="${CMAKE_CURRENT_SOURCE_DIR}/../Files/Textures/") add_executable(Example_ColorCube Source/ColorCube.cpp) target_link_libraries(Example_ColorCube lib3mf::lib3mf) +copy_lib3mf_libraries(Example_ColorCube) add_executable(Example_Components Source/Components.cpp) target_link_libraries(Example_Components lib3mf::lib3mf) +copy_lib3mf_libraries(Example_Components) add_executable(Example_Converter Source/Converter.cpp) target_link_libraries(Example_Converter lib3mf::lib3mf) +copy_lib3mf_libraries(Example_Converter) add_executable(Example_Cube Source/Cube.cpp) target_link_libraries(Example_Cube lib3mf::lib3mf) +copy_lib3mf_libraries(Example_Cube) add_executable(Example_SecureCube Source/SecureCube.cpp) target_link_libraries(Example_SecureCube lib3mf::lib3mf) +copy_lib3mf_libraries(Example_SecureCube) add_executable(Example_ExtractInfo Source/ExtractInfo.cpp) target_link_libraries(Example_ExtractInfo lib3mf::lib3mf) +copy_lib3mf_libraries(Example_ExtractInfo) add_executable(Example_TextureCube Source/TextureCube.cpp) target_link_libraries(Example_TextureCube lib3mf::lib3mf) +copy_lib3mf_libraries(Example_TextureCube) add_executable(Example_Slice Source/Slice.cpp) target_link_libraries(Example_Slice lib3mf::lib3mf) +copy_lib3mf_libraries(Example_Slice) add_executable(Example_BeamLattice Source/BeamLattice.cpp) target_link_libraries(Example_BeamLattice lib3mf::lib3mf) +copy_lib3mf_libraries(Example_BeamLattice) if (${MSVC}) IF(${CMAKE_VERSION} VERSION_LESS 3.6.3) diff --git a/cmake/lib3mfConfig.cmake b/cmake/lib3mfConfig.cmake index f2d05358f..b33c45fc7 100644 --- a/cmake/lib3mfConfig.cmake +++ b/cmake/lib3mfConfig.cmake @@ -63,4 +63,28 @@ else() if(WIN32) set_property(TARGET lib3mf::lib3mf PROPERTY IMPORTED_IMPLIB "${lib3mf_LIBRARY_IMPORT}") endif() -endif() + + # Define a custom function to handle library copying + function(copy_lib3mf_libraries target) + if(TARGET ${target}) + if(APPLE) + # On macOS, copy .dylib files, preserving symlinks + add_custom_command(TARGET ${target} POST_BUILD + COMMAND sh -c "cp -P '${lib3mf_LIBRARY_DIR}/lib3mf.dylib'* '$'" + COMMENT "Copying all lib3mf library files to target directory on MacOS") + elseif(UNIX) + # On Unix-like systems (excluding macOS), copy .so files, preserving symlinks + add_custom_command(TARGET ${target} POST_BUILD + COMMAND sh -c "cp -P '${lib3mf_LIBRARY_DIR}/lib3mf.so'* '$'" + COMMENT "Copying all lib3mf.so* files to target directory on Linux") + else() + # On Windows, directly copy the .dll file without worrying about symlinks + add_custom_command(TARGET ${target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${lib3mf_LIBRARY}" "$" + COMMENT "Copying lib3mf.dll to target directory on Windows") + endif() + else() + message(WARNING "Target '${target}' not found. lib3mf library was not copied.") + endif() + endfunction() +endif() \ No newline at end of file