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

Add CMake integration

parent dc5f12fd
Loading
Loading
Loading
Loading

CMakeLists.txt

0 → 100644
+44 −0
Original line number Diff line number Diff line
cmake_minimum_required(VERSION 3.14)
project(
  genopts
  VERSION 0.1.0
  LANGUAGES NONE
)

message(STATUS "[genopts] hi!")

find_package(Python3 3.8 REQUIRED COMPONENTS Interpreter)

set(GENOPTS_VIRTUALENV ${CMAKE_CURRENT_BINARY_DIR}/venv)

add_custom_command(
  OUTPUT ${GENOPTS_VIRTUALENV}
  COMMENT "Creating virtualenv for genopts at ${GENOPTS_VIRTUALENV}"
  COMMAND Python3::Interpreter -m venv "${GENOPTS_VIRTUALENV}"
  COMMAND ${GENOPTS_VIRTUALENV}/bin/pip install --upgrade pip -q
  COMMAND ${GENOPTS_VIRTUALENV}/bin/pip install -r
          ${CMAKE_CURRENT_LIST_DIR}/requirements.txt --upgrade -q
  COMMAND ${GENOPTS_VIRTUALENV}/bin/pip install -e ${CMAKE_CURRENT_SOURCE_DIR}
)

# ensure that the virtual environment is created by the build process
if(NOT TARGET genopts_virtualenv)
  add_custom_target(
    genopts_virtualenv ALL
    DEPENDS ${GENOPTS_VIRTUALENV}
    DEPENDS ${CMAKE_CURRENT_LIST_DIR}/requirements.txt
  )
endif()

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}
)

add_executable(Genopts::Python3_Interpreter IMPORTED GLOBAL)
set_target_properties(
  Genopts::Python3_Interpreter PROPERTIES IMPORTED_LOCATION
                                          ${GENOPTS_VIRTUALENV}/bin/python3
)