Open edsavage opened 2 years ago
Suggestions:
cmake -P
dir /od
command and parse output.rc
directly (not via shell script), replace make_rc_defines.sh
with cmake commands (using native windows commands where necessary - or simply use a windows batch file) vcvarsall.bat
file and a minimal set_env.bat
file to set CPP_SRC_HOME
etc.
- date: use native “date /T” (requires extensions to be installed and parse out the year
For the date we could use the TIMESTAMP
feature of CMake's string
function: https://cmake.org/cmake/help/v3.19/command/string.html#timestamp
If we needed accurate timestamps on each sub-compilation step this wouldn't be acceptable, as it gets the date when the build system is generated, not when it's run. However, we're only getting the year to put in the copyright message, and each CI build will generate the build system from scratch, so CMake's string
and TIMESTAMP
are adequate for our needs and have the advantage of being completely platform-independent.
For the date we could use the
TIMESTAMP
feature of CMake'sstring
function:
This looks ideal. Accurate timestamps aren't required, in fact we only require the year.
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/tmp.sh "rc -nologo ${CPPFLAGS} ${RC_DEFINES} -Fo${_target}.res ${CMAKE_SOURCE_DIR}/mk/ml.rc")
I don't think we'd need to use a tmp.sh
Bash script to run rc
. rc
is a native Windows program - the resource compiler for Windows programs. So surely we could just run it directly?
In fact, CMake might even provide a more elegant way to run rc
. https://discourse.cmake.org/t/how-to-use-resource-files-rc-in-cmake/2628 alludes to it. This might be something to research for a future enhancement.
grep -n bash build.gradle 83:// Always do the C++ build using bash (Git bash on Windows)
The reason we're doing this is so that we can set up an environment using set_env.sh
. It's nice that we can have one script for all platforms - if we had a .sh
and a separate .bat
then it's likely that people would sometimes forget to keep them in sync.
This might be the hardest of all to move away from.
However, I still think it's worth gradually getting rid of the other places where we're unnecessarily using Git Bash functionality from CMake. Once the lower level locations are dealt with we might find we don't need as many environment variables.
Another thing we could look at is setting up some of the paths that are currently in set_env.sh
in CMakeLists.txt
. It's probably going to be a long-term iterative process but we can keep taking small steps in the right direction.
- 3rd_party.sh and pull-eigen.sh: rewrite using CMake scripting and call using
cmake -P
I think this would be good. Certainly 3rd_party.sh
seems to be getting run more often than it needs to be for iterative local rebuilds. Presumably we have it as a dependency for everything. This is true, but it still doesn't need to be run after every single minor code edit. It takes quite a long time on Linux where the PyTorch and MKL libraries are big.
The initial approach to migrating to a
CMake
build system has continued to assume the presence of a Unix like build environment. On Windows this requires the presence ofgit bash
and the minimal GNU toolset -MinGW
. It is desirable to lessen the dependency on such tools on Windows as it lowers the bar for developers on that platform and simplifies the setting up of the build environment.What follows is a list of places in the
CMake
build system that make calls tobash
or other Unix commands.lib/ver/CMakeLists.txt
Suggestions:
3rd_party/CMakeLists.txt:
cmake/compiler/vs2019.cmake
cmake/variables.cmake
cmake/functions.cmake
build.gradle