2016-09-19 11:50:08 +08:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
2016-09-22 18:08:27 +08:00
|
|
|
|
2016-10-01 09:21:38 +08:00
|
|
|
macro(debug_message)
|
|
|
|
if(DEFINED PORT_DEBUG AND PORT_DEBUG)
|
|
|
|
message(STATUS "[DEBUG] ${ARGN}")
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2016-09-22 18:08:27 +08:00
|
|
|
#Detect .vcpkg-root to figure VCPKG_ROOT_DIR
|
|
|
|
SET(VCPKG_ROOT_DIR_CANDIDATE ${CMAKE_CURRENT_LIST_DIR})
|
|
|
|
while(IS_DIRECTORY ${VCPKG_ROOT_DIR_CANDIDATE} AND NOT EXISTS "${VCPKG_ROOT_DIR_CANDIDATE}/.vcpkg-root")
|
|
|
|
get_filename_component(VCPKG_ROOT_DIR_TEMP ${VCPKG_ROOT_DIR_CANDIDATE} DIRECTORY)
|
|
|
|
if (VCPKG_ROOT_DIR_TEMP STREQUAL VCPKG_ROOT_DIR_CANDIDATE) # If unchanged, we have reached the root of the drive
|
|
|
|
message(FATAL_ERROR "Could not find .vcpkg-root")
|
|
|
|
else()
|
|
|
|
SET(VCPKG_ROOT_DIR_CANDIDATE ${VCPKG_ROOT_DIR_TEMP})
|
|
|
|
endif()
|
|
|
|
endwhile()
|
|
|
|
|
|
|
|
set(VCPKG_ROOT_DIR ${VCPKG_ROOT_DIR_CANDIDATE})
|
2016-09-19 11:50:08 +08:00
|
|
|
|
|
|
|
list(APPEND CMAKE_MODULE_PATH ${VCPKG_ROOT_DIR}/scripts/cmake)
|
|
|
|
set(CURRENT_INSTALLED_DIR ${VCPKG_ROOT_DIR}/installed/${TARGET_TRIPLET} CACHE PATH "Location to install final packages")
|
|
|
|
set(DOWNLOADS ${VCPKG_ROOT_DIR}/downloads CACHE PATH "Location to download sources and tools")
|
|
|
|
set(PACKAGES_DIR ${VCPKG_ROOT_DIR}/packages CACHE PATH "Location to store package images")
|
|
|
|
set(BUILDTREES_DIR ${VCPKG_ROOT_DIR}/buildtrees CACHE PATH "Location to perform actual extract+config+build")
|
|
|
|
|
|
|
|
if(PORT)
|
|
|
|
set(CURRENT_BUILDTREES_DIR ${BUILDTREES_DIR}/${PORT})
|
|
|
|
set(CURRENT_PACKAGES_DIR ${PACKAGES_DIR}/${PORT}_${TARGET_TRIPLET})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2016-10-01 09:21:38 +08:00
|
|
|
if(CMD MATCHES "^BUILD$")
|
|
|
|
set(CMAKE_TRIPLET_FILE ${VCPKG_ROOT_DIR}/triplets/${TARGET_TRIPLET}.cmake)
|
|
|
|
if(NOT EXISTS ${CMAKE_TRIPLET_FILE})
|
|
|
|
message(FATAL_ERROR "Unsupported target triplet. Triplet file does not exist: ${CMAKE_TRIPLET_FILE}")
|
|
|
|
endif()
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2018-06-27 12:48:29 +08:00
|
|
|
if(NOT DEFINED CURRENT_PORT_DIR)
|
2016-09-19 11:50:08 +08:00
|
|
|
message(FATAL_ERROR "CURRENT_PORT_DIR was not defined")
|
|
|
|
endif()
|
|
|
|
set(TO_CMAKE_PATH "${CURRENT_PORT_DIR}" CURRENT_PORT_DIR)
|
|
|
|
if(NOT EXISTS ${CURRENT_PORT_DIR})
|
|
|
|
message(FATAL_ERROR "Cannot find port: ${PORT}\n Directory does not exist: ${CURRENT_PORT_DIR}")
|
|
|
|
endif()
|
|
|
|
if(NOT EXISTS ${CURRENT_PORT_DIR}/portfile.cmake)
|
|
|
|
message(FATAL_ERROR "Port is missing portfile: ${CURRENT_PORT_DIR}/portfile.cmake")
|
|
|
|
endif()
|
|
|
|
if(NOT EXISTS ${CURRENT_PORT_DIR}/CONTROL)
|
|
|
|
message(FATAL_ERROR "Port is missing control file: ${CURRENT_PORT_DIR}/CONTROL")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
unset(PACKAGES_DIR)
|
|
|
|
unset(BUILDTREES_DIR)
|
|
|
|
|
|
|
|
if(EXISTS ${CURRENT_PACKAGES_DIR})
|
2018-06-27 12:48:29 +08:00
|
|
|
file(GLOB FILES_IN_CURRENT_PACKAGES_DIR "${CURRENT_PACKAGES_DIR}/*")
|
|
|
|
if(FILES_IN_CURRENT_PACKAGES_DIR)
|
|
|
|
file(REMOVE_RECURSE ${FILES_IN_CURRENT_PACKAGES_DIR})
|
|
|
|
file(GLOB FILES_IN_CURRENT_PACKAGES_DIR "${CURRENT_PACKAGES_DIR}/*")
|
|
|
|
if(FILES_IN_CURRENT_PACKAGES_DIR)
|
|
|
|
message(FATAL_ERROR "Unable to empty directory: ${CURRENT_PACKAGES_DIR}\n Files are likely in use.")
|
|
|
|
endif()
|
|
|
|
endif()
|
2016-09-19 11:50:08 +08:00
|
|
|
endif()
|
|
|
|
file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR} ${CURRENT_PACKAGES_DIR})
|
|
|
|
|
2016-11-09 06:25:47 +08:00
|
|
|
include(${CMAKE_TRIPLET_FILE})
|
2017-07-28 18:57:05 +08:00
|
|
|
set(TRIPLET_SYSTEM_ARCH ${VCPKG_TARGET_ARCHITECTURE})
|
2016-09-19 11:50:08 +08:00
|
|
|
include(${CURRENT_PORT_DIR}/portfile.cmake)
|
2016-11-09 06:12:49 +08:00
|
|
|
|
|
|
|
set(BUILD_INFO_FILE_PATH ${CURRENT_PACKAGES_DIR}/BUILD_INFO)
|
|
|
|
file(WRITE ${BUILD_INFO_FILE_PATH} "CRTLinkage: ${VCPKG_CRT_LINKAGE}\n")
|
2017-02-01 10:31:19 +08:00
|
|
|
file(APPEND ${BUILD_INFO_FILE_PATH} "LibraryLinkage: ${VCPKG_LIBRARY_LINKAGE}\n")
|
|
|
|
|
|
|
|
if (DEFINED VCPKG_POLICY_DLLS_WITHOUT_LIBS)
|
|
|
|
file(APPEND ${BUILD_INFO_FILE_PATH} "PolicyDLLsWithoutLIBs: ${VCPKG_POLICY_DLLS_WITHOUT_LIBS}\n")
|
|
|
|
endif()
|
2017-02-08 09:02:57 +08:00
|
|
|
if (DEFINED VCPKG_POLICY_EMPTY_PACKAGE)
|
|
|
|
file(APPEND ${BUILD_INFO_FILE_PATH} "PolicyEmptyPackage: ${VCPKG_POLICY_EMPTY_PACKAGE}\n")
|
|
|
|
endif()
|
2017-03-04 11:09:24 +08:00
|
|
|
if (DEFINED VCPKG_POLICY_ONLY_RELEASE_CRT)
|
|
|
|
file(APPEND ${BUILD_INFO_FILE_PATH} "PolicyOnlyReleaseCRT: ${VCPKG_POLICY_ONLY_RELEASE_CRT}\n")
|
2017-03-04 11:00:48 +08:00
|
|
|
endif()
|
2017-05-23 13:00:02 +08:00
|
|
|
if (DEFINED VCPKG_POLICY_ALLOW_OBSOLETE_MSVCRT)
|
|
|
|
file(APPEND ${BUILD_INFO_FILE_PATH} "PolicyAllowObsoleteMsvcrt: ${VCPKG_POLICY_ALLOW_OBSOLETE_MSVCRT}\n")
|
|
|
|
endif()
|
2017-03-25 03:49:08 +08:00
|
|
|
if (DEFINED VCPKG_POLICY_EMPTY_INCLUDE_FOLDER)
|
|
|
|
file(APPEND ${BUILD_INFO_FILE_PATH} "PolicyEmptyIncludeFolder: ${VCPKG_POLICY_EMPTY_INCLUDE_FOLDER}\n")
|
|
|
|
endif()
|
2017-05-03 11:34:11 +08:00
|
|
|
if (DEFINED VCPKG_HEAD_VERSION)
|
|
|
|
file(APPEND ${BUILD_INFO_FILE_PATH} "Version: ${VCPKG_HEAD_VERSION}\n")
|
|
|
|
endif()
|
2016-10-01 09:21:38 +08:00
|
|
|
elseif(CMD MATCHES "^CREATE$")
|
|
|
|
file(TO_NATIVE_PATH ${VCPKG_ROOT_DIR} NATIVE_VCPKG_ROOT_DIR)
|
|
|
|
file(TO_NATIVE_PATH ${DOWNLOADS} NATIVE_DOWNLOADS)
|
|
|
|
if(EXISTS ports/${PORT}/portfile.cmake)
|
|
|
|
message(FATAL_ERROR "Portfile already exists: '${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}\\portfile.cmake'")
|
|
|
|
endif()
|
|
|
|
if(NOT FILENAME)
|
|
|
|
get_filename_component(FILENAME "${URL}" NAME)
|
|
|
|
endif()
|
|
|
|
string(REGEX REPLACE "(\\.(zip|gz|tar|tgz|bz2))+\$" "" ROOT_NAME ${FILENAME})
|
|
|
|
if(EXISTS ${DOWNLOADS}/${FILENAME})
|
|
|
|
message(STATUS "Using pre-downloaded: ${NATIVE_DOWNLOADS}\\${FILENAME}")
|
|
|
|
message(STATUS "If this is not desired, delete the file and ${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}")
|
|
|
|
else()
|
|
|
|
include(vcpkg_download_distfile)
|
2017-11-04 05:52:02 +08:00
|
|
|
set(_VCPKG_INTERNAL_NO_HASH_CHECK "TRUE")
|
|
|
|
vcpkg_download_distfile(ARCHIVE
|
|
|
|
URLS ${URL}
|
|
|
|
FILENAME ${FILENAME}
|
|
|
|
)
|
|
|
|
set(_VCPKG_INTERNAL_NO_HASH_CHECK "FALSE")
|
2016-10-01 09:21:38 +08:00
|
|
|
endif()
|
|
|
|
file(SHA512 ${DOWNLOADS}/${FILENAME} SHA512)
|
|
|
|
|
|
|
|
file(MAKE_DIRECTORY ports/${PORT})
|
|
|
|
configure_file(scripts/templates/portfile.in.cmake ports/${PORT}/portfile.cmake @ONLY)
|
|
|
|
configure_file(scripts/templates/CONTROL.in ports/${PORT}/CONTROL @ONLY)
|
|
|
|
|
|
|
|
message(STATUS "Generated portfile: ${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}\\portfile.cmake")
|
|
|
|
message(STATUS "Generated CONTROL: ${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}\\CONTROL")
|
|
|
|
message(STATUS "To launch an editor for these new files, run")
|
2017-05-08 17:16:49 +08:00
|
|
|
message(STATUS " .\\vcpkg edit ${PORT}")
|
2016-09-19 11:50:08 +08:00
|
|
|
endif()
|