-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update dependency handling logic in meson and CMake (#9)
- allow meson to find dependencies before falling back to subprojects - install module files in meson builds - add custom CMake finder for mctc-lib - add CMake macro to find (cmake/pkgconf) or include (subproject/fetch) dependencies
- Loading branch information
Showing
9 changed files
with
238 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# This file is part of mstore. | ||
# SPDX-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Handling of subproject dependencies | ||
macro( | ||
"mstore_find_package" | ||
package | ||
methods | ||
url | ||
) | ||
string(TOLOWER "${package}" _pkg_lc) | ||
string(TOUPPER "${package}" _pkg_uc) | ||
|
||
foreach(method in ITEMS ${methods}) | ||
|
||
if(TARGET "${package}::${package}") | ||
break() | ||
endif() | ||
|
||
if("${method}" STREQUAL "cmake") | ||
message(STATUS "${package}: Find installed package") | ||
find_package("${package}" CONFIG) | ||
if("${package}_FOUND") | ||
message(STATUS "${package}: Found installed package") | ||
break() | ||
endif() | ||
endif() | ||
|
||
if("${method}" STREQUAL "pkgconf") | ||
find_package(PkgConfig QUIET) | ||
pkg_check_modules("${_pkg_uc}" QUIET "${package}") | ||
if("${_pkg_uc}_FOUND") | ||
message(STATUS "Found ${package} via pkg-config") | ||
|
||
add_library("${package}::${package}" INTERFACE IMPORTED) | ||
target_link_libraries( | ||
"${package}::${package}" | ||
INTERFACE | ||
"${${_pkg_uc}_LINK_LIBRARIES}" | ||
) | ||
target_include_directories( | ||
"${package}::${package}" | ||
INTERFACE | ||
"${${_pkg_uc}_INCLUDE_DIRS}" | ||
) | ||
break() | ||
endif() | ||
endif() | ||
|
||
if("${method}" STREQUAL "subproject") | ||
set("${_pkg_uc}_SOURCE_DIR" "${PROJECT_SOURCE_DIR}/subprojects/${package}") | ||
set("${_pkg_uc}_BINARY_DIR" "${PROJECT_BINARY_DIR}/subprojects/${package}") | ||
if(EXISTS "${${_pkg_uc}_SOURCE_DIR}/CMakeLists.txt") | ||
message(STATUS "Include ${package} from subprojects") | ||
add_subdirectory( | ||
"${${_pkg_uc}_SOURCE_DIR}" | ||
"${${_pkg_uc}_BINARY_DIR}" | ||
) | ||
|
||
add_library("${package}::${package}" INTERFACE IMPORTED) | ||
target_link_libraries("${package}::${package}" INTERFACE "${package}") | ||
|
||
# We need the module directory in the subproject before we finish the configure stage | ||
if(NOT EXISTS "${${_pkg_uc}_BINARY_DIR}/include") | ||
make_directory("${${_pkg_uc}_BINARY_DIR}/include") | ||
endif() | ||
|
||
break() | ||
endif() | ||
endif() | ||
|
||
if("${method}" STREQUAL "fetch") | ||
message(STATUS "Retrieving ${package} from ${url}") | ||
include(FetchContent) | ||
FetchContent_Declare( | ||
"${_pkg_lc}" | ||
GIT_REPOSITORY "${url}" | ||
GIT_TAG "HEAD" | ||
) | ||
FetchContent_MakeAvailable("${_pkg_lc}") | ||
|
||
add_library("${package}::${package}" INTERFACE IMPORTED) | ||
target_link_libraries("${package}::${package}" INTERFACE "${package}") | ||
|
||
# We need the module directory in the subproject before we finish the configure stage | ||
FetchContent_GetProperties("${_pkg_lc}" BINARY_DIR "${_pkg_uc}_BINARY_DIR") | ||
if(NOT EXISTS "${${_pkg_uc}_BINARY_DIR}/include") | ||
make_directory("${${_pkg_uc}_BINARY_DIR}/include") | ||
endif() | ||
|
||
break() | ||
endif() | ||
|
||
endforeach() | ||
|
||
unset(_pkg_lc) | ||
unset(_pkg_uc) | ||
|
||
if(NOT TARGET "${package}::${package}") | ||
message(FATAL_ERROR "Could not find dependency ${package}") | ||
endif() | ||
|
||
endmacro() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python | ||
# This file is part of mstore. | ||
# SPDX-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from os import environ, listdir, makedirs | ||
from os.path import join, isdir, exists | ||
from sys import argv | ||
from shutil import copy | ||
|
||
build_dir = environ["MESON_BUILD_ROOT"] | ||
if "MESON_INSTALL_DESTDIR_PREFIX" in environ: | ||
install_dir = environ["MESON_INSTALL_DESTDIR_PREFIX"] | ||
else: | ||
install_dir = environ["MESON_INSTALL_PREFIX"] | ||
|
||
include_dir = argv[1] if len(argv) > 1 else "include" | ||
module_dir = join(install_dir, include_dir) | ||
|
||
modules = [] | ||
for d in listdir(build_dir): | ||
bd = join(build_dir, d) | ||
if isdir(bd): | ||
for f in listdir(bd): | ||
if f.endswith(".mod"): | ||
modules.append(join(bd, f)) | ||
|
||
if not exists(module_dir): | ||
makedirs(module_dir) | ||
|
||
for mod in modules: | ||
print("Installing", mod, "to", module_dir) | ||
copy(mod, module_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
@PACKAGE_INIT@ | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") | ||
|
||
if(NOT TARGET "@PROJECT_NAME@::@PROJECT_NAME@") | ||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters