私はC++とPythonの両方を組み合わせようとしていますが、CMakeを使用しています。 CMakeLists.txtでは、私はプログラムを見つけようとします:Cmakeのfind_programから実行可能ファイルを保存してPythonで実行できるようにします
# Check for Gmsh executable
find_program (GMSH gmsh [/Applications/Gmsh.app/Contents/MacOS/ /usr/bin/ /usr/local/bin/])
if(GMSH)
message(STATUS "Found Gmsh in: ${GMSH}")
set(HAVE_GMSH YES)
else()
set(HAVE_GMSH NO)
endif()
message(STATUS "Setting HAVE_GMSH to: ${HAVE_GMSH}")
これは問題なしで実行ファイルを見つけることができます。しかし、どういうわけか私はこれを後でPythonから呼び出せるように、どこかに保存しなければなりません。これは設定ファイルで行うべきですか?これを行う正しい方法は何ですか? UPDATE
は、私は次の内容のファイルを作成ProjectConfig.cmake.in:
# Compute paths
get_filename_component(PROJECT_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(PROJECT_INCLUDE_DIRS "@[email protected]")
# Our library dependencies (contains definitions for IMPORTED targets)
include("${PROJECT_CMAKE_DIR}/ProjectTargets.cmake")
# These are IMPORTED targets created by ProjectTargets.cmake
set(PROJECT_LIBRARIES core)
set(PROJECT_EXECUTABLE bar)
#cmakedefine HAVE_GMSH @[email protected]
#cmakedefine GMSH @[email protected]
そしてCMakeLists.txtファイルを次のようになります。今
cmake_minimum_required(VERSION 3.1)
project(TestProject)
enable_language(CXX)
# Options
# Offer the user the choice of overriding the installation directories
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
set(INSTALL_INCLUDE_DIR include CACHE PATH
"Installation directory for header files")
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKE_DIR CMake)
else()
set(DEF_INSTALL_CMAKE_DIR lib/CMake/Project)
endif()
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH
"Installation directory for CMake files")
# Make relative paths absolute (needed later on)
foreach(p LIB BIN INCLUDE CMAKE)
set(var INSTALL_${p}_DIR)
if(NOT IS_ABSOLUTE "${${var}}")
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif()
endforeach()
# Check for Gmsh executable
find_program (GMSH gmsh [/Applications/Gmsh.app/Contents/MacOS/ /usr/bin/ /usr/local/bin/])
if(GMSH)
message(STATUS "Found Gmsh in: ${GMSH}")
set(HAVE_GMSH YES)
else()
set(HAVE_GMSH NO)
endif()
message(STATUS "Setting HAVE_GMSH to: ${HAVE_GMSH}")
# Python support
#
# find Python
find_package(PythonInterp)
# find SWIG
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(PythonLibs)
include_directories(${PYTHON_INCLUDE_PATH})
message(STATUS "PYTHON_INCLUDE_PATH: ${PYTHON_INCLUDE_PATH}")
message(STATUS "PYTHON_LIBRARIES: ${PYTHON_LIBRARIES}")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/core)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/core/fem)
#set(CMAKE_SWIG_OUTDIR ${PROJECT_BINARY_DIR}/../lib/project)
SET_SOURCE_FILES_PROPERTIES(swig/core.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties(swig/core.i SWIG_FLAGS "-includeall;-c++;-shadow")
swig_add_module(core python swig/core.i core/foo.cpp)
swig_link_libraries(core project_core ${PYTHON_LIBRARIES})
################################################################################
# Directories
#
# set up include-directories
include_directories(
"${PROJECT_SOURCE_DIR}" # to find core/foo.hpp
"${PROJECT_BINARY_DIR}") # to find core/config.hpp
# Add sub-directories
add_subdirectory(core)
add_subdirectory(bar)
# The interesting stuff goes here
# ===============================
# Add all targets to the build-tree export set
export(TARGETS project_core bar
FILE "${PROJECT_BINARY_DIR}/ProjectTargets.cmake")
# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export(PACKAGE Project)
# Create the ProjectConfig.cmake and ProjectConfigVersion files
file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}"
"${INSTALL_INCLUDE_DIR}")
# ... for the build tree
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
configure_file(ProjectConfig.cmake.in
"${PROJECT_BINARY_DIR}/ProjectConfig.cmake" @ONLY)
# ... for the install treew
set(CONF_INCLUDE_DIRS "\${PROJECT_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file(ProjectConfig.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ProjectConfig.cmake" @ONLY)
# ... for both
configure_file(ProjectConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/ProjectConfigVersion.cmake" @ONLY)
# Install the ProjectConfig.cmake and ProjectConfigVersion.cmake
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ProjectConfig.cmake"
"${PROJECT_BINARY_DIR}/ProjectConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
# Install the export set for use with the install-tree
install(EXPORT ProjectTargets DESTINATION
"${INSTALL_CMAKE_DIR}" COMPONENT dev)
私は結果の設定ファイル($ {PROJECT_BINARY_DIR}の中にある)が置くべき場所が正しいかどうかは分かりません。代わりにそれを階層全体のルートに置くべきですか?
├── AUTHORS.rst
├── CHANGELOG.rst
├── CONTRIBUTING.rst
├── LICENSE
├── MANIFEST.in
├── Makefile
├── README.rst
├── core
│ ├── CMakeLists.txt
│ ├── ProjectConfig.cmake.in
│ ├── ProjectConfigVersion.cmake.in
│ ├── Makefile
│ ├── bar
│ ├── core
│ └── swig
├── setup.cfg
├── setup.py
├── src
│ └── project
├── tests
│ └── unit
└── tox.ini
あなたの提案で私の答えを更新しました。 Pythonを使って実行可能ファイルを呼び出す方法はまだ分かりません。 – aaragon