cmake: support `make` and `make install`

- `make` or `ninja` will not build but not install
- `make install` or `ninja install` will build __and__ install

Only for build system generator Visual Studio, specify the following
to disable installation of lib files:

    ZIG_SKIP_INSTALL_LIB_FILES=ON
master
Michael Dusan 2020-01-16 18:56:13 -05:00
parent bac27731e3
commit cd062b08d0
No known key found for this signature in database
GPG Key ID: ED4C5BA849FA1B74
1 changed files with 20 additions and 9 deletions

View File

@ -45,7 +45,6 @@ message("Configuring zig version ${ZIG_VERSION}")
set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)")
set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries")
set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL "Disable copying lib/ files to install prefix")
set(ZIG_ENABLE_MEM_PROFILE off CACHE BOOL "Activate memory usage instrumentation")
if(ZIG_STATIC)
@ -608,19 +607,26 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
else()
set(LIBUSERLAND_RELEASE_MODE "true")
endif()
if(ZIG_SKIP_INSTALL_LIB_FILES)
set(ZIG_BUILD_INSTALL_STEP "")
else()
set(ZIG_BUILD_INSTALL_STEP "install")
endif()
add_custom_target(zig_build_libuserland ALL
COMMAND zig0 build
set(BUILD_LIBUSERLAND_COMMAND zig0 build
--override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
libuserland ${ZIG_BUILD_INSTALL_STEP}
"-Doutput-dir=${CMAKE_BINARY_DIR}"
"-Drelease=${LIBUSERLAND_RELEASE_MODE}"
"-Dlib-files-only"
--prefix "${CMAKE_INSTALL_PREFIX}"
libuserland
)
# When using Visual Studio build system generator we default to libuserland install.
if(MSVC)
set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL "Disable copying lib/ files to install prefix")
if(NOT ZIG_SKIP_INSTALL_LIB_FILES)
set(BUILD_LIBUSERLAND_COMMAND ${BUILD_LIBUSERLAND_COMMAND} install)
endif()
endif()
add_custom_target(zig_build_libuserland ALL
COMMAND ${BUILD_LIBUSERLAND_COMMAND}
DEPENDS zig0
BYPRODUCTS "${LIBUSERLAND}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
@ -638,4 +644,9 @@ elseif(MINGW)
target_link_libraries(zig ntdll)
endif()
add_dependencies(zig zig_build_libuserland)
install(TARGETS zig DESTINATION bin)
# CODE has no effect with Visual Studio build system generator
install(CODE "message(\"-- Installing: /opt/zig/lib\")")
install(CODE "execute_process(COMMAND ${BUILD_LIBUSERLAND_COMMAND} install)")