set(MWINIIMPORT
    main.cpp
    importer.cpp
)

set(MWINIIMPORT_HEADER
    importer.hpp
)

source_group(launcher FILES ${MWINIIMPORT} ${MWINIIMPORT_HEADER})

openmw_add_executable(openmw-iniimporter
    ${MWINIIMPORT}
)

target_link_libraries(openmw-iniimporter
    Boost::program_options
    components
)

if(BUILD_TGZ)
    INSTALL(TARGETS openmw-iniimporter RUNTIME DESTINATION "." COMPONENT openmw-iniimporter)
    IF(NOT MINGW)
      exec_program("uname" ARGS "-m" OUTPUT_VARIABLE ARCH)
      SET_TARGET_PROPERTIES(openmw-iniimporter
                            PROPERTIES OUTPUT_NAME openmw-iniimporter.${ARCH})
      add_custom_command(
        TARGET openmw-iniimporter POST_BUILD
        COMMAND objcopy --only-keep-debug openmw-iniimporter.${ARCH} openmw-iniimporter.debug
        DEPENDS openmw-iniimporter.${ARCH}
        WORKING_DIRECTORY ../../
        VERBATIM)
      add_custom_command(
        TARGET openmw-iniimporter POST_BUILD
        COMMAND strip -g openmw-iniimporter.${ARCH}
        DEPENDS openmw-iniimporter.debug
        WORKING_DIRECTORY ../../
        VERBATIM)
      add_custom_command(
        TARGET openmw-iniimporter POST_BUILD
        COMMAND objcopy --add-gnu-debuglink=openmw-iniimporter.debug openmw-iniimporter.${ARCH}
        DEPENDS openmw-iniimporter.debug
        WORKING_DIRECTORY ../../
        VERBATIM)
    ENDIF(NOT MINGW)
else()
    if(DPKG_PROGRAM)
        INSTALL(TARGETS mwiniimport RUNTIME DESTINATION games COMPONENT mwiniimport)
    endif()
endif(BUILD_TGZ)

if (WIN32)
    INSTALL(TARGETS openmw-iniimporter RUNTIME DESTINATION ".")
endif(WIN32)

if (MINGW)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -municode")
endif()

if (BUILD_WITH_CODE_COVERAGE)
    target_compile_options(openmw-iniimporter PRIVATE --coverage)
    target_link_libraries(openmw-iniimporter gcov)
endif()

if (MSVC AND PRECOMPILE_HEADERS_WITH_MSVC)
    target_precompile_headers(openmw-iniimporter PRIVATE
        <string>
        <vector>
    )
endif()
