Skip to content

Commit

Permalink
Misc CMAKE build fixes (SynoCommunity#5658)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
th0ma7 authored Mar 15, 2023
1 parent c61e394 commit 528620e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
22 changes: 17 additions & 5 deletions mk/spksrc.cross-cmake-env.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,15 +69,15 @@ 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

# 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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions mk/spksrc.cross-cmake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)")' ; \
Expand All @@ -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

Expand Down
7 changes: 6 additions & 1 deletion mk/spksrc.native-cmake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)),)
Expand All @@ -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

Expand Down
24 changes: 12 additions & 12 deletions mk/spksrc.tc-flags.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 1 addition & 4 deletions mk/spksrc.tc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 528620e

Please sign in to comment.