openexr provides CMake targets:
find_package(OpenEXR CONFIG REQUIRED)
target_link_libraries(main PRIVATE OpenEXR::OpenEXR)