Verified Commit fb8dde29 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Improve CMake integration

parent fd611977
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -5,12 +5,13 @@ project(
  LANGUAGES NONE
)

message(STATUS "[genopts] hi!")
message(STATUS "[${PROJECT_NAME}] Project version: ${PROJECT_VERSION}")

find_package(Python3 3.8 REQUIRED COMPONENTS Interpreter)

set(GENOPTS_VIRTUALENV ${CMAKE_CURRENT_BINARY_DIR}/venv)

# Create a virtual environment that can be used to run genopts
add_custom_command(
  OUTPUT ${GENOPTS_VIRTUALENV}
  COMMENT "Creating virtualenv for genopts at ${GENOPTS_VIRTUALENV}"
@@ -21,7 +22,7 @@ add_custom_command(
  COMMAND ${GENOPTS_VIRTUALENV}/bin/pip install -e ${CMAKE_CURRENT_SOURCE_DIR}
)

# ensure that the virtual environment is created by the build process
# Ensure that the virtual environment is created by the build process
if(NOT TARGET genopts_virtualenv)
  add_custom_target(
    genopts_virtualenv ALL
@@ -30,13 +31,16 @@ if(NOT TARGET genopts_virtualenv)
  )
endif()

# Export a target with the location of the script in case someone needs this
# information.
add_executable(Genopts::Script IMPORTED GLOBAL)
set(GENOPTS_SCRIPT "/home/amiranda/var/projects/genopts/genopts/genopts.py")

set_target_properties(
  Genopts::Script PROPERTIES IMPORTED_LOCATION ${GENOPTS_SCRIPT}
  Genopts::Script PROPERTIES IMPORTED_LOCATION
                             ${CMAKE_CURRENT_LIST_DIR}/genopts/genopts.py}
)

# Export a target with the location of the Python interpreter of the
# virtual environment. This allows CMake users to easily call the script.
add_executable(Genopts::Python3_Interpreter IMPORTED GLOBAL)
set_target_properties(
  Genopts::Python3_Interpreter PROPERTIES IMPORTED_LOCATION