Merge pull request #7527 from mensinda/cnFixExe
cmake: resolve IMPORTED executables in custom commands (fixes #7509)pull/6430/head
commit
461cb7d534
7 changed files with 55 additions and 21 deletions
@ -1,24 +1,9 @@ |
||||
cmake_policy(VERSION 3.7) |
||||
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12) |
||||
find_package(Python COMPONENTS Interpreter) |
||||
else() |
||||
find_package(PythonInterp) |
||||
endif() |
||||
|
||||
find_package(Python COMPONENTS Interpreter) |
||||
if(Python_FOUND OR PYTHONINTERP_FOUND) |
||||
set(SomethingLikePython_FOUND ON) |
||||
set(SomethingLikePython_EXECUTABLE ${Python_EXECUTABLE}) |
||||
|
||||
if(NOT DEFINED Python_VERSION) |
||||
set(Python_VERSION ${Python_VERSION_STRING}) |
||||
endif() |
||||
if(NOT TARGET Python::Interpreter) |
||||
add_executable(Python::Interpreter IMPORTED) |
||||
set_target_properties(Python::Interpreter PROPERTIES |
||||
IMPORTED_LOCATION ${Python_EXECUTABLE} |
||||
VERSION ${Python_VERSION}) |
||||
endif() |
||||
else() |
||||
set(SomethingLikePython_FOUND OFF) |
||||
endif() |
||||
|
@ -0,0 +1,15 @@ |
||||
cmake_minimum_required(VERSION 3.5) |
||||
|
||||
project(cmMod) |
||||
|
||||
message(STATUS "CMAKE_MODULE_PATH: '${CMAKE_MODULE_PATH}'") |
||||
|
||||
find_package(SomethingLikePython REQUIRED) |
||||
|
||||
add_custom_command( |
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/main.c" |
||||
COMMAND Python::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/gen.py" |
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" |
||||
) |
||||
|
||||
add_executable(main "${CMAKE_CURRENT_BINARY_DIR}/main.c") |
@ -0,0 +1,9 @@ |
||||
with open('main.c', 'w') as fp: |
||||
print(''' |
||||
#include <stdio.h> |
||||
|
||||
int main(void) { |
||||
printf(\"Hello World\"); |
||||
return 0; |
||||
} |
||||
''', file=fp) |
@ -0,0 +1,5 @@ |
||||
{ |
||||
"tools": { |
||||
"cmake": ">=3.12" |
||||
} |
||||
} |
Loading…
Reference in new issue