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..77bdb7031 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_PROJECT_VERSION. + """ + to_write = """ +############################################# +#QIBUILD AUTOGENERATED FILE. DO NOT EDIT. +############################################# + +# Add qiproject version to CMake +set(QI_PROJECT_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())