Skip to content

Commit c968bc2

Browse files
committed
add ci build operations
1 parent 829b04c commit c968bc2

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

tools/export/cmake/CMakeLists.txt.tmpl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,26 @@ SET(CMAKE_CROSSCOMPILING TRUE)
1111
SET(CMAKE_C_COMPILER_WORKS TRUE)
1212
SET(CMAKE_CXX_COMPILER_WORKS TRUE)
1313

14-
SET(CMAKE_ASM_COMPILER_INIT "{{asm}}")
15-
SET(CMAKE_C_COMPILER_INIT "{{cc}}")
16-
SET(CMAKE_CXX_COMPILER_INIT "{{cxx}}")
17-
SET(ELF2BIN "{{elf2bin}}")
14+
# force cmake compilers
15+
SET(CMAKE_ASM_COMPILER "{{asm}}")
16+
SET(CMAKE_C_COMPILER "{{cc}}")
17+
SET(CMAKE_CXX_COMPILER "{{cxx}}")
18+
SET(ELF2BIN "{{elf2bin}}")
1819
{% if hex_files %}
1920
SET(SREC_CAT "srec_cat")
2021
{%- endif %}
2122

23+
# if the environment does not specify build type, set to Debug
24+
IF(NOT CMAKE_BUILD_TYPE)
25+
set(CMAKE_BUILD_TYPE "Debug"
26+
CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
27+
FORCE)
28+
ENDIF()
29+
2230
# here starts the project
2331
PROJECT(cmake-{{name}} C CXX ASM)
32+
33+
# uncomment below to have a verbose build process
2434
#SET(CMAKE_VERBOSE_MAKEFILE ON)
2535

2636
SET(LD_SYS_LIBS "{%- block sys_libs -%} -Wl,--start-group {{ld_sys_libs|join(" ")}} {{libraries|join(" ")}} -Wl,--end-group {%- endblock -%}")

tools/export/cmake/__init__.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
"""
1717
import re
1818
import shutil
19-
from os import remove
20-
from os.path import splitext, basename, exists
19+
from os import remove, getcwd, chdir, mkdir
20+
from os.path import basename, exists
2121
from subprocess import Popen, PIPE
2222

2323
from jinja2.exceptions import TemplateNotFound
2424

2525
from tools.export.exporters import Exporter, apply_supported_whitelist
2626
from tools.targets import TARGET_MAP
27-
from tools.utils import NotSupportedException
2827

2928

3029
class CMake(Exporter):
@@ -126,14 +125,34 @@ def generate(self):
126125
@staticmethod
127126
def build(project_name, log_name="build_log.txt", cleanup=True):
128127
""" Build Make project """
129-
# > Make -j
130-
cmd = ["make", "-j"]
128+
129+
# change into our build directory
130+
current_dir = getcwd()
131+
if not exists("BUILD"):
132+
mkdir("BUILD")
133+
chdir("BUILD")
134+
135+
# > run cmake initial command
136+
cmd = ["cmake", ".."]
131137

132138
# Build the project
133139
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
134140
out, err = p.communicate()
135141
ret_code = p.returncode
136142

143+
if ret_code == 0:
144+
# we create the cmake files inside BUILD, change into and run cmake
145+
146+
# > run make -j
147+
cmd = ["make", "-j"]
148+
149+
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
150+
out, err = p.communicate()
151+
ret_code = p.returncode
152+
153+
# go back to the original directory
154+
chdir(current_dir)
155+
137156
out_string = "=" * 10 + "STDOUT" + "=" * 10 + "\n"
138157
out_string += out
139158
out_string += "=" * 10 + "STDERR" + "=" * 10 + "\n"
@@ -161,6 +180,7 @@ def build(project_name, log_name="build_log.txt", cleanup=True):
161180
if exists('BUILD'):
162181
shutil.rmtree('BUILD')
163182

183+
164184
if ret_code != 0:
165185
# Seems like something went wrong.
166186
return -1

0 commit comments

Comments
 (0)