Skip to content

Commit

Permalink
Merge pull request #60 from FRAOTIAC/v9.0.0
Browse files Browse the repository at this point in the history
 feat(install.py): enhance installation script with argument parsing, Added fPIC compiler flags and integrate ccache
  • Loading branch information
minhanghuang authored Apr 27, 2024
2 parents 6c89706 + c1a12e7 commit 337d917
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@ set(CMAKE_CXX_STANDARD 14)
set(TARGET_NAME ${PROJECT_NAME})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug) # Debug/Release
set(CMAKE_BUILD_TYPE Release) # Debug/Release
endif()

enable_language(ASM)

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
# ccache
find_program(CCACHE_FOUND ccache)
if (CCACHE_FOUND)
message(STATUS "### use ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif (CCACHE_FOUND)

# fix for gcc 9
#set(CMAKE_POSITION_INDEPENDENT_CODE ON)
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

set(CROUTINE_FILE "cyber/croutine/detail/swap_x86_64.S")
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
Expand Down
50 changes: 38 additions & 12 deletions install.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
#!/usr/bin/env python3
import subprocess
import platform
import os

import argparse
import time

class Install:

def __init__(self) -> None:
self._machine = platform.machine()
def __init__(self, platform, install_prefix) -> None:
self._machine = platform
self._home_path = os.path.expanduser("~")
self._current_path = os.path.abspath(os.path.dirname(__file__))
self._dowload_path = os.path.join(self._current_path, "third_party")
self._install_prefix = os.path.join(self._current_path, "install")
if (install_prefix != "install"):
self._install_prefix = install_prefix

if not os.path.exists(self._install_prefix):
os.makedirs(self._install_prefix)

self.environment = self._load_environment()

def _load_environment(self):
'''
In case of cross-compilation, we need to load the environment setup file
:return: env
'''
env = os.environ.copy()
return env


def _cmd(self, command):
"""执行系统命令,使用指定的环境变量"""
print("[command] {}".format(command))
subprocess.run(command, shell=True, env=self.environment)

def start(self):
self._clone_setup()
self._clone_nlohmann_json()
Expand Down Expand Up @@ -176,21 +194,29 @@ def _clone_dds(self):
else:
dds_name = "fast-rtps-1.5.0-1.prebuilt.aarch64.tar.gz"

if os.path.exists(os.path.join(self._dowload_path, dds_name)):
return None
if not os.path.exists(os.path.join(self._dowload_path, dds_name)):
self._cmd(
"wget -t 10 {} -P {}".format(
"https://apollo-system.cdn.bcebos.com/archive/6.0/{}".format(dds_name),
self._dowload_path),
)

self._cmd(
"wget -t 10 {} -P {}".format(
"https://apollo-system.cdn.bcebos.com/archive/6.0/{}".format(dds_name),
self._dowload_path),
)
os.chdir(self._dowload_path)
self._cmd("tar -zxvf {}".format(dds_name))
self._cmd("cp -r fast-rtps-1.5.0-1/* {}".format(self._install_prefix))
self._cmd("rm -rf fast-rtps-1.5.0-1/")
os.chdir(self._current_path)

def parse_config():
parser = argparse.ArgumentParser(description="install")
parser.add_argument("--platform", type=str, default="x86_64", help="platform")
parser.add_argument("--install_prefix", type=str, default="install", help="install prefix")
args = parser.parse_args()
return args

if __name__ == "__main__":
install = Install()
args = parse_config()
print(f"args.platform: {args.platform}, args.install_prefix: {args.install_prefix}")
time.sleep(3)
install = Install(args.platform, args.install_prefix)
install.start()

0 comments on commit 337d917

Please sign in to comment.