From 528620eb4a12f2fca5215968ec344866fb7df989 Mon Sep 17 00:00:00 2001 From: Vincent Fortier Date: Tue, 14 Mar 2023 20:29:25 -0400 Subject: [PATCH] Misc CMAKE build fixes (#5658) * native-cmake.mk: Allow changing default build dir * tc.mk: Use abspath to remove all '//' use-cases from tc_vars.* * cross-cmake.mk: Set nasm only for x86 and set PKG_CONFIG_LIBDIR * cross-cmake.mk: Various fixes and enhancements 1. Use abspath instead of realpath as it does not check if location does exists. Usage of realpath sets variables to empty '' in some cases as the build may not have started yet. Usage of abspath solves that issue entirely 2. Allow NOT to build shared libraries by default. Building LLVM requires this to be unset or set to OFF so shared libraries are disabled by default 3. Enforce setting x86asm using CMAKE_USE_NASM only to i686 & x86_64 --- mk/spksrc.cross-cmake-env.mk | 22 +++++++++++++++++----- mk/spksrc.cross-cmake.mk | 9 +++++++++ mk/spksrc.native-cmake.mk | 7 ++++++- mk/spksrc.tc-flags.mk | 24 ++++++++++++------------ mk/spksrc.tc.mk | 5 +---- 5 files changed, 45 insertions(+), 22 deletions(-) diff --git a/mk/spksrc.cross-cmake-env.mk b/mk/spksrc.cross-cmake-env.mk index 3f99e1a70ab..41695288c80 100644 --- a/mk/spksrc.cross-cmake-env.mk +++ b/mk/spksrc.cross-cmake-env.mk @@ -33,7 +33,11 @@ CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = ONLY CMAKE_INSTALL_RPATH = $(INSTALL_PREFIX)/lib CMAKE_INSTALL_RPATH_USE_LINK_PATH = TRUE CMAKE_BUILD_WITH_INSTALL_RPATH = TRUE + +# Allow building shared libraries to be manually set +ifeq ($(filter -DBUILD_SHARED_LIBS%,$(CMAKE_ARGS)),) BUILD_SHARED_LIBS = ON +endif # Configuration for CMake build CMAKE_TOOLCHAIN_NAME = $(ARCH)-toolchain.cmake @@ -65,7 +69,7 @@ endif # Use native cmake (latest stable) ifeq ($(strip $(USE_NATIVE_CMAKE)),1) BUILD_DEPENDS += native/cmake - CMAKE_PATH = $(realpath $(WORK_DIR)/../../../native/cmake/work-native/install/usr/local/bin) + CMAKE_PATH = $(abspath $(PWD)/../../native/cmake/work-native/install/usr/local/bin) ENV += PATH=$(CMAKE_PATH):$$PATH export PATH := $(CMAKE_PATH):$(PATH) endif @@ -73,7 +77,7 @@ endif # Use native cmake (Debian 10 "Buster") ifeq ($(strip $(USE_NATIVE_CMAKE_LEGACY)),1) BUILD_DEPENDS += native/cmake-legacy - CMAKE_PATH = $(realpath $(WORK_DIR)/../../../native/cmake-legacy/work-native/install/usr/local/bin) + CMAKE_PATH = $(abspath $(PWD)/../../native/cmake-legacy/work-native/install/usr/local/bin) ENV += PATH=$(CMAKE_PATH):$$PATH export PATH := $(CMAKE_PATH):$(PATH) endif @@ -86,17 +90,25 @@ ifeq ($(strip $(CMAKE_USE_NINJA)),1) CMAKE_ARGS += -G Ninja endif -# Set default ASM build environment +# Set default X86ASM build environment # At toolchain step variables are not yet evaluated # resulting in inability to set in toolchain file +# +# ARM architecture may expect to be assembled with a C compiler as frontend: +# .s is raw assembly passed to as +# .S is assembly which expects to be preprocessed by a cpp then fed to assembler +# Setting the following for ARM may help: +# ENV += AS=$(abspath $(PWD)/../../toolchain/syno-$(ARCH)-$(TCVERSION)/work/$(TC_TARGET)/bin/$(TC_PREFIX)gcc) ifeq ($(strip $(CMAKE_USE_NASM)),1) + # Define x86asm + ifeq ($(findstring $(ARCH),$(i686_ARCHS) $(x64_ARCHS)),$(ARCH)) DEPENDS += native/nasm - NASM_PATH = $(realpath $(WORK_DIR)/../../../native/nasm/work-native/install/usr/local/bin) + NASM_PATH = $(abspath $(PWD)/../../native/nasm/work-native/install/usr/local/bin) ENV += PATH=$(NASM_PATH):$$PATH ENV += AS=$(NASM_PATH)/nasm - export PATH := $(NASM_PATH):$(PATH) ENABLE_ASSEMBLY = ON CMAKE_ASM_COMPILER = $(NASM_PATH)/nasm + endif else CMAKE_USE_NASM = 0 endif diff --git a/mk/spksrc.cross-cmake.mk b/mk/spksrc.cross-cmake.mk index 175ee2a692c..4aeef4bad82 100644 --- a/mk/spksrc.cross-cmake.mk +++ b/mk/spksrc.cross-cmake.mk @@ -45,10 +45,12 @@ cmake_pkg_toolchain: @cat $(CMAKE_TOOLCHAIN_WRK) ; \ echo ifeq ($(strip $(CMAKE_USE_NASM)),1) +ifeq ($(findstring $(ARCH),$(i686_ARCHS) $(x64_ARCHS)),$(ARCH)) @echo "# set assembly compiler" ; \ echo "set(ENABLE_ASSEMBLY $(ENABLE_ASSEMBLY))" ; \ echo "set(CMAKE_ASM_COMPILER $(CMAKE_ASM_COMPILER))" ; \ echo +endif endif @echo "# set compiler flags for cross-compiling" ; \ echo 'set(CMAKE_C_FLAGS "$(CFLAGS) $(CMAKE_C_FLAGS) $(ADDITIONAL_CFLAGS)")' ; \ @@ -57,11 +59,18 @@ endif echo 'set(CMAKE_EXE_LINKER_FLAGS "$(LDFLAGS) $(CMAKE_EXE_LINKER_FLAGS) $(ADDITIONAL_LDFLAGS)")' ; \ echo 'set(CMAKE_SHARED_LINKER_FLAGS "$(LDFLAGS) $(CMAKE_SHARED_LINKER_FLAGS) $(ADDITIONAL_LDFLAGS)")' ; \ echo +ifneq ($(strip $(BUILD_SHARED_LIBS)),) + @echo "# build shared library" ; \ + echo "set(BUILD_SHARED_LIBS $(BUILD_SHARED_LIBS))" +endif @echo "# define library rpath" ; \ echo "set(CMAKE_INSTALL_RPATH $(subst $() $(),:,$(CMAKE_INSTALL_RPATH)))" ; \ echo "set(CMAKE_INSTALL_RPATH_USE_LINK_PATH $(CMAKE_INSTALL_RPATH_USE_LINK_PATH))" ; \ echo "set(CMAKE_BUILD_WITH_INSTALL_RPATH $(CMAKE_BUILD_WITH_INSTALL_RPATH))" ; \ echo + @echo "# set pkg-config path" ; \ + echo 'set(ENV{PKG_CONFIG_LIBDIR} "$(abspath $(PKG_CONFIG_LIBDIR))")' ; \ + echo 'set(ENV{PKG_CONFIG_SYSROOT_DIR} "$(abspath $(INSTALL_DIR))")' .PHONY: cmake_configure_target diff --git a/mk/spksrc.native-cmake.mk b/mk/spksrc.native-cmake.mk index 9bdcf6607e5..bd788a1f4ff 100644 --- a/mk/spksrc.native-cmake.mk +++ b/mk/spksrc.native-cmake.mk @@ -35,6 +35,11 @@ ifeq ($(strip $(CONFIGURE_TARGET)),) CONFIGURE_TARGET = cmake_configure_target endif +# install +ifeq ($(strip $(CMAKE_DIR)),) +CMAKE_DIR = $(WORK_DIR)/$(PKG_DIR) +endif + ifneq ($(strip $(CMAKE_USE_NINJA)),1) # compile ifeq ($(strip $(COMPILE_TARGET)),) @@ -59,7 +64,7 @@ cmake_configure_target: @$(MSG) - Path BUILD_DIR = $(CMAKE_BUILD_DIR) $(RUN) rm -rf CMakeCache.txt CMakeFiles $(RUN) mkdir --parents $(CMAKE_BUILD_DIR) - cd $(CMAKE_BUILD_DIR) && env $(ENV) cmake $(CMAKE_ARGS) $(WORK_DIR)/$(PKG_DIR) + cd $(CMAKE_BUILD_DIR) && env $(ENV) cmake $(CMAKE_ARGS) $(CMAKE_DIR) .PHONY: cmake_compile_target diff --git a/mk/spksrc.tc-flags.mk b/mk/spksrc.tc-flags.mk index 4556198fbe4..9f22708279e 100644 --- a/mk/spksrc.tc-flags.mk +++ b/mk/spksrc.tc-flags.mk @@ -37,23 +37,23 @@ TC_PREFIX = $(TC_TARGET)- endif ifeq ($(strip $(TC_INCLUDE)),) -TC_INCLUDE = $(TC_SYSROOT)/usr/include +TC_INCLUDE = $(abspath $(TC_SYSROOT)/usr/include) endif ifeq ($(strip $(TC_LIBRARY)),) -TC_LIBRARY = $(TC_SYSROOT)/lib +TC_LIBRARY = $(abspath $(TC_SYSROOT)/lib) endif -CFLAGS += -I$(WORK_DIR)/$(TC_TARGET)/$(TC_INCLUDE) $(TC_EXTRA_CFLAGS) -CFLAGS += -I$(INSTALL_DIR)/$(INSTALL_PREFIX)/include +CFLAGS += -I$(abspath $(WORK_DIR)/$(TC_TARGET)/$(TC_INCLUDE)) $(TC_EXTRA_CFLAGS) +CFLAGS += -I$(abspath $(INSTALL_DIR)/$(INSTALL_PREFIX)/include) -CPPFLAGS += -I$(WORK_DIR)/$(TC_TARGET)/$(TC_INCLUDE) $(TC_EXTRA_CFLAGS) -CPPFLAGS += -I$(INSTALL_DIR)/$(INSTALL_PREFIX)/include +CPPFLAGS += -I$(abspath $(WORK_DIR)/$(TC_TARGET)/$(TC_INCLUDE)) $(TC_EXTRA_CFLAGS) +CPPFLAGS += -I$(abspath $(INSTALL_DIR)/$(INSTALL_PREFIX)/include) -CXXFLAGS += -I$(WORK_DIR)/$(TC_TARGET)/$(TC_INCLUDE) $(TC_EXTRA_CFLAGS) -CXXFLAGS += -I$(INSTALL_DIR)/$(INSTALL_PREFIX)/include +CXXFLAGS += -I$(abspath $(WORK_DIR)/$(TC_TARGET)/$(TC_INCLUDE)) $(TC_EXTRA_CFLAGS) +CXXFLAGS += -I$(abspath $(INSTALL_DIR)/$(INSTALL_PREFIX)/include) -LDFLAGS += -L$(WORK_DIR)/$(TC_TARGET)/$(TC_LIBRARY) $(TC_EXTRA_CFLAGS) -LDFLAGS += -L$(INSTALL_DIR)/$(INSTALL_PREFIX)/lib -LDFLAGS += -Wl,--rpath-link,$(INSTALL_DIR)/$(INSTALL_PREFIX)/lib -LDFLAGS += -Wl,--rpath,$(INSTALL_PREFIX)/lib +LDFLAGS += -L$(abspath $(WORK_DIR)/$(TC_TARGET)/$(TC_LIBRARY)) $(TC_EXTRA_CFLAGS) +LDFLAGS += -L$(abspath $(INSTALL_DIR)/$(INSTALL_PREFIX)/lib) +LDFLAGS += -Wl,--rpath-link,$(abspath $(INSTALL_DIR)/$(INSTALL_PREFIX)/lib) +LDFLAGS += -Wl,--rpath,$(abspath $(INSTALL_PREFIX)/lib) diff --git a/mk/spksrc.tc.mk b/mk/spksrc.tc.mk index 5aedc4fb15d..6dc12c22897 100644 --- a/mk/spksrc.tc.mk +++ b/mk/spksrc.tc.mk @@ -119,10 +119,7 @@ endif echo ; \ echo "# search headers and libraries in the target environment" ; \ echo "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY $(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY))" ; \ - echo "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE $(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE))" ; \ - echo ; \ - echo "# always build shared library" ; \ - echo "set(BUILD_SHARED_LIBS $(BUILD_SHARED_LIBS))" + echo "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE $(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE))" .PHONY: meson_vars meson_vars: