Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
d141a0a9
Commit
d141a0a9
authored
8 years ago
by
Marcel Loose
Browse files
Options
Downloads
Patches
Plain Diff
Task #9841: Added generic CMake find module for Python modules.
parent
e2813ddb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CMake/FindPythonModule.cmake
+83
-0
83 additions, 0 deletions
CMake/FindPythonModule.cmake
with
83 additions
and
0 deletions
CMake/FindPythonModule.cmake
0 → 100644
+
83
−
0
View file @
d141a0a9
# - Try to find a Python module.
# The macro PYTHON_FIND_PACKAGE(module) tries to find python module <module>.
#
# Variables defined by this module:
# PYTHON_<MODULE> - file path of python <module>, if found (cached)
# PYTHON_<MODULE>_FOUND - true if python <module> was found, else false.
# Copyright (C) 2015
# ASTRON (Netherlands Institute for Radio Astronomy)
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
#
# This file is part of the LOFAR software suite.
# The LOFAR software suite is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# The LOFAR software suite is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
#
# $Id$
# Search for the Python interpreter.
find_package
(
PythonInterp
)
# -----------------------------------------------------------------------------
# find_python_module(module [REQUIRED])
#
# Find the python module <module>.
# Set variable PYTHON_<MODULE> to the file path of <module> (cached).
# Set variable PYTHON_<MODULE>_FOUND to TRUE if <module> was found, else
# set it to FALSE.
# The REQUIRED option stops processing with an error message if the module
# <module> cannot be found.
# -----------------------------------------------------------------------------
macro
(
find_python_module _module
)
# Name of module in uppercase.
string
(
TOUPPER
"
${
_module
}
"
_MODULE
)
# Try to find the python module, if we have not found it yet.
if
(
NOT PYTHON_
${
_MODULE
}
)
# Check if option REQUIRED was given.
if
(
NOT
"
${
ARGN
}
"
STREQUAL
""
)
if
(
"
${
ARGN
}
"
STREQUAL
"REQUIRED"
)
set
(
PYTHON_
${
_MODULE
}
_FIND_REQUIRED TRUE
)
else
()
message
(
FATAL_ERROR
"find_python_module called with invalid argument
\"
${
ARGN
}
\"
"
)
endif
()
endif
()
# Try to import the python module we need to find, and get its file path.
if
(
PYTHON_EXECUTABLE
)
set
(
_cmd
"import
${
_module
}
; print
${
_module
}
.__file__"
)
execute_process
(
COMMAND
"
${
PYTHON_EXECUTABLE
}
"
"-c"
"
${
_cmd
}
"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _output
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Set PYTHON_<MODULE> variable in the cache, if <module> was found.
if
(
_result EQUAL 0
)
set
(
PYTHON_
${
_MODULE
}
${
_output
}
CACHE FILEPATH
"Path to python module
${
_module
}
"
)
endif
()
endif
()
endif
()
# Report result, and set PYTHON_<MODULE>_FOUND
include
(
FindPackageHandleStandardArgs
)
find_package_handle_standard_args
(
PYTHON_
${
_MODULE
}
DEFAULT_MSG
PYTHON_
${
_MODULE
}
)
endmacro
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment