cmake_minimum_required (VERSION 3.8)
set(MX_ALL_CODE_TO_ONE_PROJECT_CURRENT FALSE)

if(MX_ALL_CODE_TO_ONE_PROJECT_CURRENT)
    set(MX_SOURCE_ROOT ${MXCAD_ROOT_PATH}/src/mxcadassembly/MxDxf/SRC)
else()
    set(APP_NAME MxDxf)
    project(${APP_NAME})
    set(MX_SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
endif()

set(MX_MXDXF_HEADER
    ${MX_SOURCE_ROOT}/MxDxf.h
    ${MX_SOURCE_ROOT}/MxDxfData.h
    ${MX_SOURCE_ROOT}/MxDxfLoad.h
    ${MX_SOURCE_ROOT}/MxLineTypeData.h
    ${MX_SOURCE_ROOT}/MxHead.h 
    ${MX_SOURCE_ROOT}/MxOptBlockTable.h
    ${MX_SOURCE_ROOT}/MxOptEntity.h
	${MX_SOURCE_ROOT}/MxOptLayerTable.h
	${MX_SOURCE_ROOT}/MxOptLineTypeTable.h
	${MX_SOURCE_ROOT}/MxReadContext.h
	${MX_SOURCE_ROOT}/MxReadFilter.h
	${MX_SOURCE_ROOT}/MxReadOpt.h
	${MX_SOURCE_ROOT}/MxWriteContext.h
	${MX_SOURCE_ROOT}/MxWriteOpt.h
	${MX_SOURCE_ROOT}/pch.h
	${MX_SOURCE_ROOT}/Tool.h
	${MX_SOURCE_ROOT}/DxfLib/dl_attributes.h
	${MX_SOURCE_ROOT}/DxfLib/dl_codes.h
	${MX_SOURCE_ROOT}/DxfLib/dl_creationadapter.h
	${MX_SOURCE_ROOT}/DxfLib/dl_creationinterface.h
	${MX_SOURCE_ROOT}/DxfLib/dl_dxf.h
	${MX_SOURCE_ROOT}/DxfLib/dl_entities.h
	${MX_SOURCE_ROOT}/DxfLib/dl_exception.h
	${MX_SOURCE_ROOT}/DxfLib/dl_extrusion.h
	${MX_SOURCE_ROOT}/DxfLib/dl_writer.h
	${MX_SOURCE_ROOT}/DxfLib/dl_writer_ascii.h
)
	
set(MX_MXDXF_SRC
	${MX_SOURCE_ROOT}/MxDxf.cpp
    ${MX_SOURCE_ROOT}/MxDxfData.cpp
    ${MX_SOURCE_ROOT}/MxDxfLoad.cpp
    ${MX_SOURCE_ROOT}/MxLineTypeData.cpp
    ${MX_SOURCE_ROOT}/MxOptBlockTable.cpp
    ${MX_SOURCE_ROOT}/MxOptEntity.cpp
    ${MX_SOURCE_ROOT}/MxOptLayerTable.cpp
    ${MX_SOURCE_ROOT}/MxOptLineTypeTable.cpp
	${MX_SOURCE_ROOT}/MxReadContext.cpp
    ${MX_SOURCE_ROOT}/MxReadFilter.cpp
	${MX_SOURCE_ROOT}/MxReadOpt.cpp
	${MX_SOURCE_ROOT}/MxWriteContext.cpp
	${MX_SOURCE_ROOT}/MxWriteOpt.cpp
	${MX_SOURCE_ROOT}/pch.cpp
	${MX_SOURCE_ROOT}/Tool.cpp
	${MX_SOURCE_ROOT}/DxfLib/dl_dxf.cpp
	${MX_SOURCE_ROOT}/DxfLib/dl_writer_ascii.cpp
)

if(NOT MX_ALL_CODE_TO_ONE_PROJECT_CURRENT)
    list(APPEND MX_MXDXF_SRC ${MX_MXDXF_HEADER})
    add_library(${APP_NAME} ${MX_MXDXF_SRC})

    if(MX_BUILD_MXNODE)
        set(MXCADLIB Mx2DNode)
    else(MX_BUILD_MXNODE)
        set(MXCADLIB mxcadlib)
    endif(MX_BUILD_MXNODE)

    if(MX_ALL_CODE_TO_ONE_PROJECT)
        target_link_libraries(
            ${APP_NAME}
            ${MXCADLIB}
        )
    else(MX_ALL_CODE_TO_ONE_PROJECT)
        target_link_libraries(
            ${APP_NAME}
            MxFile
            MxArx
            MxKernel
            MxGe
            MxBaseEx
            MxBase
            Ge
        )
    endif(MX_ALL_CODE_TO_ONE_PROJECT)
    
    target_include_directories(${APP_NAME}
        PRIVATE ./
    )

    if(WINDOWS)
        if(MSVC)
            target_compile_options(${APP_NAME} PRIVATE "/bigobj")
        endif(MSVC)

        target_sources(${APP_NAME} PRIVATE "${MX_SOURCE_ROOT}/pch.cpp")
        set_target_properties(${APP_NAME} PROPERTIES COMPILE_FLAGS "/Yupch.h /FIpch.h")
        set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/pch.cpp" PROPERTIES COMPILE_FLAGS "/Ycpch.h" COMPILE_OPTIONS "/bigobj")
    endif(WINDOWS)
endif()