<commit_before>option(BUILD_EXPERIMENTAL_APPS "Should we build the experimental and possibly broken extra apps?" OFF)

add_subdirectory(PathTreeExport)

if(WIN32)
    set(OSVR_SERVER_RESOURCE osvr_server.rc)
else()
    set(OSVR_SERVER_RESOURCE)
endif()

add_executable(osvr_server
    osvr_server.cpp
    ${OSVR_SERVER_RESOURCE})
target_link_libraries(osvr_server osvrServer jsoncpp_lib)
set_target_properties(osvr_server PROPERTIES
    FOLDER "OSVR Stock Applications")
install(TARGETS osvr_server
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime)

add_executable(osvr_print_tree
    osvr_print_tree.cpp)
target_link_libraries(osvr_print_tree
    osvrClientKitCpp
    osvrCommon
    jsoncpp_lib
    boost_program_options)
set_target_properties(osvr_print_tree PROPERTIES
    FOLDER "OSVR Stock Applications")
install(TARGETS osvr_print_tree
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime)

add_executable(BasicServer BasicServer.cpp)
target_link_libraries(BasicServer
    osvrServer
    jsoncpp_lib)
set_target_properties(BasicServer PROPERTIES
    FOLDER "OSVR Stock Applications")

install(TARGETS BasicServer
    RUNTIME DESTINATION ${EXTRA_SAMPLE_BINDIR} COMPONENT ExtraSampleBinaries)

if(BUILD_EXPERIMENTAL_APPS)
    add_executable(osvr_calibrate
        osvr_calibrate.cpp
        ClientMainloop.h
        RecomposeTransform.h
        WrapRoute.h)
    target_link_libraries(osvr_calibrate
        osvrServer
        jsoncpp_lib
        osvrClientKitCpp
        osvrCommon
        eigen-headers
        boost_thread
        boost_program_options)
    set_target_properties(osvr_calibrate PROPERTIES
        FOLDER "OSVR Experimental Applications")

    add_executable(osvr_reset_yaw
        osvr_reset_yaw.cpp
        ClientMainloop.h
        ClientMainloopThread.h
        RecomposeTransform.h
        WrapRoute.h)
    target_link_libraries(osvr_reset_yaw
        jsoncpp_lib
        osvrClientKitCpp
        osvrClient
        osvrCommon
        eigen-headers
        boost_thread
        boost_program_options)
    set_target_properties(osvr_reset_yaw PROPERTIES
        FOLDER "OSVR Experimental Applications")

    add_executable(diagnose-rotation
        diagnose-rotation.cpp
        ClientMainloop.h
        ClientMainloopThread.h
        RecomposeTransform.h)
    target_link_libraries(diagnose-rotation
        jsoncpp_lib
        osvrClientKitCpp
        osvrClient
        osvrCommon
        eigen-headers
        boost_thread
        boost_program_options)
    set_target_properties(diagnose-rotation PROPERTIES
        FOLDER "OSVR Experimental Applications")

    install(TARGETS osvr_calibrate osvr_reset_yaw diagnose-rotation
        RUNTIME DESTINATION ${EXTRA_SAMPLE_BINDIR} COMPONENT ExperimentalApps)
endif()

# Grab all the config files with a glob, to avoid missing one.
file(GLOB CONFIG_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/osvr_server_config*.json")

foreach(FN ${CONFIG_FILES})
    add_custom_command(TARGET osvr_server POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${FN}" $<TARGET_FILE_DIR:osvr_server>
        COMMENT "Copying JSON config file sample ${FN}"
        VERBATIM)
    install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/${FN}"
        DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime)
endforeach()

set(DISPLAYS_DIR /displays)

add_custom_command(TARGET osvr_server POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:osvr_server>${DISPLAYS_DIR}"
        COMMENT "Making JSON display descriptor directory"
        VERBATIM)
# Grab all the display files with a glob, to avoid missing one.
file(GLOB DISPLAY_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}${DISPLAYS_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${DISPLAYS_DIR}/*.json")

foreach(FN ${DISPLAY_FILES})
    add_custom_command(TARGET osvr_server POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}${DISPLAYS_DIR}/${FN}" "$<TARGET_FILE_DIR:osvr_server>${DISPLAYS_DIR}"
        COMMENT "Copying JSON display descriptor ${FN}"
        VERBATIM)
    install(FILES "${CMAKE_CURRENT_SOURCE_DIR}${DISPLAYS_DIR}/${FN}"
        DESTINATION ${CMAKE_INSTALL_BINDIR}${DISPLAYS_DIR} COMPONENT Runtime)
endforeach()<commit_msg>Use a custom target, instead of a post-build, to more reliably copy over server/display configs<commit_after>option(BUILD_EXPERIMENTAL_APPS "Should we build the experimental and possibly broken extra apps?" OFF)

add_subdirectory(PathTreeExport)

if(WIN32)
    set(OSVR_SERVER_RESOURCE osvr_server.rc)
else()
    set(OSVR_SERVER_RESOURCE)
endif()

add_executable(osvr_server
    osvr_server.cpp
    ${OSVR_SERVER_RESOURCE})
target_link_libraries(osvr_server osvrServer jsoncpp_lib)
set_target_properties(osvr_server PROPERTIES
    FOLDER "OSVR Stock Applications")
install(TARGETS osvr_server
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime)

add_executable(osvr_print_tree
    osvr_print_tree.cpp)
target_link_libraries(osvr_print_tree
    osvrClientKitCpp
    osvrCommon
    jsoncpp_lib
    boost_program_options)
set_target_properties(osvr_print_tree PROPERTIES
    FOLDER "OSVR Stock Applications")
install(TARGETS osvr_print_tree
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime)

add_executable(BasicServer BasicServer.cpp)
target_link_libraries(BasicServer
    osvrServer
    jsoncpp_lib)
set_target_properties(BasicServer PROPERTIES
    FOLDER "OSVR Stock Applications")

install(TARGETS BasicServer
    RUNTIME DESTINATION ${EXTRA_SAMPLE_BINDIR} COMPONENT ExtraSampleBinaries)

if(BUILD_EXPERIMENTAL_APPS)
    add_executable(osvr_calibrate
        osvr_calibrate.cpp
        ClientMainloop.h
        RecomposeTransform.h
        WrapRoute.h)
    target_link_libraries(osvr_calibrate
        osvrServer
        jsoncpp_lib
        osvrClientKitCpp
        osvrCommon
        eigen-headers
        boost_thread
        boost_program_options)
    set_target_properties(osvr_calibrate PROPERTIES
        FOLDER "OSVR Experimental Applications")

    add_executable(osvr_reset_yaw
        osvr_reset_yaw.cpp
        ClientMainloop.h
        ClientMainloopThread.h
        RecomposeTransform.h
        WrapRoute.h)
    target_link_libraries(osvr_reset_yaw
        jsoncpp_lib
        osvrClientKitCpp
        osvrClient
        osvrCommon
        eigen-headers
        boost_thread
        boost_program_options)
    set_target_properties(osvr_reset_yaw PROPERTIES
        FOLDER "OSVR Experimental Applications")

    add_executable(diagnose-rotation
        diagnose-rotation.cpp
        ClientMainloop.h
        ClientMainloopThread.h
        RecomposeTransform.h)
    target_link_libraries(diagnose-rotation
        jsoncpp_lib
        osvrClientKitCpp
        osvrClient
        osvrCommon
        eigen-headers
        boost_thread
        boost_program_options)
    set_target_properties(diagnose-rotation PROPERTIES
        FOLDER "OSVR Experimental Applications")

    install(TARGETS osvr_calibrate osvr_reset_yaw diagnose-rotation
        RUNTIME DESTINATION ${EXTRA_SAMPLE_BINDIR} COMPONENT ExperimentalApps)
endif()

set(FILE_OUTPUTS)

# Grab all the config files with a glob, to avoid missing one.
file(GLOB CONFIG_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/osvr_server_config*.json")

foreach(FN ${CONFIG_FILES})
    list(APPEND FILE_OUTPUTS "${FN}")
    add_custom_command(OUTPUT "${FN}"
        COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${FN}" "$<TARGET_FILE_DIR:osvr_server>"
        MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${FN}"
        COMMENT "Copying JSON config file ${FN}"
        VERBATIM)
    install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/${FN}"
        DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Server)
endforeach()

# Copy contents of dir for both build and install trees.
macro(osvr_copy_dir _dirname _glob _comment)
    add_custom_command(OUTPUT "${_dirname}"
        COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:osvr_server>${_dirname}"
        COMMENT "Making ${_comment} directory"
        VERBATIM)

    # Grab all the files with a glob, to avoid missing one.
    file(GLOB _files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}${_dirname}" "${CMAKE_CURRENT_SOURCE_DIR}${_dirname}/${_glob}")

    foreach(FN ${_files})
        list(APPEND FILE_OUTPUTS "${_dirname}/${FN}")
        add_custom_command(OUTPUT "${_dirname}/${FN}"
            COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}${_dirname}/${FN}" "$<TARGET_FILE_DIR:osvr_server>${_dirname}"
            MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}${_dirname}/${FN}"
            DEPENDS "${_dirname}"
            COMMENT "Copying ${_comment} ${FN}"
            VERBATIM)
        install(FILES "${CMAKE_CURRENT_SOURCE_DIR}${_dirname}/${FN}"
            DESTINATION ${CMAKE_INSTALL_BINDIR}${_dirname} COMPONENT Server)
    endforeach()
endmacro()

osvr_copy_dir(/displays *.json "JSON display descriptor")

# Have to set them as symbolic because we can't use a generator expression in add_custom_command(OUTPUT
set_source_files_properties(${FILE_OUTPUTS} PROPERTIES SYMBOLIC TRUE)
add_custom_target(copy_osvr_server_config_files ALL
    DEPENDS ${FILE_OUTPUTS})
{'fraction_non_alphanumeric': 0.07318393417776334, 'fraction_numerical': 0.0004330410306376529, 'mean_word_length': 4.129372570794003, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7014940', 'n_tokens_mistral': 3044, 'n_tokens_neox': 2948, 'n_words': 552}