file(GLOB file CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/file/*.cpp)

add_library(file SHARED
    ${file}
)

target_include_directories(file PRIVATE
    ${CMAKE_SOURCE_DIR}/file/include
    ${CMAKE_SOURCE_DIR}/simdata/include
    ${CMAKE_SOURCE_DIR}/utilities/include
)

set_target_properties(file PROPERTIES 
  PUBLIC_HEADER ${CMAKE_SOURCE_DIR}/file/include
)
target_compile_options(file PRIVATE
    -Wall
    -Wextra
    -pedantic
)
if(DEBUG)
    target_compile_options(file PRIVATE
        -g
    )
    target_link_options(file PRIVATE
        -g
    )
else()
    target_compile_options(file PRIVATE
        -O2
    )
endif()

if(APPLE)
    message("Building file for MacOSX Universal into ${PROJECT_BINARY_DIR}/${PLUGIN_NAME}")

    set_target_properties(file PROPERTIES
        LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}"
        BUILD_WITH_INSTALL_NAME_DIR TRUE
    )

    target_compile_options(file PRIVATE
        "SHELL:-arch i386"
        "SHELL:-arch x86_64"
    )
    target_link_options(file PRIVATE
        "SHELL:-arch i386"
        "SHELL:-arch x86_64"
    )
    target_link_libraries(file PRIVATE
        "-framework Security"
    )
elseif(UNIX)
    message("Building file for Linux ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}")

    set_target_properties(file PROPERTIES
        LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}"
    )

    target_compile_options(file PRIVATE
        -nodefaultlibs
    )
    if(BIT STREQUAL "32")
        target_compile_options(file PRIVATE
            -m32
        )
        target_link_options(file PRIVATE
            -m32
        )
    endif()
elseif(WIN32)
    message("Building file for Windows ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}")

    set_target_properties(file PROPERTIES
        RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}"
    )

    if(DEBUG)
        target_compile_options(file PRIVATE
            -gcodeview
        )
        target_link_options(file PRIVATE
            -Wl,-pdb=
        )
    endif()
    target_link_options(file PRIVATE
        -static-libgcc
        -static-libstdc++
    )
endif()
