Skip to content

Commit

Permalink
cmake: separate installing and building (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
BratishkaErik authored and andrewrk committed Oct 18, 2022
1 parent 14c173b commit 1013212
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
21 changes: 10 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1017,9 +1017,9 @@ if("${ZIG_EXECUTABLE}" STREQUAL "")
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
if (WIN32)
set(ZIG_EXECUTABLE "${zig2_BINARY_DIR}/zig2.exe")
set(ZIG_EXECUTABLE "${CMAKE_BINARY_DIR}/zig2.exe")
else()
set(ZIG_EXECUTABLE "${zig2_BINARY_DIR}/zig2")
set(ZIG_EXECUTABLE "${CMAKE_BINARY_DIR}/zig2")
endif()
else()
add_custom_command(
Expand All @@ -1045,15 +1045,8 @@ elseif(MINGW)
target_link_libraries(zig2 ntdll)
endif()

# Dummy install command so that the "install" target is not missing.
# This is redundant from the "stage3" custom target below.
if(NOT ZIG_SKIP_INSTALL_LIB_FILES)
install(FILES "lib/compiler_rt.zig" DESTINATION "lib/zig")
endif()

set(ZIG_INSTALL_ARGS "build"
set(ZIG_BUILD_ARGS "build"
--zig-lib-dir "${CMAKE_SOURCE_DIR}/lib"
--prefix "${CMAKE_INSTALL_PREFIX}"
"-Dconfig_h=${ZIG_CONFIG_H_OUT}"
"-Denable-llvm"
"-Denable-stage1"
Expand All @@ -1067,8 +1060,14 @@ set(ZIG_INSTALL_ARGS "build"
)

add_custom_target(stage3 ALL
COMMAND zig2 ${ZIG_INSTALL_ARGS}
COMMAND zig2 ${ZIG_BUILD_ARGS}
DEPENDS zig2
COMMENT STATUS "Building stage3"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)

install(CODE "set(ZIG_EXECUTABLE \"${ZIG_EXECUTABLE}\")")
install(CODE "set(ZIG_BUILD_ARGS \"${ZIG_BUILD_ARGS}\")")
install(CODE "set(CMAKE_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\")")
install(CODE "set(CMAKE_SOURCE_DIR \"${CMAKE_SOURCE_DIR}\")")
install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/install.cmake")
24 changes: 24 additions & 0 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set(ZIG_INSTALL_ARGS ${ZIG_BUILD_ARGS} --prefix "${CMAKE_INSTALL_PREFIX}")
execute_process(COMMAND "${ZIG_EXECUTABLE}" ${ZIG_INSTALL_ARGS} WORKING_DIRECTORY "${CMAKE_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()

0 comments on commit 1013212

Please sign in to comment.