#################################################
#   ___________    ____ ______  __ __  _____    #
#   \____ \__  \ _/ ___\\____ \|  |  \/  ___/   #
#   |  |_> > __ \\  \___|  |_> >  |  /\___ \    #
#   |   __(____  /\___  >   __/|____//____  >   #
#   |__|       \/     \/|__|              \/    #
#                                               #
#################################################

project(PacpusNewComponent)
cmake_minimum_required(VERSION 2.8)
if(POLICY CMP0020)
    cmake_policy(SET CMP0020  NEW) # for QT5.1 on windows / not work on linux
endif()

################################################################################
set(PACPUS_COMPONENT_NAME "" CACHE STRING "name of the new component")

if("${PACPUS_COMPONENT_NAME}" STREQUAL "")
    message(FATAL_ERROR "You should set the PACPUS_COMPONENT_NAME variable")
endif()

################################################################################
# set substitution variables
string(TOUPPER "${PACPUS_COMPONENT_NAME}" PACPUS_COMPONENT_NAME_CAPS)
if(WIN32)
    set(USERNAME "$ENV{USERNAME}" CACHE STRING "username")
else()
    set(USERNAME "$ENV{USER}" CACHE STRING "username")
endif()
string(TIMESTAMP CURRENT_DATETIME "%Y-%m-%d %H:%M:%S")

################################################################################
# create directory for new files
set(OUTPUT_DIR "../${PACPUS_COMPONENT_NAME}")
file(MAKE_DIRECTORY "${OUTPUT_DIR}")

# configure files
configure_file("CMakeLists.txt.in" "${OUTPUT_DIR}/CMakeLists.txt" @ONLY)
configure_file("NewComponent.h.in" "${OUTPUT_DIR}/${PACPUS_COMPONENT_NAME}.h" @ONLY)
configure_file("NewComponent.cpp.in" "${OUTPUT_DIR}/${PACPUS_COMPONENT_NAME}.cpp" @ONLY)
configure_file("NewComponentImpl.h.in" "${OUTPUT_DIR}/${PACPUS_COMPONENT_NAME}Impl.h" @ONLY)
configure_file("NewComponentImpl.cpp.in" "${OUTPUT_DIR}/${PACPUS_COMPONENT_NAME}Impl.cpp" @ONLY)

################################################################################
message(STATUS "New component '${PACPUS_COMPONENT_NAME}' has been created.")
message(STATUS "Please add line 'add_subdirectory(${PACPUS_COMPONENT_NAME})' to your main CMakeLists.txt file.")
