SPTAG
SPTAG copied to clipboard
cmake: build executables, libraries and bindings files on `obj` dir
After building SPTAG and then running make clean and deleting the obj directory, the files generated by the build (including swig bindings files) are still present.
None
None/sptag-indexbuilder
None/sptag-server
None/sptag-client
None/_SPTAG.so
None/SPTAG.py
None/test
None/sptag-aggregator
None/SPTAGClient.py
None/libSPTAGLib.so
None/_SPTAGClient.so
None/libSPTAGLibStatic.a
None/sptag-indexsearcher
None/libDistanceUtils.a
Wrappers/inc/ClientInterface_pwrap.cpp
Wrappers/inc/CoreInterface_pwrap.cpp
Wrappers/inc/SPTAG.py
Wrappers/inc/SPTAGClient.py
The .gitignore file already ignores some of these files:
/Wrappers/inc/*wrap.*
/Wrappers/inc/*.py
/Wrappers/inc/*.java
Since these files are generated during the build, they should be output to the build dir (usually obj).
I noticed that on Windows, the CMakeLists.txt
$ grep -C4 CMAKE_BINARY_DIR CMakeLists.txt
if (WIN32)
set(Boost_USE_STATIC_LIBS ON)
set(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR})
set (EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR})
else()
set (LIBRARY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/${CMAKE_BUILD_TYPE}/")
set (EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/${CMAKE_BUILD_TYPE}/")
endif()
I suggest that the output directories be set to ${CMAKE_BINARY_DIR} and that the swig bindings be built in ${CMAKE_BINARY_DIR} too.
To be clear on the swig changes, in Wrappers/CMakeLists.txt, every reference to ${PROJECT_SOURCE_DIR}/Wrappers/inc/*wrap* or ${PROJECT_SOURCE_DIR}/Wrappers/inc/*.{py,java,cs} files need to be replaced with references to ${CMAKE_BINARY_DIR}/*wrap* and ${CMAKE_BINARY_DIR}/*.{py,java,cs}.
I have tested that the swig and output path changes fix this issue.
In addition, the ADDITIONAL_CLEAN_FILES property needs to be set using set_property to the corresponding *wrap* and .{py,java,cs} for each of the targets in Wrappers/CMakeLists.txt, so that make clean within the obj directory works correctly. The property setting looks like this:
set_property(TARGET _SPTAG PROPERTY ADDITIONAL_CLEAN_FILES ${CMAKE_BINARY_DIR}/CoreInterface_pwrap.cpp ${CMAKE_BINARY_DIR}/SPTAG.py)