This repository has been archived by the owner on May 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImportOppTarget.cmake
41 lines (35 loc) · 1.59 KB
/
ImportOppTarget.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
cmake_minimum_required(VERSION 3.0)
find_package(PythonInterp 3 REQUIRED)
macro(import_opp_target _target _opp_makefile)
# _cmake_target: generated CMake file with import target [optional argument]
if(${ARGC} GREATER 2)
set(_cmake_target "${ARGV2}")
else()
set(_cmake_target "${PROJECT_BINARY_DIR}/${_target}-targets.cmake")
endif()
# opp_makemake generated Makefile is required for proceeding
if(NOT EXISTS ${_opp_makefile})
message(FATAL_ERROR "Cannot import ${_target} because there is no opp_makemake file at ${_opp_makefile}")
endif()
# generate target file (prior to build system generation)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_MODULE_PATH}/opp_cmake.py ${_opp_makefile} ${_cmake_target}
ERROR_VARIABLE _opp_cmake_error
RESULT_VARIABLE _opp_cmake_result
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
if(_opp_cmake_result)
message(STATUS "opp_cmake generated following error log")
message(SEND_ERROR ${_opp_cmake_error})
message(FATAL_ERROR "import_opp_target for ${_target} aborted due to above opp_cmake error")
endif()
# include import targets if generated successfully
if(EXISTS ${_cmake_target})
include(${_cmake_target})
else()
message(FATAL_ERROR "There is no ${_cmake_target} for OMNeT++ import of ${_target}")
endif()
# sanity check: included target file has to provide the expected target
if(NOT TARGET ${_target})
message(FATAL_ERROR "Import of target ${_target} from ${_opp_makefile} failed")
endif()
endmacro()