diff options
Diffstat (limited to 'Mk/Uses/cmake.mk')
-rw-r--r-- | Mk/Uses/cmake.mk | 128 |
1 files changed, 79 insertions, 49 deletions
diff --git a/Mk/Uses/cmake.mk b/Mk/Uses/cmake.mk index eeaa2fda20f7..4129f0f341fc 100644 --- a/Mk/Uses/cmake.mk +++ b/Mk/Uses/cmake.mk @@ -2,10 +2,13 @@ # # Feature: cmake # Usage: USES=cmake or USES=cmake:ARGS -# Valid ARGS: insource, run, noninja, testing +# Valid ARGS: indirect, insource, noninja, run, testing # ARGS description: +# indirect do not run cmake for configure step, only add build dependency. +# This should be set only for ports which use other build systems, +# e.g. pep517 or meson, but rely internally on cmake. # insource do not perform an out-of-source build -# noninja don't use ninja instead of make +# noninja do not use ninja instead of make # Setting this should be an exception, and hints to an issue # inside the ports build system. # A few corner cases never use ninja, and are handled, to reduce @@ -17,6 +20,7 @@ # testing add the test target based on ctest # Additionally, CMAKE_TESTING_ON, CMAKE_TESTING_OFF, CMAKE_TESTING_ARGS, CMAKE_TESTING_TARGET # can be defined to override the default values. +# _internal Not to be used by any other ports than the ones created from the release-tarball of cmake # # # Additional variables that affect cmake behaviour: @@ -30,6 +34,7 @@ # CMAKE_OFF Appends -D<var>:bool=OFF to the CMAKE_ARGS. # CMAKE_ARGS - Arguments passed to cmake # Default: see below +# Variables for ports which use cmake for configure # CMAKE_BUILD_TYPE - Type of build (cmake predefined build types). # Projects may have their own build profiles. # CMake supports the following types: Debug, @@ -37,17 +42,28 @@ # Debug and Release profiles respect system # CFLAGS, RelWithDebInfo and MinSizeRel will set # CFLAGS to "-O2 -g" and "-Os -DNDEBUG". -# Default: Release, if WITH_DEBUG is not set, -# Debug otherwise +# Default: Release, if neither WITH_DEBUG nor WITH_DEBUGINFO is set, +# RelWithDebInfo, if WITH_DEBUGINFO is set, +# Debug, if WITH_DEBUG is set. # CMAKE_SOURCE_PATH - Path to the source directory # Default: ${WRKSRC} +# Variables for ports which use cmake for testing +# CMAKE_TESTING_ARGS - Additional arguments passed to cmake on test target. +# CMAKE_TESTING_ON Appends -D<var>:bool=ON to the CMAKE_TESTING_ARGS. +# Default: BUILD_TESTING +# CMAKE_TESTING_OFF Appends -D<var>:bool=OFF to the CMAKE_TESTING_ARGS. +# Default: empty +# CMAKE_TESTING_TARGET - Name of the test target. Default: test # # MAINTAINER: kde@FreeBSD.org .if !defined(_INCLUDE_USES_CMAKE_MK) _INCLUDE_USES_CMAKE_MK= yes -_valid_ARGS= insource run noninja testing +_valid_ARGS= indirect insource noninja run testing _internal + +_CMAKE_VERSION= 3.28.3 +CMAKE_BIN= ${LOCALBASE}/bin/cmake # Sanity check . for arg in ${cmake_ARGS} @@ -56,33 +72,33 @@ IGNORE= Incorrect 'USES+= cmake:${cmake_ARGS}' usage: argument [${arg}] is not r . endif . endfor -CMAKE_BIN= ${LOCALBASE}/bin/cmake -BUILD_DEPENDS+= ${CMAKE_BIN}:devel/cmake +. if !empty(cmake_ARGS:M_internal) +# _internal is intended only for devel/cmake-core +MASTER_SITES?= https://github.com/Kitware/CMake/releases/download/v${DISTVERSION}/ \ + https://www.cmake.org/files/v${DISTVERSION}/ +. else +BUILD_DEPENDS+= ${CMAKE_BIN}:devel/cmake-core -. if ${cmake_ARGS:Mrun} -RUN_DEPENDS+= ${CMAKE_BIN}:devel/cmake -. endif +. if !empty(cmake_ARGS:Mrun) +RUN_DEPENDS+= ${CMAKE_BIN}:devel/cmake-core +. endif -. if defined(WITH_DEBUG) +. if defined(WITH_DEBUG) CMAKE_BUILD_TYPE?= Debug -. else +. elif defined(WITH_DEBUGINFO) +CMAKE_BUILD_TYPE?= RelWithDebInfo +. else CMAKE_BUILD_TYPE?= Release -. endif #defined(WITH_DEBUG) - -PLIST_SUB+= CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:tl}" - -. if defined(STRIP) && ${STRIP} != "" && !defined(WITH_DEBUG) -INSTALL_TARGET?= install/strip -. endif +. endif #defined(WITH_DEBUG) CMAKE_ARGS+= -DCMAKE_C_COMPILER:STRING="${CC}" \ -DCMAKE_CXX_COMPILER:STRING="${CXX}" \ -DCMAKE_C_FLAGS:STRING="${CFLAGS}" \ -DCMAKE_C_FLAGS_DEBUG:STRING="${CFLAGS}" \ - -DCMAKE_C_FLAGS_RELEASE:STRING="${CFLAGS}" \ + -DCMAKE_C_FLAGS_RELEASE:STRING="${CFLAGS} -DNDEBUG" \ -DCMAKE_CXX_FLAGS:STRING="${CXXFLAGS}" \ -DCMAKE_CXX_FLAGS_DEBUG:STRING="${CXXFLAGS}" \ - -DCMAKE_CXX_FLAGS_RELEASE:STRING="${CXXFLAGS}" \ + -DCMAKE_CXX_FLAGS_RELEASE:STRING="${CXXFLAGS} -DNDEBUG" \ -DCMAKE_EXE_LINKER_FLAGS:STRING="${LDFLAGS}" \ -DCMAKE_MODULE_LINKER_FLAGS:STRING="${LDFLAGS}" \ -DCMAKE_SHARED_LINKER_FLAGS:STRING="${LDFLAGS}" \ @@ -90,80 +106,94 @@ CMAKE_ARGS+= -DCMAKE_C_COMPILER:STRING="${CC}" \ -DCMAKE_BUILD_TYPE:STRING="${CMAKE_BUILD_TYPE}" \ -DTHREADS_HAVE_PTHREAD_ARG:BOOL=YES \ -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=YES \ - -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON + -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ + -DFETCHCONTENT_FULLY_DISCONNECTED:BOOL=ON # Handle the option-like CMAKE_ON and CMAKE_OFF lists. -. for _bool_kind in ON OFF -. if defined(CMAKE_${_bool_kind}) +. for _bool_kind in ON OFF +. if defined(CMAKE_${_bool_kind}) CMAKE_ARGS+= ${CMAKE_${_bool_kind}:C/.*/-D&:BOOL=${_bool_kind}/} -. endif -. endfor +. endif +. endfor CMAKE_INSTALL_PREFIX?= ${PREFIX} -. if defined(BATCH) || defined(PACKAGE_BUILDING) +. if defined(BATCH) || defined(PACKAGE_BUILDING) CMAKE_NOCOLOR= yes -. endif +. endif -. if defined(CMAKE_NOCOLOR) +. if defined(CMAKE_NOCOLOR) CMAKE_ARGS+= -DCMAKE_COLOR_MAKEFILE:BOOL=OFF +. endif +. endif + +. if empty(cmake_ARGS:Mindirect) +. if defined(STRIP) && ${STRIP} != "" && !defined(WITH_DEBUG) && !defined(WITH_DEBUGINFO) +INSTALL_TARGET?= install/strip +. endif . endif +# Use cmake for configure stage and for testing +. if empty(cmake_ARGS:M_internal) && empty(cmake_ARGS:Mindirect) +PLIST_SUB+= CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:tl}" + _CMAKE_MSG= "===> Performing in-source build" CMAKE_SOURCE_PATH?= ${WRKSRC} -. if empty(cmake_ARGS:Minsource) +. if empty(cmake_ARGS:Minsource) _CMAKE_MSG= "===> Performing out-of-source build" CONFIGURE_WRKSRC= ${WRKDIR}/.build BUILD_WRKSRC?= ${CONFIGURE_WRKSRC} INSTALL_WRKSRC?= ${CONFIGURE_WRKSRC} TEST_WRKSRC?= ${CONFIGURE_WRKSRC} -. endif +. endif # By default we use the ninja generator. # Except, if cmake:run is set (cmake not wanted as generator) # fortran is used, as the ninja-generator does not handle it. # or if CONFIGURE_WRKSRC does not match BUILD_WRKSRC or INSTALL_WRKSRC # as the build.ninja file won't be where ninja expects it. -. if empty(cmake_ARGS:Mnoninja) && empty(cmake_ARGS:Mrun) && empty(USES:Mfortran) -. if "${CONFIGURE_WRKSRC}" == "${BUILD_WRKSRC}" && "${CONFIGURE_WRKSRC}" == "${INSTALL_WRKSRC}" +. if empty(cmake_ARGS:Mnoninja) && empty(cmake_ARGS:Mrun) && empty(USES:Mfortran) +. if "${CONFIGURE_WRKSRC}" == "${BUILD_WRKSRC}" && "${CONFIGURE_WRKSRC}" == "${INSTALL_WRKSRC}" # USES=gmake sets MAKE_CMD and ninja.mk does too (it also messes with MAKEFILE and MAKE_CMD). -. if ! empty(USES:Mgmake) +. if ! empty(USES:Mgmake) BROKEN= USES=gmake is incompatible with cmake's ninja-generator (try cmake:noninja) -. endif +. endif # USES=emacs appends EMACS=<path> to MAKE_ARGS, which then get passed to ninja. # Since ninja doesn't support that kind of variable-setting on the command-line, # it errors out. -. if ! empty(USES:Memacs) +. if ! empty(USES:Memacs) BROKEN= USES=emacs is incompatible with cmake's ninja-generator (try cmake:noninja) -. endif +. endif . include "${USESDIR}/ninja.mk" +. endif . endif -. endif -. if !target(do-configure) +. if !target(do-configure) do-configure: @${ECHO_MSG} ${_CMAKE_MSG} ${MKDIR} ${CONFIGURE_WRKSRC} - @cd ${CONFIGURE_WRKSRC}; ${SETENV} ${CONFIGURE_ENV} ${CMAKE_BIN} ${CMAKE_ARGS} ${CMAKE_SOURCE_PATH} -. endif + @cd ${CONFIGURE_WRKSRC}; ${SETENVI} ${WRK_ENV} ${CONFIGURE_ENV} ${CMAKE_BIN} \ + ${CMAKE_ARGS} ${CMAKE_SOURCE_PATH} +. endif -. if !target(do-test) && ${cmake_ARGS:Mtesting} +. if !target(do-test) && ${cmake_ARGS:Mtesting} CMAKE_TESTING_ON?= BUILD_TESTING CMAKE_TESTING_TARGET?= test # Handle the option-like CMAKE_TESTING_ON and CMAKE_TESTING_OFF lists. -. for _bool_kind in ON OFF -. if defined(CMAKE_TESTING_${_bool_kind}) +. for _bool_kind in ON OFF +. if defined(CMAKE_TESTING_${_bool_kind}) CMAKE_TESTING_ARGS+= ${CMAKE_TESTING_${_bool_kind}:C/.*/-D&:BOOL=${_bool_kind}/} -. endif -. endfor +. endif +. endfor do-test: @cd ${BUILD_WRKSRC} && \ - ${SETENV} ${CONFIGURE_ENV} ${CMAKE_BIN} ${CMAKE_ARGS} ${CMAKE_TESTING_ARGS} ${CMAKE_SOURCE_PATH} && \ - ${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${_MAKE_JOBS} ${MAKE_ARGS} ${ALL_TARGET} && \ - ${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} ${CMAKE_TESTING_TARGET} + ${SETENVI} ${WRK_ENV} ${CONFIGURE_ENV} ${CMAKE_BIN} ${CMAKE_ARGS} ${CMAKE_TESTING_ARGS} ${CMAKE_SOURCE_PATH} && \ + ${SETENVI} ${WRK_ENV} ${MAKE_ENV} ${MAKE_CMD} ${_MAKE_JOBS} ${MAKE_ARGS} ${ALL_TARGET} && \ + ${SETENVI} ${WRK_ENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} ${CMAKE_TESTING_TARGET} +. endif . endif .endif #!defined(_INCLUDE_USES_CMAKE_MK) |