Skip to content

Commit

Permalink
chore(matlab): reorganize installation folder structure post-build
Browse files Browse the repository at this point in the history
  • Loading branch information
yliu7949 committed Dec 14, 2024
1 parent 74c1fb9 commit 40e092d
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 56 deletions.
2 changes: 1 addition & 1 deletion matlab/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ spglib
build/

_test*
_spglib_test.cpp
install/
**/*.zip
26 changes: 19 additions & 7 deletions matlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ find_package(Matlab REQUIRED)

# Set the root path for the Spglib library
set(SPGLIB_ROOT "../install")
set(Spglib_DIR "../install/lib/cmake/Spglib")
find_package(Spglib REQUIRED)

# Add header file path
Expand All @@ -42,14 +43,25 @@ file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/install/+spglib")
# Define MATLAB .m files to be copied
file(GLOB MATLAB_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.m")

# Add a custom command to copy the generated MEX file to the install directory after build
# Add a custom command to copy the generated MEX file and .m files to the install directory after build
add_custom_command(TARGET spglib_mex POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:spglib_mex>" "${CMAKE_CURRENT_SOURCE_DIR}/install/+spglib/"
COMMENT "Copying MEX file to install directory"
COMMAND ${CMAKE_COMMAND} -E copy ${MATLAB_FILES} "${CMAKE_CURRENT_SOURCE_DIR}/install/+spglib/"
COMMENT "Copying MEX file and MATLAB .m files to install directory"
)

# Add a custom command to copy MATLAB .m files to the install directory after build
add_custom_command(TARGET spglib_mex POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${MATLAB_FILES} "${CMAKE_CURRENT_SOURCE_DIR}/install/"
COMMENT "Copying MATLAB .m files to install directory"
)
# Allow the option to decide whether to compile _spglib_test.cpp
option(BUILD_TEST_EXECUTABLE "Build test executable" OFF)

# If the switch is turned on, add a target to compile _spglib_test.cpp
if(BUILD_TEST_EXECUTABLE)
set(TEST_SOURCE_FILES _spglib_test.cpp)
add_executable(test_executable ${TEST_SOURCE_FILES})
set_target_properties(test_executable PROPERTIES
OUTPUT_NAME "_test"
PREFIX ""
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
target_link_libraries(test_executable PRIVATE Spglib::symspg)
target_include_directories(test_executable PRIVATE "${SPGLIB_ROOT}/include")
endif()
4 changes: 2 additions & 2 deletions matlab/Spglib.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

function error_code = getErrorCode()
error_code = spglib.symspg('spg_get_error_code');
SpglibError(error_code);
spglib.SpglibError(error_code);
end

function error_message = getErrorMessage(error_code)
arguments
error_code SpglibError = 0
error_code spglib.SpglibError = 0
end

error_message = spglib.symspg('spg_get_error_message', double(error_code));
Expand Down
Loading

0 comments on commit 40e092d

Please sign in to comment.