From b2766b6be2aa033839dd03b281d3d9ea9136e7eb Mon Sep 17 00:00:00 2001 From: Gauvain Chery Date: Mon, 9 Oct 2017 11:12:53 +0200 Subject: [PATCH 1/2] qibuild: generating the project.cmake file Creating the project.cmake file containing the project version number when running qibuild configure. This file allows the use of the qiproject.xml information in CMake. It is automatically included by the qibuild-config.cmake in the same way than the dependencies.cmake. --- cmake/qibuild/qibuild-config.cmake | 6 ++++++ python/qibuild/cmake_builder.py | 5 +++-- python/qibuild/project.py | 18 ++++++++++++++++++ python/qibuild/test/test_project.py | 9 +++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/cmake/qibuild/qibuild-config.cmake b/cmake/qibuild/qibuild-config.cmake index aa1820320..72b5b444c 100644 --- a/cmake/qibuild/qibuild-config.cmake +++ b/cmake/qibuild/qibuild-config.cmake @@ -12,6 +12,12 @@ if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/dependencies.cmake) include(${CMAKE_CURRENT_BINARY_DIR}/dependencies.cmake) endif() +# If someone is using qibuild configure, includes +# the project.cmake file +if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/project.cmake) + include(${CMAKE_CURRENT_BINARY_DIR}/project.cmake) +endif() + # remove qi_tests.json # Note: # this will fail silently if the file does not exist diff --git a/python/qibuild/cmake_builder.py b/python/qibuild/cmake_builder.py index c1c5f9874..49cf1dc30 100644 --- a/python/qibuild/cmake_builder.py +++ b/python/qibuild/cmake_builder.py @@ -105,13 +105,14 @@ def bootstrap_projects(self): """ projects = self.deps_solver.get_dep_projects(self.projects, ["build", "runtime", "test"]) - # subtle diffs here: dependencies.cmake must be written for *all* projects, - # with the build dependencies + # subtle diffs here: dependencies.cmake and project.cmake must be written + # for *all* projects, with the build dependencies for project in projects: sdk_dirs = self.get_sdk_dirs_for_project(project) host_dirs = self.get_host_dirs(project) if not project.meta: project.write_dependencies_cmake(sdk_dirs, host_dirs=host_dirs) + project.write_project_cmake() def get_sdk_dirs_for_project(self, project): sdk_dirs = self.deps_solver.get_sdk_dirs(project, ["build", "test"]) diff --git a/python/qibuild/project.py b/python/qibuild/project.py index b07d792b6..a662937a2 100644 --- a/python/qibuild/project.py +++ b/python/qibuild/project.py @@ -177,6 +177,24 @@ def using_make(self): def verbose_make(self): return self.build_config.verbose_make + def write_project_cmake(self): + """ Write the project.cmake file. This will be read by + qibuild-config.cmake to set QI_SDK_VERSION. + """ + to_write = """ +############################################# +#QIBUILD AUTOGENERATED FILE. DO NOT EDIT. +############################################# + +# Add qiproject version to CMake +set(QI_SDK_VERSION %s CACHE STRING "" FORCE) +""" % self.version + + + qisys.sh.mkdir(self.build_directory, recursive=True) + proj_cmake = os.path.join(self.build_directory, "project.cmake") + qisys.sh.write_file_if_different(to_write, proj_cmake) + def write_dependencies_cmake(self, sdk_dirs, host_dirs=None): """ Write the dependencies.cmake file. This will be read by qibuild-config.cmake to set CMAKE_PREFIX_PATH and diff --git a/python/qibuild/test/test_project.py b/python/qibuild/test/test_project.py index 8a8c70a4e..e549a2c3c 100644 --- a/python/qibuild/test/test_project.py +++ b/python/qibuild/test/test_project.py @@ -14,6 +14,15 @@ import pytest +def test_project_cmake(build_worktree): + hello_proj = build_worktree.create_project("hello") + hello_proj.write_project_cmake() + proj_cmake = os.path.join(hello_proj.build_directory, + "project.cmake") + # only way to check this really works is to build some + # cmake projects, so no other assertions here + assert os.path.exists(proj_cmake) + def test_dependencies_cmake(build_worktree): hello_proj = build_worktree.create_project("hello") hello_proj.write_dependencies_cmake(list()) From a5135ced0e10cc6eed4e59a0c8a604de927a5192 Mon Sep 17 00:00:00 2001 From: Gauvain Chery Date: Thu, 12 Oct 2017 15:23:23 +0200 Subject: [PATCH 2/2] qibuild: generating the project.cmake file Changing cmake variable name from QI_SDK_VERSION to QI_PROJECT_VERSION. --- python/qibuild/project.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/qibuild/project.py b/python/qibuild/project.py index a662937a2..77bdb7031 100644 --- a/python/qibuild/project.py +++ b/python/qibuild/project.py @@ -179,7 +179,7 @@ def verbose_make(self): def write_project_cmake(self): """ Write the project.cmake file. This will be read by - qibuild-config.cmake to set QI_SDK_VERSION. + qibuild-config.cmake to set QI_PROJECT_VERSION. """ to_write = """ ############################################# @@ -187,7 +187,7 @@ def write_project_cmake(self): ############################################# # Add qiproject version to CMake -set(QI_SDK_VERSION %s CACHE STRING "" FORCE) +set(QI_PROJECT_VERSION %s CACHE STRING "" FORCE) """ % self.version