zig/cmake/install.cmake
Eric Joldasov b59c722a3f
CMake: clean CMAKE_{SOURCE,BUILD}_DIR
Replace `CMAKE_SOURCE_DIR` and `CMAKE_BUILD_DIR` with different variables,
or in some cases just remove them.

For some function arguments, prepended `CMAKE_SOURCE_DIR` was removed without
replacement. This includes:
 * Sources for `add_library` and `add_executable` (`ZIG_CPP_SOURCES` and `ZIG_WASM2C_SOURCES`)
 * Inputs for `configure_file` and `target_include_directory`
 * For arguments above, CMake already prepends
   `CMAKE_CURRENT_SOURCE_DIR` to them by default, if they are relative paths.
   Additionaly, it was removed from arguments of commands that have `WORKING_DIRECTORY` set to
   `PROJECT_SOURCE_DIR`, they will be similarly converted by CMake for us.

Also:
 * Move project declaration to the top so that these variables are
available earlier.
 * Avoid calling "git" executable if ".git" directory does not exist.
 * Swap "--prefix" and `ZIG_BUILD_ARGS` arguments in cmake/install.cmake
   to match same "zig2 build" command in CMakeLists.txt and allow
   overriding "--prefix" argument

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2024-05-14 23:40:41 +05:00

28 lines
785 B
CMake

set(ZIG_INSTALL_ARGS build --prefix "${CMAKE_INSTALL_PREFIX}" ${ZIG_BUILD_ARGS})
execute_process(
COMMAND "${ZIG_EXECUTABLE}" ${ZIG_INSTALL_ARGS}
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
RESULT_VARIABLE _result)
if(_result)
message("::")
message(":: ERROR: ${_result}")
message(":: (execute_process)")
list(JOIN ZIG_INSTALL_ARGS " " s_INSTALL_LIBSTAGE2_ARGS)
message("::")
message(":: argv: ${ZIG_EXECUTABLE} ${s_INSTALL_LIBSTAGE2_ARGS}")
set(_args ${ZIG_EXECUTABLE} ${ZIG_INSTALL_ARGS})
list(LENGTH _args _len)
math(EXPR _len "${_len} - 1")
message("::")
foreach(_i RANGE 0 ${_len})
list(GET _args ${_i} _arg)
message(":: argv[${_i}]: ${_arg}")
endforeach()
message("::")
message(FATAL_ERROR)
endif()