Skip to content

Commit

Permalink
A preliminary addition to config.cmake to copy libraries. The functio…
Browse files Browse the repository at this point in the history
…n name is copy_lib3mf_libraries
  • Loading branch information
vijaiaeroastro authored and gangatp committed Apr 15, 2024
1 parent 822796f commit ceca3e1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
9 changes: 9 additions & 0 deletions SDK/Examples/CppNew/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 25 additions & 1 deletion cmake/lib3mfConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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'* '$<TARGET_FILE_DIR:${target}>'"
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'* '$<TARGET_FILE_DIR:${target}>'"
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}" "$<TARGET_FILE_DIR:${target}>"
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()

0 comments on commit ceca3e1

Please sign in to comment.